@stellar/typescript-wallet-sdk 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babel.config.js +5 -1
- package/examples/sep24/sep24.ts +6 -1
- package/jest.integration.config.js +1 -1
- package/lib/bundle.js +35919 -35080
- package/lib/bundle.js.map +1 -1
- package/lib/bundle_browser.js +29734 -67834
- package/lib/bundle_browser.js.map +1 -1
- package/lib/index.d.ts +6 -1
- package/lib/walletSdk/Anchor/index.d.ts +2 -0
- package/lib/walletSdk/Asset/index.d.ts +1 -1
- package/lib/walletSdk/Auth/WalletSigner.d.ts +1 -1
- package/lib/walletSdk/Exceptions/index.d.ts +16 -1
- package/lib/walletSdk/Horizon/Account.d.ts +1 -1
- package/lib/walletSdk/Horizon/AccountService.d.ts +1 -1
- package/lib/walletSdk/Horizon/Stellar.d.ts +1 -1
- package/lib/walletSdk/Horizon/Transaction/CommonTransactionBuilder.d.ts +1 -1
- package/lib/walletSdk/Horizon/Transaction/SponsoringBuilder.d.ts +1 -1
- package/lib/walletSdk/Horizon/Transaction/TransactionBuilder.d.ts +1 -1
- package/lib/walletSdk/Recovery/AccountRecover.d.ts +1 -1
- package/lib/walletSdk/Recovery/index.d.ts +1 -1
- package/lib/walletSdk/Server/index.d.ts +21 -0
- package/lib/walletSdk/Types/anchor.d.ts +1 -1
- package/lib/walletSdk/Types/auth.d.ts +12 -2
- package/lib/walletSdk/Types/horizon.d.ts +1 -1
- package/lib/walletSdk/Types/index.d.ts +2 -1
- package/lib/walletSdk/Types/recovery.d.ts +1 -1
- package/lib/walletSdk/Types/sep24.d.ts +1 -1
- package/lib/walletSdk/Utils/toml.d.ts +1 -1
- package/lib/walletSdk/index.d.ts +4 -2
- package/package.json +8 -11
- package/src/index.ts +7 -1
- package/src/walletSdk/Anchor/index.ts +9 -5
- package/src/walletSdk/Asset/index.ts +1 -1
- package/src/walletSdk/Auth/WalletSigner.ts +1 -1
- package/src/walletSdk/Auth/index.ts +3 -3
- package/src/walletSdk/Exceptions/index.ts +36 -1
- package/src/walletSdk/Horizon/Account.ts +1 -1
- package/src/walletSdk/Horizon/AccountService.ts +1 -1
- package/src/walletSdk/Horizon/Stellar.ts +1 -1
- package/src/walletSdk/Horizon/Transaction/CommonTransactionBuilder.ts +5 -5
- package/src/walletSdk/Horizon/Transaction/SponsoringBuilder.ts +4 -4
- package/src/walletSdk/Horizon/Transaction/TransactionBuilder.ts +8 -9
- package/src/walletSdk/Recovery/AccountRecover.ts +1 -1
- package/src/walletSdk/Recovery/index.ts +1 -1
- package/src/walletSdk/Server/index.ts +95 -0
- package/src/walletSdk/Types/anchor.ts +1 -1
- package/src/walletSdk/Types/auth.ts +14 -2
- package/src/walletSdk/Types/horizon.ts +1 -1
- package/src/walletSdk/Types/index.ts +2 -1
- package/src/walletSdk/Types/recovery.ts +1 -1
- package/src/walletSdk/Types/sep24.ts +1 -1
- package/src/walletSdk/Utils/toml.ts +1 -1
- package/src/walletSdk/index.ts +14 -2
- package/test/account.test.ts +1 -1
- package/test/accountService.test.ts +13 -41
- package/test/integration/anchorplatform.test.ts +145 -0
- package/test/{integration.test.ts → integration/recovery.test.ts} +2 -2
- package/test/recovery.test.ts +1 -1
- package/test/sep6.test.ts +1 -1
- package/test/server.test.ts +71 -0
- package/test/stellar.test.ts +1 -1
- package/test/transaction.test.ts +1 -1
- package/test/wallet.test.ts +1 -1
- package/webpack.config.js +48 -32
- package/.eslintrc.js +0 -76
- package/.github/workflows/integrationTest.yml +0 -19
- package/.github/workflows/runTests.yml +0 -14
- package/.husky/pre-commit +0 -5
- package/LICENSE +0 -204
- package/README.md +0 -51
- package/docs/WalletGuide.md +0 -5
- package/jest.config.js +0 -9
- package/prettier.config.js +0 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code in the Server module is written to be used by server side
|
|
3
|
+
* applications.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Transaction,
|
|
8
|
+
TransactionBuilder,
|
|
9
|
+
Keypair,
|
|
10
|
+
StellarToml,
|
|
11
|
+
} from "@stellar/stellar-sdk";
|
|
12
|
+
|
|
13
|
+
import { parseToml } from "../Utils";
|
|
14
|
+
import {
|
|
15
|
+
SignChallengeTxnParams,
|
|
16
|
+
SignChallengeTxnResponse,
|
|
17
|
+
AnchorTransaction,
|
|
18
|
+
WithdrawTransaction,
|
|
19
|
+
DepositTransaction,
|
|
20
|
+
ErrorTransaction,
|
|
21
|
+
} from "../Types";
|
|
22
|
+
import {
|
|
23
|
+
ChallengeTxnIncorrectSequenceError,
|
|
24
|
+
ChallengeTxnInvalidSignatureError,
|
|
25
|
+
UnknownAnchorTransactionError,
|
|
26
|
+
InvalidJsonError,
|
|
27
|
+
} from "../Exceptions";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Helper method for signing a SEP-10 challenge transaction if valid.
|
|
31
|
+
* @param {SignChallengeTxnParams} params - The Authentication params.
|
|
32
|
+
* @param {AccountKeypair} params.accountKp - Keypair for the Stellar account signing the transaction.
|
|
33
|
+
* @param {string} [params.challengeTx] - The challenge transaction given by an anchor for authentication.
|
|
34
|
+
* @param {string} [params.networkPassphrase] - The network passphrase for the network authenticating on.
|
|
35
|
+
* @param {string} [params.anchorDomain] - Domain hosting stellar.toml file containing `SIGNING_KEY`.
|
|
36
|
+
* @returns {Promise<SignChallengeTxnResponse>} The signed transaction.
|
|
37
|
+
*/
|
|
38
|
+
export const signChallengeTransaction = async ({
|
|
39
|
+
accountKp,
|
|
40
|
+
challengeTx,
|
|
41
|
+
networkPassphrase,
|
|
42
|
+
anchorDomain,
|
|
43
|
+
}: SignChallengeTxnParams): Promise<SignChallengeTxnResponse> => {
|
|
44
|
+
const tx = TransactionBuilder.fromXDR(
|
|
45
|
+
challengeTx,
|
|
46
|
+
networkPassphrase,
|
|
47
|
+
) as Transaction;
|
|
48
|
+
|
|
49
|
+
if (parseInt(tx.sequence) !== 0) {
|
|
50
|
+
throw new ChallengeTxnIncorrectSequenceError();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const tomlResp = await StellarToml.Resolver.resolve(anchorDomain);
|
|
54
|
+
const parsedToml = parseToml(tomlResp);
|
|
55
|
+
const anchorKp = Keypair.fromPublicKey(parsedToml.signingKey);
|
|
56
|
+
|
|
57
|
+
const isValid =
|
|
58
|
+
tx.signatures.length &&
|
|
59
|
+
anchorKp.verify(tx.hash(), tx.signatures[0].signature());
|
|
60
|
+
if (!isValid) {
|
|
61
|
+
throw new ChallengeTxnInvalidSignatureError();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
accountKp.sign(tx);
|
|
65
|
+
return {
|
|
66
|
+
transaction: tx.toXDR(),
|
|
67
|
+
networkPassphrase,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Helper method for parsing a JSON string into an AnchorTransaction.
|
|
73
|
+
* @param {string} transaction - The json string of an anchor transaction.
|
|
74
|
+
* @returns {AnchorTransaction} The transaction object.
|
|
75
|
+
*/
|
|
76
|
+
export const parseAnchorTransaction = (
|
|
77
|
+
transaction: string,
|
|
78
|
+
): AnchorTransaction => {
|
|
79
|
+
let parsed;
|
|
80
|
+
try {
|
|
81
|
+
parsed = JSON.parse(transaction);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
throw new InvalidJsonError();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (parsed.kind === "withdrawal") {
|
|
87
|
+
return parsed as WithdrawTransaction;
|
|
88
|
+
} else if (parsed.kind === "deposit") {
|
|
89
|
+
return parsed as DepositTransaction;
|
|
90
|
+
} else if (parsed.status === "error") {
|
|
91
|
+
return parsed as ErrorTransaction;
|
|
92
|
+
} else {
|
|
93
|
+
throw new UnknownAnchorTransactionError();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Transaction } from "stellar-sdk";
|
|
1
|
+
import { Transaction } from "@stellar/stellar-sdk";
|
|
2
2
|
import { decode } from "jws";
|
|
3
3
|
|
|
4
4
|
import { WalletSigner } from "../Auth/WalletSigner";
|
|
5
|
-
import { AccountKeypair } from "../Horizon/Account";
|
|
5
|
+
import { AccountKeypair, SigningKeypair } from "../Horizon/Account";
|
|
6
6
|
|
|
7
7
|
export type AuthenticateParams = {
|
|
8
8
|
accountKp: AccountKeypair;
|
|
@@ -79,3 +79,15 @@ export type SignWithDomainAccountParams = {
|
|
|
79
79
|
export type HttpHeaders = {
|
|
80
80
|
[key: string]: string;
|
|
81
81
|
};
|
|
82
|
+
|
|
83
|
+
export type SignChallengeTxnParams = {
|
|
84
|
+
accountKp: SigningKeypair;
|
|
85
|
+
challengeTx: string;
|
|
86
|
+
networkPassphrase: string;
|
|
87
|
+
anchorDomain: string;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type SignChallengeTxnResponse = {
|
|
91
|
+
transaction: XdrEncodedTransaction;
|
|
92
|
+
networkPassphrase: NetworkPassphrase;
|
|
93
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Memo, Horizon, Transaction } from "stellar-sdk";
|
|
1
|
+
import { Memo, Horizon, Transaction } from "@stellar/stellar-sdk";
|
|
2
2
|
import { AccountKeypair } from "../Horizon/Account";
|
|
3
3
|
import { SponsoringBuilder, TransactionBuilder } from "walletSdk/Horizon";
|
|
4
4
|
import { StellarAssetId } from "../Asset";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RawAxiosRequestHeaders } from "axios";
|
|
2
|
-
import { Networks } from "stellar-sdk";
|
|
2
|
+
import { Networks } from "@stellar/stellar-sdk";
|
|
3
3
|
import { ApplicationConfiguration, StellarConfiguration } from "walletSdk";
|
|
4
4
|
import { RecoveryServerMap } from "./recovery";
|
|
5
5
|
|
|
@@ -12,6 +12,7 @@ export type WalletParams = {
|
|
|
12
12
|
|
|
13
13
|
export type WalletAnchor = {
|
|
14
14
|
homeDomain: string;
|
|
15
|
+
allowHttp?: boolean;
|
|
15
16
|
language?: string;
|
|
16
17
|
};
|
|
17
18
|
|
package/src/walletSdk/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios, { AxiosInstance } from "axios";
|
|
2
|
-
import { Networks, Horizon } from "stellar-sdk";
|
|
2
|
+
import { Networks, Horizon } from "@stellar/stellar-sdk";
|
|
3
3
|
|
|
4
4
|
import { Anchor } from "./Anchor";
|
|
5
5
|
import { DefaultSigner, WalletSigner } from "./Auth";
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
NETWORK_URLS,
|
|
15
15
|
} from "./Types";
|
|
16
16
|
import { getUrlDomain } from "./Utils";
|
|
17
|
+
import { AllowHttpOnNonTestnetError } from "./Exceptions";
|
|
17
18
|
|
|
18
19
|
/* eslint-disable-next-line @typescript-eslint/no-var-requires */
|
|
19
20
|
const version = require("../../package.json").version;
|
|
@@ -73,16 +74,27 @@ export class Wallet {
|
|
|
73
74
|
* @param {WalletAnchor} params - The anchor params.
|
|
74
75
|
* @param {string} params.homeDomain - The home domain of the anchor. This domain will be used for
|
|
75
76
|
* things like getting the toml info.
|
|
77
|
+
* @param {allowHttp} [params.allowHttp] - Flag to allow http protocol for the home domain.
|
|
78
|
+
* Defaults to false, and can only be set to true on Testnet.
|
|
76
79
|
* @param {string} [params.language=this.language] - The language setting for the Anchor.
|
|
77
80
|
* @returns {Anchor} An Anchor instance.
|
|
78
81
|
*/
|
|
79
|
-
anchor({
|
|
82
|
+
anchor({
|
|
83
|
+
homeDomain,
|
|
84
|
+
allowHttp = false,
|
|
85
|
+
language = this.language,
|
|
86
|
+
}: WalletAnchor): Anchor {
|
|
80
87
|
const url =
|
|
81
88
|
homeDomain.indexOf("://") !== -1 ? homeDomain : `https://${homeDomain}`;
|
|
82
89
|
|
|
90
|
+
if (allowHttp && this.cfg.stellar.network !== Networks.TESTNET) {
|
|
91
|
+
throw new AllowHttpOnNonTestnetError();
|
|
92
|
+
}
|
|
93
|
+
|
|
83
94
|
return new Anchor({
|
|
84
95
|
cfg: this.cfg,
|
|
85
96
|
homeDomain: getUrlDomain(url),
|
|
97
|
+
allowHttp,
|
|
86
98
|
httpClient: this.cfg.app.defaultClient,
|
|
87
99
|
language,
|
|
88
100
|
});
|
package/test/account.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import { Horizon } from "stellar-sdk";
|
|
2
|
+
import { Horizon } from "@stellar/stellar-sdk";
|
|
3
3
|
|
|
4
4
|
import { AccountService, SigningKeypair, Wallet } from "../src";
|
|
5
5
|
import { HORIZON_ORDER } from "../src/walletSdk/Types";
|
|
@@ -29,50 +29,22 @@ describe("Horizon", () => {
|
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// create test account
|
|
33
|
+
const testingAccountKp = accountService.createKeypair();
|
|
34
|
+
await axios.get(
|
|
35
|
+
"https://friendbot.stellar.org/?addr=" + testingAccountKp.publicKey,
|
|
34
36
|
);
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
sourceAddress: fundingAccountKp,
|
|
43
|
-
baseFee: 100,
|
|
44
|
-
});
|
|
45
|
-
const createAccTx = txBuilder1.createAccount(testingAccountKp, 2).build();
|
|
46
|
-
createAccTx.sign(fundingAccountKp.keypair);
|
|
47
|
-
|
|
48
|
-
let failed = false;
|
|
49
|
-
try {
|
|
50
|
-
await stellar.submitTransaction(createAccTx);
|
|
51
|
-
await stellar.server.loadAccount(accountAddress);
|
|
52
|
-
} catch (e) {
|
|
53
|
-
failed = true;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const txBuilder2 = await stellar.transaction({
|
|
57
|
-
sourceAddress: testingAccountKp,
|
|
58
|
-
baseFee: 100,
|
|
59
|
-
});
|
|
60
|
-
const asset = new IssuedAssetId(
|
|
61
|
-
"USDC",
|
|
62
|
-
"GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
|
|
63
|
-
);
|
|
64
|
-
const addUsdcTx = txBuilder2.addAssetSupport(asset).build();
|
|
65
|
-
addUsdcTx.sign(testingAccountKp.keypair);
|
|
38
|
+
const txBuilder = await stellar.transaction({
|
|
39
|
+
sourceAddress: testingAccountKp,
|
|
40
|
+
});
|
|
41
|
+
const asset = new IssuedAssetId("USDC", fundingAccountKp.publicKey);
|
|
42
|
+
const addUsdcTx = txBuilder.addAssetSupport(asset).build();
|
|
43
|
+
addUsdcTx.sign(testingAccountKp.keypair);
|
|
66
44
|
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
await stellar.submitTransaction(addUsdcTx);
|
|
70
|
-
} catch (e) {
|
|
71
|
-
failed = true;
|
|
72
|
-
}
|
|
45
|
+
await stellar.submitTransaction(addUsdcTx);
|
|
73
46
|
|
|
74
|
-
|
|
75
|
-
}
|
|
47
|
+
accountAddress = testingAccountKp.publicKey;
|
|
76
48
|
}, 30000);
|
|
77
49
|
|
|
78
50
|
it("should return stellar account details", async () => {
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Wallet } from "../../src";
|
|
2
|
+
import { IssuedAssetId } from "../../src/walletSdk/Asset";
|
|
3
|
+
|
|
4
|
+
let wallet;
|
|
5
|
+
let stellar;
|
|
6
|
+
let anchor;
|
|
7
|
+
let accountKp;
|
|
8
|
+
const anchorUrl = "http://localhost:8080";
|
|
9
|
+
|
|
10
|
+
describe("Anchor Platform Integration Tests", () => {
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
// Setup
|
|
13
|
+
wallet = Wallet.TestNet();
|
|
14
|
+
stellar = wallet.stellar();
|
|
15
|
+
anchor = wallet.anchor({ homeDomain: anchorUrl, allowHttp: true });
|
|
16
|
+
accountKp = stellar.account().createKeypair();
|
|
17
|
+
await stellar.fundTestnetAccount(accountKp.publicKey);
|
|
18
|
+
}, 15000);
|
|
19
|
+
|
|
20
|
+
it("SEP-10 auth should work", async () => {
|
|
21
|
+
const auth = await anchor.sep10();
|
|
22
|
+
const authToken = await auth.authenticate({ accountKp });
|
|
23
|
+
expect(authToken.token).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("SEP-12 KYC and SEP-6 should work", async () => {
|
|
27
|
+
const auth = await anchor.sep10();
|
|
28
|
+
const authToken = await auth.authenticate({ accountKp });
|
|
29
|
+
|
|
30
|
+
// add USDC trustline
|
|
31
|
+
const asset = new IssuedAssetId(
|
|
32
|
+
"USDC",
|
|
33
|
+
// anchor platform USDC issuer
|
|
34
|
+
"GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP",
|
|
35
|
+
);
|
|
36
|
+
const txBuilder = await stellar.transaction({
|
|
37
|
+
sourceAddress: accountKp,
|
|
38
|
+
});
|
|
39
|
+
const addUsdcTx = txBuilder.addAssetSupport(asset).build();
|
|
40
|
+
addUsdcTx.sign(accountKp.keypair);
|
|
41
|
+
await stellar.submitTransaction(addUsdcTx);
|
|
42
|
+
|
|
43
|
+
// add SEP-12 KYC info
|
|
44
|
+
const sep12 = await anchor.sep12(authToken);
|
|
45
|
+
const sep12Resp = await sep12.add({
|
|
46
|
+
sep9Info: {
|
|
47
|
+
first_name: "john",
|
|
48
|
+
last_name: "smith",
|
|
49
|
+
email_address: "123@gmail.com",
|
|
50
|
+
bank_number: "12345",
|
|
51
|
+
bank_account_number: "12345",
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
expect(sep12Resp.data.id).toBeTruthy();
|
|
55
|
+
|
|
56
|
+
// SEP-6 deposit
|
|
57
|
+
const sep6 = anchor.sep6();
|
|
58
|
+
const dResp = await sep6.deposit({
|
|
59
|
+
authToken,
|
|
60
|
+
params: {
|
|
61
|
+
asset_code: "USDC",
|
|
62
|
+
account: accountKp.publicKey,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
expect(dResp.id).toBeTruthy();
|
|
66
|
+
|
|
67
|
+
// SEP-6 withdraw
|
|
68
|
+
const wResp = await sep6.withdraw({
|
|
69
|
+
authToken,
|
|
70
|
+
params: {
|
|
71
|
+
asset_code: "USDC",
|
|
72
|
+
account: accountKp.publicKey,
|
|
73
|
+
type: "bank_account",
|
|
74
|
+
dest: "123",
|
|
75
|
+
dest_extra: "12345",
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
expect(wResp.id).toBeTruthy();
|
|
79
|
+
}, 30000);
|
|
80
|
+
|
|
81
|
+
it("SEP-24 should work", async () => {
|
|
82
|
+
const assetCode = "USDC";
|
|
83
|
+
const auth = await anchor.sep10();
|
|
84
|
+
const authToken = await auth.authenticate({ accountKp });
|
|
85
|
+
|
|
86
|
+
const dResp = await anchor.sep24().deposit({
|
|
87
|
+
assetCode,
|
|
88
|
+
authToken,
|
|
89
|
+
});
|
|
90
|
+
const transactionId = dResp.id;
|
|
91
|
+
expect(transactionId).toBeTruthy();
|
|
92
|
+
|
|
93
|
+
const wResp = await anchor.sep24().withdraw({
|
|
94
|
+
withdrawalAccount: accountKp.publicKey,
|
|
95
|
+
assetCode,
|
|
96
|
+
authToken,
|
|
97
|
+
});
|
|
98
|
+
expect(wResp.id).toBeTruthy();
|
|
99
|
+
|
|
100
|
+
const transaction = await anchor.sep24().getTransactionBy({
|
|
101
|
+
authToken,
|
|
102
|
+
id: transactionId,
|
|
103
|
+
});
|
|
104
|
+
expect(transaction.id).toBeTruthy();
|
|
105
|
+
expect(transaction.status).toBe("incomplete");
|
|
106
|
+
|
|
107
|
+
const transactions = await anchor.sep24().getTransactionsForAsset({
|
|
108
|
+
authToken,
|
|
109
|
+
assetCode,
|
|
110
|
+
limit: 5,
|
|
111
|
+
});
|
|
112
|
+
expect(transactions.length).toBe(2);
|
|
113
|
+
}, 45000);
|
|
114
|
+
|
|
115
|
+
it("SEP-38 should work", async () => {
|
|
116
|
+
const auth = await anchor.sep10();
|
|
117
|
+
const authToken = await auth.authenticate({ accountKp });
|
|
118
|
+
const sep38 = anchor.sep38(authToken);
|
|
119
|
+
|
|
120
|
+
// Price
|
|
121
|
+
const resp = await sep38.price({
|
|
122
|
+
sellAsset: "iso4217:USD",
|
|
123
|
+
buyAsset:
|
|
124
|
+
"stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP",
|
|
125
|
+
sellAmount: "5",
|
|
126
|
+
context: "sep6",
|
|
127
|
+
});
|
|
128
|
+
expect(resp.price).toBeTruthy();
|
|
129
|
+
|
|
130
|
+
// Create Quote
|
|
131
|
+
const postResp = await sep38.requestQuote({
|
|
132
|
+
sell_asset: "iso4217:USD",
|
|
133
|
+
buy_asset:
|
|
134
|
+
"stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP",
|
|
135
|
+
sell_amount: "5",
|
|
136
|
+
context: "sep6",
|
|
137
|
+
});
|
|
138
|
+
expect(postResp.id).toBeTruthy();
|
|
139
|
+
|
|
140
|
+
// Get Quote
|
|
141
|
+
const quoteId = postResp.id;
|
|
142
|
+
const getResp = await sep38.getQuote(quoteId);
|
|
143
|
+
expect(getResp.id).toBeTruthy();
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import { Wallet } from "
|
|
2
|
+
import { Wallet } from "../../src";
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
RecoveryServer,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
RecoveryRole,
|
|
10
10
|
RecoveryAccountIdentity,
|
|
11
11
|
RecoveryType,
|
|
12
|
-
} from "
|
|
12
|
+
} from "../../src/walletSdk/Types/recovery";
|
|
13
13
|
|
|
14
14
|
describe("Recovery Integration Tests", () => {
|
|
15
15
|
it("should work", async () => {
|
package/test/recovery.test.ts
CHANGED
package/test/sep6.test.ts
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { TransactionBuilder } from "@stellar/stellar-sdk";
|
|
2
|
+
import { Wallet, Server } from "../src";
|
|
3
|
+
|
|
4
|
+
let wallet;
|
|
5
|
+
let account;
|
|
6
|
+
let accountKp;
|
|
7
|
+
const networkPassphrase = "Test SDF Network ; September 2015";
|
|
8
|
+
describe("SEP-10 helpers", () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
wallet = Wallet.TestNet();
|
|
11
|
+
account = wallet.stellar().account();
|
|
12
|
+
accountKp = account.createKeypair();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should validate and sign challenge txn", async () => {
|
|
16
|
+
const validChallengeTx =
|
|
17
|
+
"AAAAAgAAAACpn2Fr7GAZ4XOcFvEz+xduBFDK1NDLQP875GtWWlJ0XQAAAMgAAAAAAAAAAAAAAAEAAAAAZa76AgAAAABlrv2GAAAAAAAAAAIAAAABAAAAALO9GbK9e+E+ul46lJyGjkzjlQnwqNryiqBsIR1vgMlAAAAACgAAABt0ZXN0YW5jaG9yLnN0ZWxsYXIub3JnIGF1dGgAAAAAAQAAAEBRT0ZDTE02OFQ0cVF4Um55TCtRdlBlVTdPeDJYNnhLdzdyenZTbzBBYUdqdUtIdGxQRkpHNTFKMndJazBwMXl2AAAAAQAAAACpn2Fr7GAZ4XOcFvEz+xduBFDK1NDLQP875GtWWlJ0XQAAAAoAAAAPd2ViX2F1dGhfZG9tYWluAAAAAAEAAAAWdGVzdGFuY2hvci5zdGVsbGFyLm9yZwAAAAAAAAAAAAFaUnRdAAAAQG6cMkt4YhwOzgizIimXRX8zTfFjAOItG7kSX14A454KlhGj9ocFhaRpj3tCc4fK45toFCBKRAdyFM7aQq331QI=";
|
|
18
|
+
|
|
19
|
+
let isValid;
|
|
20
|
+
try {
|
|
21
|
+
const signedResp = await Server.signChallengeTransaction({
|
|
22
|
+
accountKp,
|
|
23
|
+
challengeTx: validChallengeTx,
|
|
24
|
+
networkPassphrase,
|
|
25
|
+
anchorDomain: "testanchor.stellar.org",
|
|
26
|
+
});
|
|
27
|
+
const signedTxn = TransactionBuilder.fromXDR(
|
|
28
|
+
signedResp.transaction,
|
|
29
|
+
networkPassphrase,
|
|
30
|
+
);
|
|
31
|
+
expect(signedTxn.signatures.length).toBe(2);
|
|
32
|
+
expect(signedResp.networkPassphrase).toBe(networkPassphrase);
|
|
33
|
+
isValid = true;
|
|
34
|
+
} catch (e) {
|
|
35
|
+
isValid = false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
expect(isValid).toBeTruthy();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should invalidate bad challenge txn", async () => {
|
|
42
|
+
const invalidChallengeTx =
|
|
43
|
+
"AAAAAgAAAABQ5qHpn3ATIgt6yWrU4bhOdEszALPqLHb5V2pTRsYq0QAAAGQAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAACgAAABZ0ZXN0YW5jaG9yLnN0ZWxsYXIub3JnAAAAAAABAAAAQFFPRkNMTTY4VDRxUXhSbnlMK1F2UGVVN094Mlg2eEt3N3J6dlNvMEFhR2p1S0h0bFBGSkc1MUoyd0lrMHAxeXYAAAAAAAAAAA==";
|
|
44
|
+
|
|
45
|
+
let isValid;
|
|
46
|
+
try {
|
|
47
|
+
await Server.signChallengeTransaction({
|
|
48
|
+
accountKp,
|
|
49
|
+
challengeTx: invalidChallengeTx,
|
|
50
|
+
networkPassphrase,
|
|
51
|
+
anchorDomain: "testanchor.stellar.org",
|
|
52
|
+
});
|
|
53
|
+
isValid = true;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
isValid = false;
|
|
56
|
+
}
|
|
57
|
+
expect(isValid).toBeFalsy();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("Server helpers", () => {
|
|
62
|
+
it("should parse a JSON AnchorTransaction", () => {
|
|
63
|
+
const depositJson = `{"id":"82fhs729f63dh0v4","kind":"deposit","status":"pending_external","status_eta":3600,"external_transaction_id":"2dd16cb409513026fbe7defc0c6f826c2d2c65c3da993f747d09bf7dafd31093","more_info_url":"https://youranchor.com/tx/242523523","amount_in":"18.34","amount_out":"18.24","amount_fee":"0.1","started_at":"2017-03-20T17:05:32Z","claimable_balance_id":"00000000c2d8c89264288dbde8488364fd3fd30850fd4e7fbf6d1e9809702558afa4fdea"}`;
|
|
64
|
+
let parsed = Server.parseAnchorTransaction(depositJson);
|
|
65
|
+
expect(parsed.kind).toBe("deposit");
|
|
66
|
+
|
|
67
|
+
const withdrawJson = `{"id":"82fhs729f63dh0v4","kind":"withdrawal","status":"completed","amount_in":"510","amount_out":"490","amount_fee":"5","started_at":"2017-03-20T17:00:02Z","completed_at":"2017-03-20T17:09:58Z","updated_at":"2017-03-20T17:09:58Z","more_info_url":"https://youranchor.com/tx/242523523","stellar_transaction_id":"17a670bc424ff5ce3b386dbfaae9990b66a2a37b4fbe51547e8794962a3f9e6a","external_transaction_id":"1941491","withdraw_anchor_account":"GBANAGOAXH5ONSBI2I6I5LHP2TCRHWMZIAMGUQH2TNKQNCOGJ7GC3ZOL","withdraw_memo":"186384","withdraw_memo_type":"id"}`;
|
|
68
|
+
parsed = Server.parseAnchorTransaction(withdrawJson);
|
|
69
|
+
expect(parsed.kind).toBe("withdrawal");
|
|
70
|
+
});
|
|
71
|
+
});
|
package/test/stellar.test.ts
CHANGED
package/test/transaction.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import { Horizon, MuxedAccount } from "stellar-sdk";
|
|
2
|
+
import { Horizon, MuxedAccount } from "@stellar/stellar-sdk";
|
|
3
3
|
|
|
4
4
|
import { AccountService, SigningKeypair, Stellar, Wallet } from "../src";
|
|
5
5
|
import { IssuedAssetId, NativeAssetId } from "../src/walletSdk/Asset";
|
package/test/wallet.test.ts
CHANGED
package/webpack.config.js
CHANGED
|
@@ -1,35 +1,51 @@
|
|
|
1
1
|
const path = require("path");
|
|
2
|
+
const webpack = require("webpack");
|
|
2
3
|
|
|
3
|
-
module.exports = (env = { NODE: false }) =>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
4
|
+
module.exports = (env = { NODE: false }) => {
|
|
5
|
+
const isBrowser = !env.NODE;
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
mode: "development",
|
|
9
|
+
entry: "./src/index.ts",
|
|
10
|
+
devtool: "source-map",
|
|
11
|
+
module: {
|
|
12
|
+
rules: [
|
|
13
|
+
{
|
|
14
|
+
test: /\.ts$/,
|
|
15
|
+
use: "ts-loader",
|
|
16
|
+
exclude: /node_modules/,
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
resolve: {
|
|
21
|
+
extensions: [".js", ".json", ".ts"],
|
|
22
|
+
fallback: isBrowser
|
|
23
|
+
? {
|
|
24
|
+
crypto: require.resolve("crypto-browserify"),
|
|
25
|
+
http: require.resolve("stream-http"),
|
|
26
|
+
https: require.resolve("https-browserify"),
|
|
27
|
+
stream: require.resolve("stream-browserify"),
|
|
28
|
+
url: require.resolve("url"),
|
|
29
|
+
util: require.resolve("util"),
|
|
30
|
+
vm: require.resolve("vm-browserify"),
|
|
31
|
+
"process/browser": require.resolve("process/browser"),
|
|
32
|
+
}
|
|
33
|
+
: {},
|
|
34
|
+
},
|
|
35
|
+
output: {
|
|
36
|
+
library: "WalletSDK",
|
|
37
|
+
libraryTarget: "umd",
|
|
38
|
+
globalObject: "this",
|
|
39
|
+
filename: `bundle${isBrowser ? "_browser" : ""}.js`,
|
|
40
|
+
path: path.resolve(__dirname, "lib"),
|
|
25
41
|
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
42
|
+
target: isBrowser ? "web" : "node",
|
|
43
|
+
plugins: isBrowser
|
|
44
|
+
? [
|
|
45
|
+
new webpack.ProvidePlugin({
|
|
46
|
+
process: "process/browser",
|
|
47
|
+
}),
|
|
48
|
+
]
|
|
49
|
+
: [],
|
|
50
|
+
};
|
|
51
|
+
};
|