@stellar/typescript-wallet-sdk 1.3.1 → 1.4.1
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/jest.integration.config.js +1 -1
- package/lib/bundle.js +1880 -1723
- package/lib/bundle.js.map +1 -1
- package/lib/bundle_browser.js +23189 -9762
- package/lib/bundle_browser.js.map +1 -1
- package/lib/index.d.ts +5 -0
- package/lib/walletSdk/Anchor/index.d.ts +2 -0
- package/lib/walletSdk/Exceptions/index.d.ts +15 -0
- package/lib/walletSdk/Server/index.d.ts +21 -0
- package/lib/walletSdk/Types/auth.d.ts +11 -1
- package/lib/walletSdk/Types/index.d.ts +1 -0
- package/lib/walletSdk/index.d.ts +3 -1
- package/package.json +7 -10
- package/src/index.ts +6 -0
- package/src/walletSdk/Anchor/index.ts +8 -4
- package/src/walletSdk/Auth/index.ts +3 -3
- package/src/walletSdk/Exceptions/index.ts +35 -0
- 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 +7 -8
- package/src/walletSdk/Server/index.ts +95 -0
- package/src/walletSdk/Types/auth.ts +13 -1
- package/src/walletSdk/Types/index.ts +1 -0
- package/src/walletSdk/index.ts +13 -1
- package/test/accountService.test.ts +12 -40
- package/test/integration/anchorplatform.test.ts +145 -0
- package/test/{integration.test.ts → integration/recovery.test.ts} +2 -2
- package/test/sep6.test.ts +1 -1
- package/test/server.test.ts +71 -0
- 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/docs/WalletGuide.md +0 -5
- package/jest.config.js +0 -9
- package/prettier.config.js +0 -1
package/lib/index.d.ts
CHANGED
|
@@ -24,6 +24,11 @@ export { Utils };
|
|
|
24
24
|
*/
|
|
25
25
|
import * as Exceptions from "./walletSdk/Exceptions";
|
|
26
26
|
export { Exceptions };
|
|
27
|
+
/**
|
|
28
|
+
* Server
|
|
29
|
+
*/
|
|
30
|
+
import * as Server from "./walletSdk/Server";
|
|
31
|
+
export { Server };
|
|
27
32
|
import * as walletSdk from "./walletSdk";
|
|
28
33
|
import { Keypair } from "@stellar/stellar-sdk";
|
|
29
34
|
export { walletSdk, Keypair };
|
|
@@ -9,6 +9,7 @@ import { AnchorServiceInfo, TomlInfo, AuthToken } from "../Types";
|
|
|
9
9
|
type AnchorParams = {
|
|
10
10
|
cfg: Config;
|
|
11
11
|
homeDomain: string;
|
|
12
|
+
allowHttp?: boolean;
|
|
12
13
|
httpClient: AxiosInstance;
|
|
13
14
|
language: string;
|
|
14
15
|
};
|
|
@@ -26,6 +27,7 @@ export declare class Anchor {
|
|
|
26
27
|
language: string;
|
|
27
28
|
private cfg;
|
|
28
29
|
private homeDomain;
|
|
30
|
+
private allowHttp;
|
|
29
31
|
private httpClient;
|
|
30
32
|
private toml;
|
|
31
33
|
/**
|
|
@@ -100,3 +100,18 @@ export declare class NoAccountAndNoSponsorError extends Error {
|
|
|
100
100
|
export declare class Sep38PriceOnlyOneAmountError extends Error {
|
|
101
101
|
constructor();
|
|
102
102
|
}
|
|
103
|
+
export declare class ChallengeTxnIncorrectSequenceError extends Error {
|
|
104
|
+
constructor();
|
|
105
|
+
}
|
|
106
|
+
export declare class ChallengeTxnInvalidSignatureError extends Error {
|
|
107
|
+
constructor();
|
|
108
|
+
}
|
|
109
|
+
export declare class AllowHttpOnNonTestnetError extends Error {
|
|
110
|
+
constructor();
|
|
111
|
+
}
|
|
112
|
+
export declare class UnknownAnchorTransactionError extends Error {
|
|
113
|
+
constructor();
|
|
114
|
+
}
|
|
115
|
+
export declare class InvalidJsonError extends Error {
|
|
116
|
+
constructor();
|
|
117
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code in the Server module is written to be used by server side
|
|
3
|
+
* applications.
|
|
4
|
+
*/
|
|
5
|
+
import { SignChallengeTxnParams, SignChallengeTxnResponse, AnchorTransaction } from "../Types";
|
|
6
|
+
/**
|
|
7
|
+
* Helper method for signing a SEP-10 challenge transaction if valid.
|
|
8
|
+
* @param {SignChallengeTxnParams} params - The Authentication params.
|
|
9
|
+
* @param {AccountKeypair} params.accountKp - Keypair for the Stellar account signing the transaction.
|
|
10
|
+
* @param {string} [params.challengeTx] - The challenge transaction given by an anchor for authentication.
|
|
11
|
+
* @param {string} [params.networkPassphrase] - The network passphrase for the network authenticating on.
|
|
12
|
+
* @param {string} [params.anchorDomain] - Domain hosting stellar.toml file containing `SIGNING_KEY`.
|
|
13
|
+
* @returns {Promise<SignChallengeTxnResponse>} The signed transaction.
|
|
14
|
+
*/
|
|
15
|
+
export declare const signChallengeTransaction: ({ accountKp, challengeTx, networkPassphrase, anchorDomain, }: SignChallengeTxnParams) => Promise<SignChallengeTxnResponse>;
|
|
16
|
+
/**
|
|
17
|
+
* Helper method for parsing a JSON string into an AnchorTransaction.
|
|
18
|
+
* @param {string} transaction - The json string of an anchor transaction.
|
|
19
|
+
* @returns {AnchorTransaction} The transaction object.
|
|
20
|
+
*/
|
|
21
|
+
export declare const parseAnchorTransaction: (transaction: string) => AnchorTransaction;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transaction } from "@stellar/stellar-sdk";
|
|
2
2
|
import { WalletSigner } from "../Auth/WalletSigner";
|
|
3
|
-
import { AccountKeypair } from "../Horizon/Account";
|
|
3
|
+
import { AccountKeypair, SigningKeypair } from "../Horizon/Account";
|
|
4
4
|
export type AuthenticateParams = {
|
|
5
5
|
accountKp: AccountKeypair;
|
|
6
6
|
walletSigner?: WalletSigner;
|
|
@@ -46,3 +46,13 @@ export type SignWithDomainAccountParams = {
|
|
|
46
46
|
export type HttpHeaders = {
|
|
47
47
|
[key: string]: string;
|
|
48
48
|
};
|
|
49
|
+
export type SignChallengeTxnParams = {
|
|
50
|
+
accountKp: SigningKeypair;
|
|
51
|
+
challengeTx: string;
|
|
52
|
+
networkPassphrase: string;
|
|
53
|
+
anchorDomain: string;
|
|
54
|
+
};
|
|
55
|
+
export type SignChallengeTxnResponse = {
|
|
56
|
+
transaction: XdrEncodedTransaction;
|
|
57
|
+
networkPassphrase: NetworkPassphrase;
|
|
58
|
+
};
|
package/lib/walletSdk/index.d.ts
CHANGED
|
@@ -36,10 +36,12 @@ export declare class Wallet {
|
|
|
36
36
|
* @param {WalletAnchor} params - The anchor params.
|
|
37
37
|
* @param {string} params.homeDomain - The home domain of the anchor. This domain will be used for
|
|
38
38
|
* things like getting the toml info.
|
|
39
|
+
* @param {allowHttp} [params.allowHttp] - Flag to allow http protocol for the home domain.
|
|
40
|
+
* Defaults to false, and can only be set to true on Testnet.
|
|
39
41
|
* @param {string} [params.language=this.language] - The language setting for the Anchor.
|
|
40
42
|
* @returns {Anchor} An Anchor instance.
|
|
41
43
|
*/
|
|
42
|
-
anchor({ homeDomain, language }: WalletAnchor): Anchor;
|
|
44
|
+
anchor({ homeDomain, allowHttp, language, }: WalletAnchor): Anchor;
|
|
43
45
|
/**
|
|
44
46
|
* Create a Stellar instance for interacting with the Stellar network.
|
|
45
47
|
* @returns {Stellar} A Stellar instance.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stellar/typescript-wallet-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"private": false,
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@babel/preset-env": "^7.20.2",
|
|
14
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
14
15
|
"@stellar/prettier-config": "^1.0.1",
|
|
15
16
|
"@stellar/tsconfig": "^1.0.2",
|
|
16
17
|
"@types/jest": "^29.4.0",
|
|
@@ -30,6 +31,7 @@
|
|
|
30
31
|
"npm-run-all": "^4.1.5",
|
|
31
32
|
"prettier": "^2.0.5",
|
|
32
33
|
"pretty-quick": "^2.0.1",
|
|
34
|
+
"process": "^0.11.10",
|
|
33
35
|
"sinon": "^15.1.0",
|
|
34
36
|
"stream-browserify": "^3.0.0",
|
|
35
37
|
"ts-jest": "^29.0.5",
|
|
@@ -50,22 +52,17 @@
|
|
|
50
52
|
"stream-http": "^3.2.0",
|
|
51
53
|
"url": "^0.11.0",
|
|
52
54
|
"util": "^0.12.5",
|
|
53
|
-
"utility-types": "^3.10.0"
|
|
55
|
+
"utility-types": "^3.10.0",
|
|
56
|
+
"vm-browserify": "^1.1.2"
|
|
54
57
|
},
|
|
55
58
|
"scripts": {
|
|
56
|
-
"lint": "eslint . --ext .ts",
|
|
57
|
-
"prepare": "husky install",
|
|
58
59
|
"test": "jest --watchAll",
|
|
59
60
|
"test:ci": "jest --ci",
|
|
60
|
-
"test:
|
|
61
|
+
"test:recovery:ci": "jest --config jest.integration.config.js recovery.test.ts --ci",
|
|
62
|
+
"test:anchorplatform:ci": "yarn jest --config jest.integration.config.js anchorplatform.test.ts --ci",
|
|
61
63
|
"build:web": "webpack --config webpack.config.js",
|
|
62
64
|
"build:node": "webpack --env NODE=true --config webpack.config.js",
|
|
63
65
|
"build": "run-p build:web build:node",
|
|
64
66
|
"example:sep24": "ts-node examples/sep24/sep24.ts"
|
|
65
|
-
},
|
|
66
|
-
"lint-staged": {
|
|
67
|
-
"**/*.ts": [
|
|
68
|
-
"eslint --fix --max-warnings 0"
|
|
69
|
-
]
|
|
70
67
|
}
|
|
71
68
|
}
|
package/src/index.ts
CHANGED
|
@@ -42,6 +42,12 @@ export { Utils };
|
|
|
42
42
|
import * as Exceptions from "./walletSdk/Exceptions";
|
|
43
43
|
export { Exceptions };
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Server
|
|
47
|
+
*/
|
|
48
|
+
import * as Server from "./walletSdk/Server";
|
|
49
|
+
export { Server };
|
|
50
|
+
|
|
45
51
|
import * as walletSdk from "./walletSdk";
|
|
46
52
|
import { Keypair } from "@stellar/stellar-sdk";
|
|
47
53
|
// TODO - figure out why Keypair used in parent codebase throws error
|
|
@@ -19,6 +19,7 @@ import { parseToml } from "../Utils";
|
|
|
19
19
|
type AnchorParams = {
|
|
20
20
|
cfg: Config;
|
|
21
21
|
homeDomain: string;
|
|
22
|
+
allowHttp?: boolean;
|
|
22
23
|
httpClient: AxiosInstance;
|
|
23
24
|
language: string;
|
|
24
25
|
};
|
|
@@ -43,6 +44,7 @@ export class Anchor {
|
|
|
43
44
|
|
|
44
45
|
private cfg: Config;
|
|
45
46
|
private homeDomain: string;
|
|
47
|
+
private allowHttp: boolean;
|
|
46
48
|
private httpClient: AxiosInstance;
|
|
47
49
|
private toml: TomlInfo;
|
|
48
50
|
|
|
@@ -52,10 +54,10 @@ export class Anchor {
|
|
|
52
54
|
* @param {AnchorParams} params - The parameters to initialize the Anchor.
|
|
53
55
|
*/
|
|
54
56
|
constructor(params: AnchorParams) {
|
|
55
|
-
const { cfg, homeDomain, httpClient, language } = params;
|
|
56
|
-
|
|
57
|
+
const { cfg, homeDomain, httpClient, language, allowHttp = false } = params;
|
|
57
58
|
this.cfg = cfg;
|
|
58
59
|
this.homeDomain = homeDomain;
|
|
60
|
+
this.allowHttp = allowHttp;
|
|
59
61
|
this.httpClient = httpClient;
|
|
60
62
|
this.language = language;
|
|
61
63
|
}
|
|
@@ -72,8 +74,10 @@ export class Anchor {
|
|
|
72
74
|
return this.toml;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
const stellarToml = await StellarToml.Resolver.resolve(this.homeDomain, {
|
|
78
|
+
allowHttp: this.allowHttp,
|
|
79
|
+
});
|
|
80
|
+
|
|
77
81
|
const parsedToml = parseToml(stellarToml);
|
|
78
82
|
this.toml = parsedToml;
|
|
79
83
|
return parsedToml;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
-
import
|
|
2
|
+
import { TransactionBuilder, Transaction } from "@stellar/stellar-sdk";
|
|
3
3
|
import { decode } from "jws";
|
|
4
4
|
|
|
5
5
|
import { Config } from "walletSdk";
|
|
@@ -118,10 +118,10 @@ export class Sep10 {
|
|
|
118
118
|
challengeResponse,
|
|
119
119
|
walletSigner,
|
|
120
120
|
}: SignParams): Promise<Transaction> {
|
|
121
|
-
let transaction: Transaction =
|
|
121
|
+
let transaction: Transaction = TransactionBuilder.fromXDR(
|
|
122
122
|
challengeResponse.transaction,
|
|
123
123
|
challengeResponse.network_passphrase,
|
|
124
|
-
);
|
|
124
|
+
) as Transaction;
|
|
125
125
|
|
|
126
126
|
// check if verifying client domain as well
|
|
127
127
|
for (const op of transaction.operations) {
|
|
@@ -270,3 +270,38 @@ export class Sep38PriceOnlyOneAmountError extends Error {
|
|
|
270
270
|
Object.setPrototypeOf(this, Sep38PriceOnlyOneAmountError.prototype);
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
|
+
|
|
274
|
+
export class ChallengeTxnIncorrectSequenceError extends Error {
|
|
275
|
+
constructor() {
|
|
276
|
+
super("Challenge transaction sequence number must be 0");
|
|
277
|
+
Object.setPrototypeOf(this, ChallengeTxnIncorrectSequenceError.prototype);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export class ChallengeTxnInvalidSignatureError extends Error {
|
|
282
|
+
constructor() {
|
|
283
|
+
super("Invalid signature for challenge transaction");
|
|
284
|
+
Object.setPrototypeOf(this, ChallengeTxnInvalidSignatureError.prototype);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export class AllowHttpOnNonTestnetError extends Error {
|
|
289
|
+
constructor() {
|
|
290
|
+
super("Can only allow Http on Testnet");
|
|
291
|
+
Object.setPrototypeOf(this, AllowHttpOnNonTestnetError.prototype);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export class UnknownAnchorTransactionError extends Error {
|
|
296
|
+
constructor() {
|
|
297
|
+
super("Unknown AnchorTransaction type parse failed");
|
|
298
|
+
Object.setPrototypeOf(this, UnknownAnchorTransactionError.prototype);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export class InvalidJsonError extends Error {
|
|
303
|
+
constructor() {
|
|
304
|
+
super("Invalid Json given");
|
|
305
|
+
Object.setPrototypeOf(this, InvalidJsonError.prototype);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Operation, xdr } from "@stellar/stellar-sdk";
|
|
2
2
|
import { IssuedAssetId } from "../../Asset";
|
|
3
3
|
import { AccountKeypair } from "../Account";
|
|
4
4
|
|
|
@@ -19,7 +19,7 @@ export abstract class CommonTransactionBuilder<T> {
|
|
|
19
19
|
*/
|
|
20
20
|
addAssetSupport(asset: IssuedAssetId, trustLimit?: string): T {
|
|
21
21
|
this.operations.push(
|
|
22
|
-
|
|
22
|
+
Operation.changeTrust({
|
|
23
23
|
asset: asset.toAsset(),
|
|
24
24
|
limit: trustLimit,
|
|
25
25
|
source: this.sourceAddress,
|
|
@@ -46,7 +46,7 @@ export abstract class CommonTransactionBuilder<T> {
|
|
|
46
46
|
*/
|
|
47
47
|
addAccountSigner(signerAddress: AccountKeypair, signerWeight: number): T {
|
|
48
48
|
this.operations.push(
|
|
49
|
-
|
|
49
|
+
Operation.setOptions({
|
|
50
50
|
source: this.sourceAddress,
|
|
51
51
|
signer: {
|
|
52
52
|
ed25519PublicKey: signerAddress.publicKey,
|
|
@@ -75,7 +75,7 @@ export abstract class CommonTransactionBuilder<T> {
|
|
|
75
75
|
*/
|
|
76
76
|
lockAccountMasterKey(): T {
|
|
77
77
|
this.operations.push(
|
|
78
|
-
|
|
78
|
+
Operation.setOptions({
|
|
79
79
|
source: this.sourceAddress,
|
|
80
80
|
masterWeight: 0,
|
|
81
81
|
}),
|
|
@@ -102,7 +102,7 @@ export abstract class CommonTransactionBuilder<T> {
|
|
|
102
102
|
high?: number;
|
|
103
103
|
}): T {
|
|
104
104
|
this.operations.push(
|
|
105
|
-
|
|
105
|
+
Operation.setOptions({
|
|
106
106
|
source: this.sourceAddress,
|
|
107
107
|
lowThreshold: low,
|
|
108
108
|
medThreshold: medium,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Operation, xdr } from "@stellar/stellar-sdk";
|
|
2
2
|
|
|
3
3
|
import { CommonTransactionBuilder } from "./CommonTransactionBuilder";
|
|
4
4
|
import { AccountKeypair } from "../Account";
|
|
@@ -45,7 +45,7 @@ export class SponsoringBuilder extends CommonTransactionBuilder<SponsoringBuilde
|
|
|
45
45
|
startingBalance: number = 0,
|
|
46
46
|
): SponsoringBuilder {
|
|
47
47
|
this.operations.push(
|
|
48
|
-
|
|
48
|
+
Operation.createAccount({
|
|
49
49
|
destination: newAccount.publicKey,
|
|
50
50
|
startingBalance: startingBalance.toString(),
|
|
51
51
|
source: this.sponsorAccount.publicKey,
|
|
@@ -60,7 +60,7 @@ export class SponsoringBuilder extends CommonTransactionBuilder<SponsoringBuilde
|
|
|
60
60
|
*/
|
|
61
61
|
startSponsoring() {
|
|
62
62
|
this.operations.push(
|
|
63
|
-
|
|
63
|
+
Operation.beginSponsoringFutureReserves({
|
|
64
64
|
sponsoredId: this.sourceAddress,
|
|
65
65
|
source: this.sponsorAccount.publicKey,
|
|
66
66
|
}),
|
|
@@ -73,7 +73,7 @@ export class SponsoringBuilder extends CommonTransactionBuilder<SponsoringBuilde
|
|
|
73
73
|
*/
|
|
74
74
|
stopSponsoring() {
|
|
75
75
|
this.operations.push(
|
|
76
|
-
|
|
76
|
+
Operation.endSponsoringFutureReserves({
|
|
77
77
|
source: this.sourceAddress,
|
|
78
78
|
}),
|
|
79
79
|
);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
Operation,
|
|
2
3
|
TransactionBuilder as StellarTransactionBuilder,
|
|
3
4
|
Account as StellarAccount,
|
|
4
5
|
Transaction,
|
|
@@ -101,7 +102,7 @@ export class TransactionBuilder extends CommonTransactionBuilder<TransactionBuil
|
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
this.operations.push(
|
|
104
|
-
|
|
105
|
+
Operation.createAccount({
|
|
105
106
|
destination: newAccount.publicKey,
|
|
106
107
|
startingBalance: startingBalance.toString(),
|
|
107
108
|
source: this.sourceAddress,
|
|
@@ -123,7 +124,7 @@ export class TransactionBuilder extends CommonTransactionBuilder<TransactionBuil
|
|
|
123
124
|
amount: string,
|
|
124
125
|
): TransactionBuilder {
|
|
125
126
|
this.operations.push(
|
|
126
|
-
|
|
127
|
+
Operation.payment({
|
|
127
128
|
destination: destinationAddress,
|
|
128
129
|
asset: assetId.toAsset(),
|
|
129
130
|
amount,
|
|
@@ -167,7 +168,7 @@ export class TransactionBuilder extends CommonTransactionBuilder<TransactionBuil
|
|
|
167
168
|
}
|
|
168
169
|
if (sendAmount) {
|
|
169
170
|
this.operations.push(
|
|
170
|
-
|
|
171
|
+
Operation.pathPaymentStrictSend({
|
|
171
172
|
destination: destinationAddress,
|
|
172
173
|
sendAsset: sendAsset.toAsset(),
|
|
173
174
|
sendAmount,
|
|
@@ -177,7 +178,7 @@ export class TransactionBuilder extends CommonTransactionBuilder<TransactionBuil
|
|
|
177
178
|
);
|
|
178
179
|
} else {
|
|
179
180
|
this.operations.push(
|
|
180
|
-
|
|
181
|
+
Operation.pathPaymentStrictReceive({
|
|
181
182
|
destination: destinationAddress,
|
|
182
183
|
sendAsset: sendAsset.toAsset(),
|
|
183
184
|
destAmount,
|
|
@@ -289,9 +290,7 @@ export class TransactionBuilder extends CommonTransactionBuilder<TransactionBuil
|
|
|
289
290
|
* @returns {TransactionBuilder} The TransactionBuilder instance.
|
|
290
291
|
*/
|
|
291
292
|
accountMerge(destination: string, source?: string): TransactionBuilder {
|
|
292
|
-
this.operations.push(
|
|
293
|
-
StellarSdk.Operation.accountMerge({ destination, source }),
|
|
294
|
-
);
|
|
293
|
+
this.operations.push(Operation.accountMerge({ destination, source }));
|
|
295
294
|
return this;
|
|
296
295
|
}
|
|
297
296
|
|
|
@@ -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
|
+
};
|
|
@@ -2,7 +2,7 @@ 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
|
+
};
|
package/src/walletSdk/index.ts
CHANGED
|
@@ -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
|
});
|
|
@@ -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 () => {
|