Skip to content

Commit

Permalink
Merge pull request #6 from satoshipay/bugfix/compat-latest-stellar-sdk
Browse files Browse the repository at this point in the history
Make compatible with latest Stellar SDK versions
  • Loading branch information
andywer authored Jun 23, 2020
2 parents a8c8be9 + 6e42951 commit 156f819
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 97 deletions.
164 changes: 76 additions & 88 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"posttest": "npm run lint"
},
"peerDependencies": {
"stellar-sdk": "^2.0.1"
"stellar-sdk": ">= 5.0.0"
},
"dependencies": {
"axios": "^0.19.0",
Expand All @@ -28,12 +28,12 @@
"husky": "^1.3.1",
"lint-staged": "^8.1.4",
"prettier": "^1.16.4",
"stellar-sdk": "^2.0.1",
"stellar-sdk": "^5.0.3",
"tap-xunit": "^2.3.0",
"ts-node": "^8.0.2",
"tslint": "^5.12.1",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.3.3"
"typescript": "^3.9.5"
},
"ava": {
"compileEnhancements": false,
Expand Down
13 changes: 7 additions & 6 deletions src/authentication.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios, { AxiosResponse } from "axios"
import { Keypair, Network, Operation, Transaction } from "stellar-sdk"
import { Keypair, Networks, Operation, Transaction } from "stellar-sdk"
import { debug } from "./logger"

function assertChallengeOK(
Expand Down Expand Up @@ -80,7 +80,8 @@ function getNonceOperation(challenge: Transaction): Buffer {
export async function fetchChallenge(
endpointURL: string,
serviceSigningKey: string | null,
localPublicKey: string
localPublicKey: string,
network: Networks
): Promise<Transaction> {
debug(`Fetching web auth challenge from ${endpointURL}...`)
let response: AxiosResponse<any>
Expand All @@ -95,7 +96,7 @@ export async function fetchChallenge(
}

debug("Fetched web auth challenge:", response.data)
const transaction = new Transaction(response.data.transaction)
const transaction = new Transaction(response.data.transaction, network)
assertChallengeOK(transaction, serviceSigningKey, localPublicKey)

return transaction
Expand Down Expand Up @@ -145,15 +146,15 @@ export async function authenticate(
endpointURL: string,
serviceSigningKey: string,
keypair: Keypair,
network: Network
network: Networks
) {
const transaction = await fetchChallenge(
endpointURL,
serviceSigningKey,
keypair.publicKey()
keypair.publicKey(),
network
)

Network.use(network)
transaction.sign(keypair)

const token = await postResponse(endpointURL, transaction)
Expand Down

0 comments on commit 156f819

Please sign in to comment.