@ledgerhq/hw-app-aptos 6.31.0 → 6.32.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -0
- package/README.md +10 -0
- package/lib/Aptos.d.ts +1 -2
- package/lib/Aptos.d.ts.map +1 -1
- package/lib/Aptos.js +40 -76
- package/lib/Aptos.js.map +1 -1
- package/lib/bip32.d.ts +15 -0
- package/lib/bip32.d.ts.map +1 -0
- package/lib/bip32.js +35 -0
- package/lib/bip32.js.map +1 -0
- package/lib-es/Aptos.d.ts +1 -2
- package/lib-es/Aptos.d.ts.map +1 -1
- package/lib-es/Aptos.js +40 -73
- package/lib-es/Aptos.js.map +1 -1
- package/lib-es/bip32.d.ts +15 -0
- package/lib-es/bip32.d.ts.map +1 -0
- package/lib-es/bip32.js +26 -0
- package/lib-es/bip32.js.map +1 -0
- package/package.json +4 -4
- package/src/Aptos.ts +3 -22
- package/src/bip32.ts +29 -0
- package/tests/bip32.test.ts +27 -0
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @ledgerhq/hw-app-aptos
|
|
2
2
|
|
|
3
|
+
## 6.32.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#9362](https://github.com/LedgerHQ/ledger-live/pull/9362) [`8675df1`](https://github.com/LedgerHQ/ledger-live/commit/8675df12c24067877358f27e1e7c66f739ff0c78) Thanks [@hedi-edelbloute](https://github.com/hedi-edelbloute)! - Fix Aptos derivation path account metadata
|
|
8
|
+
|
|
3
9
|
## 6.31.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@ For a smooth and quick integration:
|
|
|
36
36
|
* [signTransaction](#signtransaction)
|
|
37
37
|
* [Parameters](#parameters-2)
|
|
38
38
|
* [Examples](#examples-2)
|
|
39
|
+
* [bippath](#bippath)
|
|
39
40
|
|
|
40
41
|
### Aptos
|
|
41
42
|
|
|
@@ -113,3 +114,12 @@ const signature = await aptos.signTransaction("44'/144'/0'/0/0", "12000022800000
|
|
|
113
114
|
```
|
|
114
115
|
|
|
115
116
|
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{signature: [Buffer](https://nodejs.org/api/buffer.html)}>** a signature as hex string
|
|
117
|
+
|
|
118
|
+
### bippath
|
|
119
|
+
|
|
120
|
+
BIP32 Path Handling for Aptos Wallets
|
|
121
|
+
|
|
122
|
+
This file provides utility functions to handle BIP32 paths,
|
|
123
|
+
which are commonly used in hierarchical deterministic (HD) wallets.
|
|
124
|
+
It includes functions to convert BIP32 paths to and from different formats,
|
|
125
|
+
extract components from extended public keys (xpubs), and manipulate path elements.
|
package/lib/Aptos.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
********************************************************************************/
|
|
17
17
|
/// <reference types="node" />
|
|
18
|
+
/// <reference types="node" />
|
|
18
19
|
import Transport from "@ledgerhq/hw-transport";
|
|
19
20
|
interface AppConfig {
|
|
20
21
|
version: string;
|
|
@@ -86,8 +87,6 @@ export default class Aptos {
|
|
|
86
87
|
signature: Buffer;
|
|
87
88
|
}>;
|
|
88
89
|
private sendToDevice;
|
|
89
|
-
private pathToBuffer;
|
|
90
|
-
private serializePath;
|
|
91
90
|
private publicKeyToAddress;
|
|
92
91
|
private throwOnFailure;
|
|
93
92
|
}
|
package/lib/Aptos.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Aptos.d.ts","sourceRoot":"","sources":["../src/Aptos.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;kFAekF
|
|
1
|
+
{"version":3,"file":"Aptos.d.ts","sourceRoot":"","sources":["../src/Aptos.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;kFAekF;;;AAGlF,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAkB/C,UAAU,SAAS;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IACxB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS,EAAE,WAAW,SAAU;IAKjD,UAAU,IAAI,OAAO,CAAC,SAAS,CAAC;IAYtC;;;;;;;;;OASG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;IAwBrE;;;;;;;;;OASG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;YAWvE,YAAY;IA+B1B,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,cAAc;CAOvB"}
|
package/lib/Aptos.js
CHANGED
|
@@ -15,22 +15,10 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
********************************************************************************/
|
|
18
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
19
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
-
};
|
|
30
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
const bip32_path_1 = __importDefault(require("bip32-path"));
|
|
32
19
|
const sha3_1 = require("@noble/hashes/sha3");
|
|
33
20
|
const errors_1 = require("@ledgerhq/errors");
|
|
21
|
+
const bip32_1 = require("./bip32");
|
|
34
22
|
const MAX_APDU_LEN = 255;
|
|
35
23
|
const P1_NON_CONFIRM = 0x00;
|
|
36
24
|
const P1_CONFIRM = 0x01;
|
|
@@ -77,17 +65,16 @@ const INS = {
|
|
|
77
65
|
* .catch(e => console.log(`An error occurred (${e.message})`));
|
|
78
66
|
*/
|
|
79
67
|
class Aptos {
|
|
68
|
+
transport;
|
|
80
69
|
constructor(transport, scrambleKey = "aptos") {
|
|
81
70
|
this.transport = transport;
|
|
82
71
|
transport.decorateAppAPIMethods(this, ["getVersion", "getAddress"], scrambleKey);
|
|
83
72
|
}
|
|
84
|
-
getVersion() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
};
|
|
90
|
-
});
|
|
73
|
+
async getVersion() {
|
|
74
|
+
const [major, minor, patch] = await this.sendToDevice(INS.GET_VERSION, P1_NON_CONFIRM, P2_LAST, Buffer.alloc(0));
|
|
75
|
+
return {
|
|
76
|
+
version: `${major}.${minor}.${patch}`,
|
|
77
|
+
};
|
|
91
78
|
}
|
|
92
79
|
/**
|
|
93
80
|
* get Aptos address for a given BIP 32 path.
|
|
@@ -99,22 +86,20 @@ class Aptos {
|
|
|
99
86
|
* const result = await aptos.getAddress("44'/144'/0'/0/0");
|
|
100
87
|
* const { publicKey, address } = result;
|
|
101
88
|
*/
|
|
102
|
-
getAddress(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
};
|
|
117
|
-
});
|
|
89
|
+
async getAddress(path, display = false) {
|
|
90
|
+
const pathBuffer = (0, bip32_1.bip32asBuffer)(path);
|
|
91
|
+
const responseBuffer = await this.sendToDevice(INS.GET_PUBLIC_KEY, display ? P1_CONFIRM : P1_NON_CONFIRM, P2_LAST, pathBuffer);
|
|
92
|
+
let offset = 1;
|
|
93
|
+
const pubKeyLen = responseBuffer.subarray(0, offset)[0] - 1;
|
|
94
|
+
const pubKeyBuffer = responseBuffer.subarray(++offset, (offset += pubKeyLen));
|
|
95
|
+
const chainCodeLen = responseBuffer.subarray(offset, ++offset)[0];
|
|
96
|
+
const chainCodeBuffer = responseBuffer.subarray(offset, offset + chainCodeLen);
|
|
97
|
+
const address = "0x" + this.publicKeyToAddress(pubKeyBuffer).toString("hex");
|
|
98
|
+
return {
|
|
99
|
+
publicKey: pubKeyBuffer,
|
|
100
|
+
chainCode: chainCodeBuffer,
|
|
101
|
+
address,
|
|
102
|
+
};
|
|
118
103
|
}
|
|
119
104
|
/**
|
|
120
105
|
* sign a Aptos transaction with a given BIP 32 path
|
|
@@ -126,50 +111,29 @@ class Aptos {
|
|
|
126
111
|
* @example
|
|
127
112
|
* const signature = await aptos.signTransaction("44'/144'/0'/0/0", "12000022800000002400000002614000000001315D3468400000000000000C73210324E5F600B52BB3D9246D49C4AB1722BA7F32B7A3E4F9F2B8A1A28B9118CC36C48114F31B152151B6F42C1D61FE4139D34B424C8647D183142ECFC1831F6E979C6DA907E88B1CAD602DB59E2F");
|
|
128
113
|
*/
|
|
129
|
-
signTransaction(path, txBuffer) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return { signature: signatureBuffer };
|
|
137
|
-
});
|
|
114
|
+
async signTransaction(path, txBuffer) {
|
|
115
|
+
const pathBuffer = (0, bip32_1.bip32asBuffer)(path);
|
|
116
|
+
await this.sendToDevice(INS.SIGN_TX, P1_START, P2_MORE, pathBuffer);
|
|
117
|
+
const responseBuffer = await this.sendToDevice(INS.SIGN_TX, 1, P2_LAST, txBuffer);
|
|
118
|
+
const signatureLen = responseBuffer[0];
|
|
119
|
+
const signatureBuffer = responseBuffer.subarray(1, 1 + signatureLen);
|
|
120
|
+
return { signature: signatureBuffer };
|
|
138
121
|
}
|
|
139
122
|
// send chunked if payload size exceeds maximum for a call
|
|
140
|
-
sendToDevice(instruction, p1, p2, payload) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
this.throwOnFailure(reply);
|
|
149
|
-
}
|
|
123
|
+
async sendToDevice(instruction, p1, p2, payload) {
|
|
124
|
+
const acceptStatusList = [errors_1.StatusCodes.OK];
|
|
125
|
+
let payloadOffset = 0;
|
|
126
|
+
if (payload.length > MAX_APDU_LEN) {
|
|
127
|
+
while (payload.length - payloadOffset > MAX_APDU_LEN) {
|
|
128
|
+
const buf = payload.subarray(payloadOffset, (payloadOffset += MAX_APDU_LEN));
|
|
129
|
+
const reply = await this.transport.send(LEDGER_CLA, instruction, p1++, P2_MORE, buf, acceptStatusList);
|
|
130
|
+
this.throwOnFailure(reply);
|
|
150
131
|
}
|
|
151
|
-
const buf = payload.subarray(payloadOffset);
|
|
152
|
-
const reply = yield this.transport.send(LEDGER_CLA, instruction, p1, p2, buf, acceptStatusList);
|
|
153
|
-
this.throwOnFailure(reply);
|
|
154
|
-
return reply.subarray(0, reply.length - 2);
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
pathToBuffer(originalPath) {
|
|
158
|
-
const path = originalPath
|
|
159
|
-
.split("/")
|
|
160
|
-
.filter(value => value !== "m")
|
|
161
|
-
.map(value => (value.endsWith("'") || value.endsWith("h") ? value : value + "'"))
|
|
162
|
-
.join("/");
|
|
163
|
-
const pathNums = bip32_path_1.default.fromString(path).toPathArray();
|
|
164
|
-
return this.serializePath(pathNums);
|
|
165
|
-
}
|
|
166
|
-
serializePath(path) {
|
|
167
|
-
const buf = Buffer.alloc(1 + path.length * 4);
|
|
168
|
-
buf.writeUInt8(path.length, 0);
|
|
169
|
-
for (const [i, num] of path.entries()) {
|
|
170
|
-
buf.writeUInt32BE(num, 1 + i * 4);
|
|
171
132
|
}
|
|
172
|
-
|
|
133
|
+
const buf = payload.subarray(payloadOffset);
|
|
134
|
+
const reply = await this.transport.send(LEDGER_CLA, instruction, p1, p2, buf, acceptStatusList);
|
|
135
|
+
this.throwOnFailure(reply);
|
|
136
|
+
return reply.subarray(0, reply.length - 2);
|
|
173
137
|
}
|
|
174
138
|
publicKeyToAddress(pubKey) {
|
|
175
139
|
const hash = sha3_1.sha3_256.create();
|
package/lib/Aptos.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Aptos.js","sourceRoot":"","sources":["../src/Aptos.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;kFAekF
|
|
1
|
+
{"version":3,"file":"Aptos.js","sourceRoot":"","sources":["../src/Aptos.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;kFAekF;;AAElF,6CAA0D;AAE1D,6CAA+C;AAC/C,mCAAwC;AAExC,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,MAAM,OAAO,GAAG,IAAI,CAAC;AAErB,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,GAAG,GAAG;IACV,WAAW,EAAE,IAAI;IACjB,cAAc,EAAE,IAAI;IACpB,OAAO,EAAE,IAAI;CACd,CAAC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HC"}
|
package/lib/bip32.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file bip32.ts
|
|
3
|
+
* @description BIP32 Path Handling for Aptos Wallets
|
|
4
|
+
*
|
|
5
|
+
* This file provides utility functions to handle BIP32 paths,
|
|
6
|
+
* which are commonly used in hierarchical deterministic (HD) wallets.
|
|
7
|
+
* It includes functions to convert BIP32 paths to and from different formats,
|
|
8
|
+
* extract components from extended public keys (xpubs), and manipulate path elements.
|
|
9
|
+
*/
|
|
10
|
+
/// <reference types="node" />
|
|
11
|
+
/// <reference types="node" />
|
|
12
|
+
export declare function pathElementsToBuffer(paths: number[]): Buffer;
|
|
13
|
+
export declare function bip32asBuffer(path: string): Buffer;
|
|
14
|
+
export declare function pathStringToArray(path: string): number[];
|
|
15
|
+
//# sourceMappingURL=bip32.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bip32.d.ts","sourceRoot":"","sources":["../src/bip32.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;;;AAIH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAO5D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGlD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAExD"}
|
package/lib/bip32.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file bip32.ts
|
|
4
|
+
* @description BIP32 Path Handling for Aptos Wallets
|
|
5
|
+
*
|
|
6
|
+
* This file provides utility functions to handle BIP32 paths,
|
|
7
|
+
* which are commonly used in hierarchical deterministic (HD) wallets.
|
|
8
|
+
* It includes functions to convert BIP32 paths to and from different formats,
|
|
9
|
+
* extract components from extended public keys (xpubs), and manipulate path elements.
|
|
10
|
+
*/
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.pathStringToArray = exports.bip32asBuffer = exports.pathElementsToBuffer = void 0;
|
|
16
|
+
const bip32_path_1 = __importDefault(require("bip32-path"));
|
|
17
|
+
function pathElementsToBuffer(paths) {
|
|
18
|
+
const buffer = Buffer.alloc(1 + paths.length * 4);
|
|
19
|
+
buffer[0] = paths.length;
|
|
20
|
+
paths.forEach((element, index) => {
|
|
21
|
+
buffer.writeUInt32BE(element, 1 + 4 * index);
|
|
22
|
+
});
|
|
23
|
+
return buffer;
|
|
24
|
+
}
|
|
25
|
+
exports.pathElementsToBuffer = pathElementsToBuffer;
|
|
26
|
+
function bip32asBuffer(path) {
|
|
27
|
+
const pathElements = !path ? [] : pathStringToArray(path);
|
|
28
|
+
return pathElementsToBuffer(pathElements);
|
|
29
|
+
}
|
|
30
|
+
exports.bip32asBuffer = bip32asBuffer;
|
|
31
|
+
function pathStringToArray(path) {
|
|
32
|
+
return bip32_path_1.default.fromString(path).toPathArray();
|
|
33
|
+
}
|
|
34
|
+
exports.pathStringToArray = pathStringToArray;
|
|
35
|
+
//# sourceMappingURL=bip32.js.map
|
package/lib/bip32.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bip32.js","sourceRoot":"","sources":["../src/bip32.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;AAEH,4DAAiC;AAEjC,SAAgB,oBAAoB,CAAC,KAAe;IAClD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAClD,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;IACzB,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;QAC/B,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAPD,oDAOC;AAED,SAAgB,aAAa,CAAC,IAAY;IACxC,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC1D,OAAO,oBAAoB,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC;AAHD,sCAGC;AAED,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,OAAO,oBAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AAChD,CAAC;AAFD,8CAEC"}
|
package/lib-es/Aptos.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
********************************************************************************/
|
|
17
17
|
/// <reference types="node" />
|
|
18
|
+
/// <reference types="node" />
|
|
18
19
|
import Transport from "@ledgerhq/hw-transport";
|
|
19
20
|
interface AppConfig {
|
|
20
21
|
version: string;
|
|
@@ -86,8 +87,6 @@ export default class Aptos {
|
|
|
86
87
|
signature: Buffer;
|
|
87
88
|
}>;
|
|
88
89
|
private sendToDevice;
|
|
89
|
-
private pathToBuffer;
|
|
90
|
-
private serializePath;
|
|
91
90
|
private publicKeyToAddress;
|
|
92
91
|
private throwOnFailure;
|
|
93
92
|
}
|
package/lib-es/Aptos.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Aptos.d.ts","sourceRoot":"","sources":["../src/Aptos.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;kFAekF
|
|
1
|
+
{"version":3,"file":"Aptos.d.ts","sourceRoot":"","sources":["../src/Aptos.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;kFAekF;;;AAGlF,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAkB/C,UAAU,SAAS;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IACxB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS,EAAE,WAAW,SAAU;IAKjD,UAAU,IAAI,OAAO,CAAC,SAAS,CAAC;IAYtC;;;;;;;;;OASG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;IAwBrE;;;;;;;;;OASG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;YAWvE,YAAY;IA+B1B,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,cAAc;CAOvB"}
|
package/lib-es/Aptos.js
CHANGED
|
@@ -14,18 +14,9 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
********************************************************************************/
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
import BIPPath from "bip32-path";
|
|
27
17
|
import { sha3_256 as sha3Hash } from "@noble/hashes/sha3";
|
|
28
18
|
import { StatusCodes } from "@ledgerhq/errors";
|
|
19
|
+
import { bip32asBuffer } from "./bip32";
|
|
29
20
|
const MAX_APDU_LEN = 255;
|
|
30
21
|
const P1_NON_CONFIRM = 0x00;
|
|
31
22
|
const P1_CONFIRM = 0x01;
|
|
@@ -72,17 +63,16 @@ const INS = {
|
|
|
72
63
|
* .catch(e => console.log(`An error occurred (${e.message})`));
|
|
73
64
|
*/
|
|
74
65
|
export default class Aptos {
|
|
66
|
+
transport;
|
|
75
67
|
constructor(transport, scrambleKey = "aptos") {
|
|
76
68
|
this.transport = transport;
|
|
77
69
|
transport.decorateAppAPIMethods(this, ["getVersion", "getAddress"], scrambleKey);
|
|
78
70
|
}
|
|
79
|
-
getVersion() {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
};
|
|
85
|
-
});
|
|
71
|
+
async getVersion() {
|
|
72
|
+
const [major, minor, patch] = await this.sendToDevice(INS.GET_VERSION, P1_NON_CONFIRM, P2_LAST, Buffer.alloc(0));
|
|
73
|
+
return {
|
|
74
|
+
version: `${major}.${minor}.${patch}`,
|
|
75
|
+
};
|
|
86
76
|
}
|
|
87
77
|
/**
|
|
88
78
|
* get Aptos address for a given BIP 32 path.
|
|
@@ -94,22 +84,20 @@ export default class Aptos {
|
|
|
94
84
|
* const result = await aptos.getAddress("44'/144'/0'/0/0");
|
|
95
85
|
* const { publicKey, address } = result;
|
|
96
86
|
*/
|
|
97
|
-
getAddress(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
};
|
|
112
|
-
});
|
|
87
|
+
async getAddress(path, display = false) {
|
|
88
|
+
const pathBuffer = bip32asBuffer(path);
|
|
89
|
+
const responseBuffer = await this.sendToDevice(INS.GET_PUBLIC_KEY, display ? P1_CONFIRM : P1_NON_CONFIRM, P2_LAST, pathBuffer);
|
|
90
|
+
let offset = 1;
|
|
91
|
+
const pubKeyLen = responseBuffer.subarray(0, offset)[0] - 1;
|
|
92
|
+
const pubKeyBuffer = responseBuffer.subarray(++offset, (offset += pubKeyLen));
|
|
93
|
+
const chainCodeLen = responseBuffer.subarray(offset, ++offset)[0];
|
|
94
|
+
const chainCodeBuffer = responseBuffer.subarray(offset, offset + chainCodeLen);
|
|
95
|
+
const address = "0x" + this.publicKeyToAddress(pubKeyBuffer).toString("hex");
|
|
96
|
+
return {
|
|
97
|
+
publicKey: pubKeyBuffer,
|
|
98
|
+
chainCode: chainCodeBuffer,
|
|
99
|
+
address,
|
|
100
|
+
};
|
|
113
101
|
}
|
|
114
102
|
/**
|
|
115
103
|
* sign a Aptos transaction with a given BIP 32 path
|
|
@@ -121,50 +109,29 @@ export default class Aptos {
|
|
|
121
109
|
* @example
|
|
122
110
|
* const signature = await aptos.signTransaction("44'/144'/0'/0/0", "12000022800000002400000002614000000001315D3468400000000000000C73210324E5F600B52BB3D9246D49C4AB1722BA7F32B7A3E4F9F2B8A1A28B9118CC36C48114F31B152151B6F42C1D61FE4139D34B424C8647D183142ECFC1831F6E979C6DA907E88B1CAD602DB59E2F");
|
|
123
111
|
*/
|
|
124
|
-
signTransaction(path, txBuffer) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return { signature: signatureBuffer };
|
|
132
|
-
});
|
|
112
|
+
async signTransaction(path, txBuffer) {
|
|
113
|
+
const pathBuffer = bip32asBuffer(path);
|
|
114
|
+
await this.sendToDevice(INS.SIGN_TX, P1_START, P2_MORE, pathBuffer);
|
|
115
|
+
const responseBuffer = await this.sendToDevice(INS.SIGN_TX, 1, P2_LAST, txBuffer);
|
|
116
|
+
const signatureLen = responseBuffer[0];
|
|
117
|
+
const signatureBuffer = responseBuffer.subarray(1, 1 + signatureLen);
|
|
118
|
+
return { signature: signatureBuffer };
|
|
133
119
|
}
|
|
134
120
|
// send chunked if payload size exceeds maximum for a call
|
|
135
|
-
sendToDevice(instruction, p1, p2, payload) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
this.throwOnFailure(reply);
|
|
144
|
-
}
|
|
121
|
+
async sendToDevice(instruction, p1, p2, payload) {
|
|
122
|
+
const acceptStatusList = [StatusCodes.OK];
|
|
123
|
+
let payloadOffset = 0;
|
|
124
|
+
if (payload.length > MAX_APDU_LEN) {
|
|
125
|
+
while (payload.length - payloadOffset > MAX_APDU_LEN) {
|
|
126
|
+
const buf = payload.subarray(payloadOffset, (payloadOffset += MAX_APDU_LEN));
|
|
127
|
+
const reply = await this.transport.send(LEDGER_CLA, instruction, p1++, P2_MORE, buf, acceptStatusList);
|
|
128
|
+
this.throwOnFailure(reply);
|
|
145
129
|
}
|
|
146
|
-
const buf = payload.subarray(payloadOffset);
|
|
147
|
-
const reply = yield this.transport.send(LEDGER_CLA, instruction, p1, p2, buf, acceptStatusList);
|
|
148
|
-
this.throwOnFailure(reply);
|
|
149
|
-
return reply.subarray(0, reply.length - 2);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
pathToBuffer(originalPath) {
|
|
153
|
-
const path = originalPath
|
|
154
|
-
.split("/")
|
|
155
|
-
.filter(value => value !== "m")
|
|
156
|
-
.map(value => (value.endsWith("'") || value.endsWith("h") ? value : value + "'"))
|
|
157
|
-
.join("/");
|
|
158
|
-
const pathNums = BIPPath.fromString(path).toPathArray();
|
|
159
|
-
return this.serializePath(pathNums);
|
|
160
|
-
}
|
|
161
|
-
serializePath(path) {
|
|
162
|
-
const buf = Buffer.alloc(1 + path.length * 4);
|
|
163
|
-
buf.writeUInt8(path.length, 0);
|
|
164
|
-
for (const [i, num] of path.entries()) {
|
|
165
|
-
buf.writeUInt32BE(num, 1 + i * 4);
|
|
166
130
|
}
|
|
167
|
-
|
|
131
|
+
const buf = payload.subarray(payloadOffset);
|
|
132
|
+
const reply = await this.transport.send(LEDGER_CLA, instruction, p1, p2, buf, acceptStatusList);
|
|
133
|
+
this.throwOnFailure(reply);
|
|
134
|
+
return reply.subarray(0, reply.length - 2);
|
|
168
135
|
}
|
|
169
136
|
publicKeyToAddress(pubKey) {
|
|
170
137
|
const hash = sha3Hash.create();
|
package/lib-es/Aptos.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Aptos.js","sourceRoot":"","sources":["../src/Aptos.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;kFAekF
|
|
1
|
+
{"version":3,"file":"Aptos.js","sourceRoot":"","sources":["../src/Aptos.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;kFAekF;AAElF,OAAO,EAAE,QAAQ,IAAI,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,MAAM,OAAO,GAAG,IAAI,CAAC;AAErB,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,GAAG,GAAG;IACV,WAAW,EAAE,IAAI;IACjB,cAAc,EAAE,IAAI;IACpB,OAAO,EAAE,IAAI;CACd,CAAC;AAYF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,OAAO,OAAO,KA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ling for Aptos Wallets
|
|
4
|
+
*
|
|
5
|
+
* This file provides utility functions to handle BIP32 paths,
|
|
6
|
+
* which are commonly used in hierarchical deterministic (HD) wallets.
|
|
7
|
+
* It includes functions to convert BIP32 paths to and from different formats,
|
|
8
|
+
* extract components from extended public keys (xpubs), and manipulate path elements.
|
|
9
|
+
*/
|
|
10
|
+
/// <reference types="node" />
|
|
11
|
+
/// <reference types="node" />
|
|
12
|
+
export declare function pathElementsToBuffer(paths: number[]): Buffer;
|
|
13
|
+
export declare function bip32asBuffer(path: string): Buffer;
|
|
14
|
+
export declare function pathStringToArray(path: string): number[];
|
|
15
|
+
//# sourceMappingURL=bip32.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bip32.d.ts","sourceRoot":"","sources":["../src/bip32.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;;;AAIH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAO5D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGlD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAExD"}
|
package/lib-es/bip32.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file bip32.ts
|
|
3
|
+
* @description BIP32 Path Handling for Aptos Wallets
|
|
4
|
+
*
|
|
5
|
+
* This file provides utility functions to handle BIP32 paths,
|
|
6
|
+
* which are commonly used in hierarchical deterministic (HD) wallets.
|
|
7
|
+
* It includes functions to convert BIP32 paths to and from different formats,
|
|
8
|
+
* extract components from extended public keys (xpubs), and manipulate path elements.
|
|
9
|
+
*/
|
|
10
|
+
import bippath from "bip32-path";
|
|
11
|
+
export function pathElementsToBuffer(paths) {
|
|
12
|
+
const buffer = Buffer.alloc(1 + paths.length * 4);
|
|
13
|
+
buffer[0] = paths.length;
|
|
14
|
+
paths.forEach((element, index) => {
|
|
15
|
+
buffer.writeUInt32BE(element, 1 + 4 * index);
|
|
16
|
+
});
|
|
17
|
+
return buffer;
|
|
18
|
+
}
|
|
19
|
+
export function bip32asBuffer(path) {
|
|
20
|
+
const pathElements = !path ? [] : pathStringToArray(path);
|
|
21
|
+
return pathElementsToBuffer(pathElements);
|
|
22
|
+
}
|
|
23
|
+
export function pathStringToArray(path) {
|
|
24
|
+
return bippath.fromString(path).toPathArray();
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=bip32.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bip32.js","sourceRoot":"","sources":["../src/bip32.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,MAAM,UAAU,oBAAoB,CAAC,KAAe;IAClD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAClD,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;IACzB,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;QAC/B,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC1D,OAAO,oBAAoB,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AAChD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/hw-app-aptos",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.32.0",
|
|
4
4
|
"description": "Ledger Hardware Wallet Aptos Application API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/jest": "^29.5.10",
|
|
37
|
-
"@types/node": "^
|
|
37
|
+
"@types/node": "^22.10.10",
|
|
38
38
|
"documentation": "14.0.2",
|
|
39
39
|
"jest": "^29.7.0",
|
|
40
40
|
"rimraf": "^4.4.1",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"gitHead": "dd0dea64b58e5a9125c8a422dcffd29e5ef6abec",
|
|
47
47
|
"scripts": {
|
|
48
48
|
"clean": "rimraf lib lib-es",
|
|
49
|
-
"build": "tsc && tsc -m
|
|
49
|
+
"build": "tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es",
|
|
50
50
|
"prewatch": "pnpm build",
|
|
51
51
|
"watch": "tsc --watch",
|
|
52
|
-
"watch:es": "tsc --watch -m
|
|
52
|
+
"watch:es": "tsc --watch -m esnext --moduleResolution bundler --outDir lib-es",
|
|
53
53
|
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
54
54
|
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
55
55
|
"lint:fix": "pnpm lint --fix",
|
package/src/Aptos.ts
CHANGED
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
********************************************************************************/
|
|
17
17
|
|
|
18
|
-
import BIPPath from "bip32-path";
|
|
19
18
|
import { sha3_256 as sha3Hash } from "@noble/hashes/sha3";
|
|
20
19
|
import Transport from "@ledgerhq/hw-transport";
|
|
21
20
|
import { StatusCodes } from "@ledgerhq/errors";
|
|
21
|
+
import { bip32asBuffer } from "./bip32";
|
|
22
22
|
|
|
23
23
|
const MAX_APDU_LEN = 255;
|
|
24
24
|
const P1_NON_CONFIRM = 0x00;
|
|
@@ -108,7 +108,7 @@ export default class Aptos {
|
|
|
108
108
|
* const { publicKey, address } = result;
|
|
109
109
|
*/
|
|
110
110
|
async getAddress(path: string, display = false): Promise<AddressData> {
|
|
111
|
-
const pathBuffer =
|
|
111
|
+
const pathBuffer = bip32asBuffer(path);
|
|
112
112
|
const responseBuffer = await this.sendToDevice(
|
|
113
113
|
INS.GET_PUBLIC_KEY,
|
|
114
114
|
display ? P1_CONFIRM : P1_NON_CONFIRM,
|
|
@@ -142,7 +142,7 @@ export default class Aptos {
|
|
|
142
142
|
* const signature = await aptos.signTransaction("44'/144'/0'/0/0", "12000022800000002400000002614000000001315D3468400000000000000C73210324E5F600B52BB3D9246D49C4AB1722BA7F32B7A3E4F9F2B8A1A28B9118CC36C48114F31B152151B6F42C1D61FE4139D34B424C8647D183142ECFC1831F6E979C6DA907E88B1CAD602DB59E2F");
|
|
143
143
|
*/
|
|
144
144
|
async signTransaction(path: string, txBuffer: Buffer): Promise<{ signature: Buffer }> {
|
|
145
|
-
const pathBuffer =
|
|
145
|
+
const pathBuffer = bip32asBuffer(path);
|
|
146
146
|
await this.sendToDevice(INS.SIGN_TX, P1_START, P2_MORE, pathBuffer);
|
|
147
147
|
const responseBuffer = await this.sendToDevice(INS.SIGN_TX, 1, P2_LAST, txBuffer);
|
|
148
148
|
|
|
@@ -183,25 +183,6 @@ export default class Aptos {
|
|
|
183
183
|
return reply.subarray(0, reply.length - 2);
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
private pathToBuffer(originalPath: string): Buffer {
|
|
187
|
-
const path = originalPath
|
|
188
|
-
.split("/")
|
|
189
|
-
.filter(value => value !== "m")
|
|
190
|
-
.map(value => (value.endsWith("'") || value.endsWith("h") ? value : value + "'"))
|
|
191
|
-
.join("/");
|
|
192
|
-
const pathNums: number[] = BIPPath.fromString(path).toPathArray();
|
|
193
|
-
return this.serializePath(pathNums);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
private serializePath(path: number[]): Buffer {
|
|
197
|
-
const buf = Buffer.alloc(1 + path.length * 4);
|
|
198
|
-
buf.writeUInt8(path.length, 0);
|
|
199
|
-
for (const [i, num] of path.entries()) {
|
|
200
|
-
buf.writeUInt32BE(num, 1 + i * 4);
|
|
201
|
-
}
|
|
202
|
-
return buf;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
186
|
private publicKeyToAddress(pubKey: Buffer): Buffer {
|
|
206
187
|
const hash = sha3Hash.create();
|
|
207
188
|
hash.update(pubKey);
|
package/src/bip32.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file bip32.ts
|
|
3
|
+
* @description BIP32 Path Handling for Aptos Wallets
|
|
4
|
+
*
|
|
5
|
+
* This file provides utility functions to handle BIP32 paths,
|
|
6
|
+
* which are commonly used in hierarchical deterministic (HD) wallets.
|
|
7
|
+
* It includes functions to convert BIP32 paths to and from different formats,
|
|
8
|
+
* extract components from extended public keys (xpubs), and manipulate path elements.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import bippath from "bip32-path";
|
|
12
|
+
|
|
13
|
+
export function pathElementsToBuffer(paths: number[]): Buffer {
|
|
14
|
+
const buffer = Buffer.alloc(1 + paths.length * 4);
|
|
15
|
+
buffer[0] = paths.length;
|
|
16
|
+
paths.forEach((element, index) => {
|
|
17
|
+
buffer.writeUInt32BE(element, 1 + 4 * index);
|
|
18
|
+
});
|
|
19
|
+
return buffer;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function bip32asBuffer(path: string): Buffer {
|
|
23
|
+
const pathElements = !path ? [] : pathStringToArray(path);
|
|
24
|
+
return pathElementsToBuffer(pathElements);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function pathStringToArray(path: string): number[] {
|
|
28
|
+
return bippath.fromString(path).toPathArray();
|
|
29
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { pathElementsToBuffer, bip32asBuffer } from "../src/bip32";
|
|
2
|
+
|
|
3
|
+
describe("Aptos bip32asBuffer", () => {
|
|
4
|
+
test("pathElementsToBuffer", () => {
|
|
5
|
+
const arg = [44, 637, 1, 0, 0];
|
|
6
|
+
const expected = Buffer.from([
|
|
7
|
+
0x05, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x02, 0x7d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
|
|
8
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
9
|
+
]);
|
|
10
|
+
expect(pathElementsToBuffer(arg)).toStrictEqual(expected);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("bip32asBuffer", () => {
|
|
14
|
+
const arg = "44'/637'/1'/0'/0'";
|
|
15
|
+
const expected = Buffer.from([
|
|
16
|
+
0x05, 0x80, 0x00, 0x00, 0x2c, 0x80, 0x00, 0x02, 0x7d, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00,
|
|
17
|
+
0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
|
|
18
|
+
]);
|
|
19
|
+
expect(bip32asBuffer(arg)).toStrictEqual(expected);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("bip32asBuffer with empty string", () => {
|
|
23
|
+
const arg = "";
|
|
24
|
+
const expected = Buffer.from([0x00]);
|
|
25
|
+
expect(bip32asBuffer(arg)).toStrictEqual(expected);
|
|
26
|
+
});
|
|
27
|
+
});
|