@ledgerhq/wallet-api-exchange-module 0.1.0 → 0.2.0-next.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/lib-es/package.json +1 -0
- package/package.json +11 -40
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -20
- package/.turbo/turbo-build.log +0 -4
- package/.unimportedrc.json +0 -5
- package/jest.config.js +0 -10
- package/src/index.ts +0 -180
- package/src/types.ts +0 -52
- package/tsconfig.json +0 -15
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/wallet-api-exchange-module",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-next.0",
|
|
4
4
|
"description": "Wallet-API Exchange Module for Ledger Live",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -14,6 +14,13 @@
|
|
|
14
14
|
"url": "https://github.com/LedgerHQ/ledger-live/issues"
|
|
15
15
|
},
|
|
16
16
|
"homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/exchange-module",
|
|
17
|
+
"main": "lib/index.js",
|
|
18
|
+
"module": "lib-es/index.js",
|
|
19
|
+
"types": "lib/index.d.ts",
|
|
20
|
+
"files": [
|
|
21
|
+
"/lib",
|
|
22
|
+
"/lib-es"
|
|
23
|
+
],
|
|
17
24
|
"publishConfig": {
|
|
18
25
|
"access": "public"
|
|
19
26
|
},
|
|
@@ -22,50 +29,14 @@
|
|
|
22
29
|
"@ledgerhq/wallet-api-core": "^1.6.0"
|
|
23
30
|
},
|
|
24
31
|
"devDependencies": {
|
|
25
|
-
"@types/
|
|
26
|
-
"@types/node": "^20.2.5",
|
|
27
|
-
"jest": "^28.1.1",
|
|
28
|
-
"jest-environment-jsdom": "28",
|
|
29
|
-
"ts-jest": "^28.0.5"
|
|
30
|
-
},
|
|
31
|
-
"typesVersions": {
|
|
32
|
-
"*": {
|
|
33
|
-
"*.json": [
|
|
34
|
-
"*.json"
|
|
35
|
-
],
|
|
36
|
-
"*": [
|
|
37
|
-
"lib/*"
|
|
38
|
-
],
|
|
39
|
-
"lib/*": [
|
|
40
|
-
"lib/*"
|
|
41
|
-
],
|
|
42
|
-
"lib-es/*": [
|
|
43
|
-
"lib-es/*"
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"exports": {
|
|
48
|
-
"./lib/*": "./lib/*.js",
|
|
49
|
-
"./lib/*.js": "./lib/*.js",
|
|
50
|
-
"./lib-es/*": "./lib-es/*.js",
|
|
51
|
-
"./lib-es/*.js": "./lib-es/*.js",
|
|
52
|
-
"./*": {
|
|
53
|
-
"require": "./lib/*.js",
|
|
54
|
-
"default": "./lib-es/*.js"
|
|
55
|
-
},
|
|
56
|
-
"./*.js": {
|
|
57
|
-
"require": "./lib/*.js",
|
|
58
|
-
"default": "./lib-es/*.js"
|
|
59
|
-
},
|
|
60
|
-
"./package.json": "./package.json"
|
|
32
|
+
"@types/node": "^20.2.5"
|
|
61
33
|
},
|
|
62
34
|
"scripts": {
|
|
63
35
|
"clean": "rimraf lib lib-es",
|
|
64
|
-
"build": "tsc && tsc -m ES6 --outDir lib-es",
|
|
36
|
+
"build": "tsc && tsc -m ES6 --outDir lib-es && echo '{ \"type\": \"module\" }' > lib-es/package.json",
|
|
65
37
|
"prewatch": "pnpm build",
|
|
66
38
|
"watch": "tsc --watch",
|
|
67
39
|
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx",
|
|
68
|
-
"lint:fix": "pnpm lint --fix"
|
|
69
|
-
"test": "jest"
|
|
40
|
+
"lint:fix": "pnpm lint --fix"
|
|
70
41
|
}
|
|
71
42
|
}
|
package/.eslintignore
DELETED
package/.eslintrc.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
env: {
|
|
3
|
-
browser: true,
|
|
4
|
-
es6: true,
|
|
5
|
-
},
|
|
6
|
-
overrides: [
|
|
7
|
-
{
|
|
8
|
-
files: ["src/**/*.test.{ts,tsx}"],
|
|
9
|
-
env: {
|
|
10
|
-
"jest/globals": true,
|
|
11
|
-
},
|
|
12
|
-
plugins: ["jest"],
|
|
13
|
-
},
|
|
14
|
-
],
|
|
15
|
-
rules: {
|
|
16
|
-
"no-console": ["error", { allow: ["warn", "error"] }],
|
|
17
|
-
"@typescript-eslint/no-empty-function": "off",
|
|
18
|
-
"@typescript-eslint/no-explicit-any": "warn",
|
|
19
|
-
},
|
|
20
|
-
};
|
package/.turbo/turbo-build.log
DELETED
package/.unimportedrc.json
DELETED
package/jest.config.js
DELETED
package/src/index.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { CustomModule, Transaction, serializeTransaction } from "@ledgerhq/wallet-api-client";
|
|
2
|
-
import {
|
|
3
|
-
ExchangeCompleteParams,
|
|
4
|
-
ExchangeCompleteResult,
|
|
5
|
-
ExchangeStartParams,
|
|
6
|
-
ExchangeStartResult,
|
|
7
|
-
} from "./types";
|
|
8
|
-
|
|
9
|
-
export * from "./types";
|
|
10
|
-
|
|
11
|
-
// TODO maybe find a better way to type the available custom requests with correct types
|
|
12
|
-
export class ExchangeModule extends CustomModule {
|
|
13
|
-
/**
|
|
14
|
-
* Start the exchange process by generating a nonce on Ledger device
|
|
15
|
-
* @param exchangeType - used by the exchange transport to discern between swap/sell/fund
|
|
16
|
-
*
|
|
17
|
-
* @returns - A transaction ID used to complete the exchange process
|
|
18
|
-
*/
|
|
19
|
-
async start(exchangeType: ExchangeStartParams["exchangeType"]) {
|
|
20
|
-
const result = await this.request<ExchangeStartParams, ExchangeStartResult>(
|
|
21
|
-
"custom.exchange.start",
|
|
22
|
-
{
|
|
23
|
-
exchangeType,
|
|
24
|
-
},
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
return result.transactionId;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Complete an exchange swap process by passing by the exchange content and its signature.
|
|
32
|
-
* User will be prompted on its device to approve the swap exchange operation.
|
|
33
|
-
* If the exchange is validated, the transaction is then signed and broadcasted to the network.
|
|
34
|
-
* @param provider - Used to verify the signature
|
|
35
|
-
* @param fromAccountId - Identifier of the account used as a source for the tx or parent account (for "new token")
|
|
36
|
-
* @param toAccountId - Identifier of the account or parent account (for "new token") used as a destination
|
|
37
|
-
* @param swapId - Identifier of the swap used by backend
|
|
38
|
-
* @param rate - Swap rate in the transaction
|
|
39
|
-
* @param tokenCurrency - "new token" used in the transaction, not listed yet in wallet-api list
|
|
40
|
-
* @param transaction - Transaction containing the recipient and amount
|
|
41
|
-
* @param binaryPayload - Blueprint of the data that we'll allow signing
|
|
42
|
-
* @param signature - Ensures the source of the payload
|
|
43
|
-
* @param feesStrategy - Slow / Medium / Fast
|
|
44
|
-
*
|
|
45
|
-
* @returns - The broadcasted transaction hash.
|
|
46
|
-
*/
|
|
47
|
-
async completeSwap({
|
|
48
|
-
provider,
|
|
49
|
-
fromAccountId,
|
|
50
|
-
toAccountId,
|
|
51
|
-
swapId,
|
|
52
|
-
rate,
|
|
53
|
-
transaction,
|
|
54
|
-
binaryPayload,
|
|
55
|
-
signature,
|
|
56
|
-
feeStrategy,
|
|
57
|
-
tokenCurrency,
|
|
58
|
-
}: {
|
|
59
|
-
provider: string;
|
|
60
|
-
fromAccountId: string;
|
|
61
|
-
toAccountId: string;
|
|
62
|
-
swapId: string;
|
|
63
|
-
rate: number;
|
|
64
|
-
transaction: Transaction;
|
|
65
|
-
binaryPayload: Buffer;
|
|
66
|
-
signature: Buffer;
|
|
67
|
-
feeStrategy: ExchangeCompleteParams["feeStrategy"];
|
|
68
|
-
tokenCurrency?: string;
|
|
69
|
-
}) {
|
|
70
|
-
const result = await this.request<ExchangeCompleteParams, ExchangeCompleteResult>(
|
|
71
|
-
"custom.exchange.complete",
|
|
72
|
-
{
|
|
73
|
-
exchangeType: "SWAP",
|
|
74
|
-
provider,
|
|
75
|
-
fromAccountId,
|
|
76
|
-
toAccountId,
|
|
77
|
-
swapId,
|
|
78
|
-
rate,
|
|
79
|
-
rawTransaction: serializeTransaction(transaction),
|
|
80
|
-
hexBinaryPayload: binaryPayload.toString("hex"),
|
|
81
|
-
hexSignature: signature.toString("hex"),
|
|
82
|
-
feeStrategy,
|
|
83
|
-
tokenCurrency,
|
|
84
|
-
},
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
return result.transactionHash;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Complete an exchange sell process by passing by the exchange content and its signature.
|
|
92
|
-
* User will be prompted on its device to approve the sell exchange operation.
|
|
93
|
-
* If the exchange is validated, the transaction is then signed and broadcasted to the network.
|
|
94
|
-
* @param provider - Used to verify the signature
|
|
95
|
-
* @param fromAccountId - Identifier of the account used as a source for the tx
|
|
96
|
-
* @param transaction - Transaction containing the recipient and amount
|
|
97
|
-
* @param binaryPayload - Blueprint of the data that we'll allow signing
|
|
98
|
-
* @param signature - Ensures the source of the payload
|
|
99
|
-
* @param feesStrategy - Slow / Medium / Fast
|
|
100
|
-
*
|
|
101
|
-
* @returns - The broadcasted transaction hash.
|
|
102
|
-
*/
|
|
103
|
-
async completeSell({
|
|
104
|
-
provider,
|
|
105
|
-
fromAccountId,
|
|
106
|
-
transaction,
|
|
107
|
-
binaryPayload,
|
|
108
|
-
signature,
|
|
109
|
-
feeStrategy,
|
|
110
|
-
}: {
|
|
111
|
-
provider: string;
|
|
112
|
-
fromAccountId: string;
|
|
113
|
-
transaction: Transaction;
|
|
114
|
-
binaryPayload: Buffer;
|
|
115
|
-
signature: Buffer;
|
|
116
|
-
feeStrategy: ExchangeCompleteParams["feeStrategy"];
|
|
117
|
-
}): Promise<string> {
|
|
118
|
-
const result = await this.request<ExchangeCompleteParams, ExchangeCompleteResult>(
|
|
119
|
-
"custom.exchange.complete",
|
|
120
|
-
{
|
|
121
|
-
exchangeType: "SELL",
|
|
122
|
-
provider,
|
|
123
|
-
fromAccountId,
|
|
124
|
-
rawTransaction: serializeTransaction(transaction),
|
|
125
|
-
hexBinaryPayload: binaryPayload.toString("hex"),
|
|
126
|
-
hexSignature: signature.toString("hex"),
|
|
127
|
-
feeStrategy,
|
|
128
|
-
},
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
return result.transactionHash;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Complete an exchange fund process by passing by the exchange content and its signature.
|
|
136
|
-
* User will be prompted on its device to approve the fund exchange operation.
|
|
137
|
-
* If the exchange is validated, the transaction is then signed and broadcasted to the network.
|
|
138
|
-
* @param provider - Used to verify the signature
|
|
139
|
-
* @param fromAccountId - Identifier of the account used as a source for the tx
|
|
140
|
-
* @param transaction - Transaction containing the recipient and amount
|
|
141
|
-
* @param binaryPayload - Blueprint of the data that we'll allow signing
|
|
142
|
-
* @param signature - Ensures the source of the payload
|
|
143
|
-
* @param feesStrategy - Slow / Medium / Fast
|
|
144
|
-
*
|
|
145
|
-
* @returns - The broadcasted transaction hash.
|
|
146
|
-
*/
|
|
147
|
-
async completeFund({
|
|
148
|
-
provider,
|
|
149
|
-
fromAccountId,
|
|
150
|
-
transaction,
|
|
151
|
-
binaryPayload,
|
|
152
|
-
signature,
|
|
153
|
-
feeStrategy,
|
|
154
|
-
tokenCurrency,
|
|
155
|
-
}: {
|
|
156
|
-
provider: string;
|
|
157
|
-
fromAccountId: string;
|
|
158
|
-
transaction: Transaction;
|
|
159
|
-
binaryPayload: Buffer;
|
|
160
|
-
signature: Buffer;
|
|
161
|
-
feeStrategy: ExchangeCompleteParams["feeStrategy"];
|
|
162
|
-
tokenCurrency?: string;
|
|
163
|
-
}): Promise<string> {
|
|
164
|
-
const result = await this.request<ExchangeCompleteParams, ExchangeCompleteResult>(
|
|
165
|
-
"custom.exchange.complete",
|
|
166
|
-
{
|
|
167
|
-
exchangeType: "FUND",
|
|
168
|
-
provider,
|
|
169
|
-
fromAccountId,
|
|
170
|
-
rawTransaction: serializeTransaction(transaction),
|
|
171
|
-
hexBinaryPayload: binaryPayload.toString("hex"),
|
|
172
|
-
hexSignature: signature.toString("hex"),
|
|
173
|
-
feeStrategy,
|
|
174
|
-
tokenCurrency,
|
|
175
|
-
},
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
return result.transactionHash;
|
|
179
|
-
}
|
|
180
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { RawTransaction } from "@ledgerhq/wallet-api-core";
|
|
2
|
-
|
|
3
|
-
export enum ExchangeType {
|
|
4
|
-
SWAP = 0x00,
|
|
5
|
-
SELL = 0x01,
|
|
6
|
-
FUND = 0x02,
|
|
7
|
-
SWAP_NG = 0x03,
|
|
8
|
-
SELL_NG = 0x04,
|
|
9
|
-
FUND_NG = 0x05,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type ExchangeStartParams = {
|
|
13
|
-
exchangeType: "FUND" | "SELL" | "SWAP" | "FUND_NG" | "SELL_NG" | "SWAP_NG";
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type ExchangeStartResult = {
|
|
17
|
-
transactionId: string;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type ExchangeCompleteBaseParams = {
|
|
21
|
-
provider: string;
|
|
22
|
-
fromAccountId: string;
|
|
23
|
-
rawTransaction: RawTransaction;
|
|
24
|
-
hexBinaryPayload: string;
|
|
25
|
-
hexSignature: string;
|
|
26
|
-
feeStrategy: "SLOW" | "MEDIUM" | "FAST" | "CUSTOM";
|
|
27
|
-
tokenCurrency?: string;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type ExchangeCompleteFundParams = ExchangeCompleteBaseParams & {
|
|
31
|
-
exchangeType: "FUND";
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type ExchangeCompleteSellParams = ExchangeCompleteBaseParams & {
|
|
35
|
-
exchangeType: "SELL";
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export type ExchangeCompleteSwapParams = ExchangeCompleteBaseParams & {
|
|
39
|
-
exchangeType: "SWAP";
|
|
40
|
-
toAccountId: string;
|
|
41
|
-
swapId: string;
|
|
42
|
-
rate: number;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type ExchangeCompleteParams =
|
|
46
|
-
| ExchangeCompleteFundParams
|
|
47
|
-
| ExchangeCompleteSellParams
|
|
48
|
-
| ExchangeCompleteSwapParams;
|
|
49
|
-
|
|
50
|
-
export type ExchangeCompleteResult = {
|
|
51
|
-
transactionHash: string;
|
|
52
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"declarationMap": true,
|
|
6
|
-
"noImplicitAny": false,
|
|
7
|
-
"noImplicitThis": false,
|
|
8
|
-
"downlevelIteration": true,
|
|
9
|
-
"module": "commonjs",
|
|
10
|
-
"lib": ["es2020", "dom"],
|
|
11
|
-
"jsx": "react",
|
|
12
|
-
"outDir": "lib"
|
|
13
|
-
},
|
|
14
|
-
"include": ["src/**/*"]
|
|
15
|
-
}
|