@pezkuwi/hw-ledger 14.0.6 → 14.0.7
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/package.json +153 -3
- package/build/Ledger.js +0 -112
- package/build/LedgerGeneric.js +0 -211
- package/build/README.md +0 -2
- package/build/bundle.js +0 -2
- package/build/cjs/Ledger.d.ts +0 -43
- package/build/cjs/Ledger.js +0 -117
- package/build/cjs/LedgerGeneric.d.ts +0 -63
- package/build/cjs/LedgerGeneric.js +0 -216
- package/build/cjs/bundle.d.ts +0 -2
- package/build/cjs/bundle.js +0 -7
- package/build/cjs/constants.js +0 -7
- package/build/cjs/defaults.js +0 -61
- package/build/cjs/index.js +0 -5
- package/build/cjs/packageInfo.js +0 -4
- package/build/cjs/types.js +0 -2
- package/build/constants.d.ts +0 -4
- package/build/constants.js +0 -4
- package/build/defaults.d.ts +0 -14
- package/build/defaults.js +0 -58
- package/build/index.d.ts +0 -2
- package/build/index.js +0 -2
- package/build/package.json +0 -178
- package/build/packageDetect.d.ts +0 -1
- package/build/packageDetect.js +0 -5
- package/build/packageInfo.d.ts +0 -6
- package/build/packageInfo.js +0 -1
- package/build/types.d.ts +0 -34
- package/build/types.js +0 -1
- package/build-deno/Ledger.ts +0 -144
- package/build-deno/LedgerGeneric.ts +0 -271
- package/build-deno/README.md +0 -2
- package/build-deno/bundle.ts +0 -3
- package/build-deno/constants.ts +0 -8
- package/build-deno/defaults.ts +0 -61
- package/build-deno/index.ts +0 -4
- package/build-deno/mod.ts +0 -2
- package/build-deno/packageDetect.ts +0 -9
- package/build-deno/packageInfo.ts +0 -3
- package/build-deno/types.ts +0 -42
- package/build-tsc-cjs/packageDetect.js +0 -7
- package/src/Ledger.ts +0 -144
- package/src/LedgerGeneric.ts +0 -275
- package/src/bundle.ts +0 -8
- package/src/constants.ts +0 -10
- package/src/defaults.spec.ts +0 -20
- package/src/defaults.ts +0 -69
- package/src/index.ts +0 -6
- package/src/mod.ts +0 -4
- package/src/packageDetect.ts +0 -13
- package/src/packageInfo.ts +0 -6
- package/src/types.ts +0 -42
- package/tsconfig.build.json +0 -16
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.spec.json +0 -16
- package/tsconfig.spec.tsbuildinfo +0 -1
- /package/{build/LICENSE → LICENSE} +0 -0
- /package/{build-tsc/Ledger.d.ts → Ledger.d.ts} +0 -0
- /package/{build-tsc-esm/Ledger.js → Ledger.js} +0 -0
- /package/{build-tsc/LedgerGeneric.d.ts → LedgerGeneric.d.ts} +0 -0
- /package/{build-tsc-esm/LedgerGeneric.js → LedgerGeneric.js} +0 -0
- /package/{build/bundle-pezkuwi-hw-ledger.js → bundle-pezkuwi-hw-ledger.js} +0 -0
- /package/{build-tsc/bundle.d.ts → bundle.d.ts} +0 -0
- /package/{build-tsc-esm/bundle.js → bundle.js} +0 -0
- /package/{build → cjs}/Ledger.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/Ledger.js +0 -0
- /package/{build → cjs}/LedgerGeneric.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/LedgerGeneric.js +0 -0
- /package/{build → cjs}/bundle.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/bundle.js +0 -0
- /package/{build-tsc → cjs}/constants.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/constants.js +0 -0
- /package/{build-tsc → cjs}/defaults.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/defaults.js +0 -0
- /package/{build-tsc → cjs}/index.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/index.js +0 -0
- /package/{build/cjs → cjs}/package.json +0 -0
- /package/{build-tsc → cjs}/packageDetect.d.ts +0 -0
- /package/{build/cjs → cjs}/packageDetect.js +0 -0
- /package/{build-tsc → cjs}/packageInfo.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/packageInfo.js +0 -0
- /package/{build-tsc → cjs}/types.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/types.js +0 -0
- /package/{build/cjs/constants.d.ts → constants.d.ts} +0 -0
- /package/{build-tsc-esm/constants.js → constants.js} +0 -0
- /package/{build/cjs/defaults.d.ts → defaults.d.ts} +0 -0
- /package/{build-tsc-esm/defaults.js → defaults.js} +0 -0
- /package/{build/cjs/index.d.ts → index.d.ts} +0 -0
- /package/{build-tsc-esm/index.js → index.js} +0 -0
- /package/{build/cjs/packageDetect.d.ts → packageDetect.d.ts} +0 -0
- /package/{build-tsc-esm/packageDetect.js → packageDetect.js} +0 -0
- /package/{build/cjs/packageInfo.d.ts → packageInfo.d.ts} +0 -0
- /package/{build-tsc-esm/packageInfo.js → packageInfo.js} +0 -0
- /package/{build/cjs/types.d.ts → types.d.ts} +0 -0
- /package/{build-tsc-esm/types.js → types.js} +0 -0
package/package.json
CHANGED
|
@@ -14,11 +14,161 @@
|
|
|
14
14
|
},
|
|
15
15
|
"sideEffects": [
|
|
16
16
|
"./packageDetect.js",
|
|
17
|
-
"./packageDetect.
|
|
17
|
+
"./cjs/packageDetect.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "14.0.
|
|
21
|
-
"main": "index.js",
|
|
20
|
+
"version": "14.0.7",
|
|
21
|
+
"main": "./cjs/index.js",
|
|
22
|
+
"module": "./index.js",
|
|
23
|
+
"types": "./index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
"./cjs/package.json": "./cjs/package.json",
|
|
26
|
+
"./cjs/*": "./cjs/*.js",
|
|
27
|
+
".": {
|
|
28
|
+
"module": {
|
|
29
|
+
"types": "./index.d.ts",
|
|
30
|
+
"default": "./index.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./cjs/index.d.ts",
|
|
34
|
+
"default": "./cjs/index.js"
|
|
35
|
+
},
|
|
36
|
+
"default": {
|
|
37
|
+
"types": "./index.d.ts",
|
|
38
|
+
"default": "./index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"./bundle": {
|
|
42
|
+
"module": {
|
|
43
|
+
"types": "./bundle.d.ts",
|
|
44
|
+
"default": "./bundle.js"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./cjs/bundle.d.ts",
|
|
48
|
+
"default": "./cjs/bundle.js"
|
|
49
|
+
},
|
|
50
|
+
"default": {
|
|
51
|
+
"types": "./bundle.d.ts",
|
|
52
|
+
"default": "./bundle.js"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"./constants": {
|
|
56
|
+
"module": {
|
|
57
|
+
"types": "./constants.d.ts",
|
|
58
|
+
"default": "./constants.js"
|
|
59
|
+
},
|
|
60
|
+
"require": {
|
|
61
|
+
"types": "./cjs/constants.d.ts",
|
|
62
|
+
"default": "./cjs/constants.js"
|
|
63
|
+
},
|
|
64
|
+
"default": {
|
|
65
|
+
"types": "./constants.d.ts",
|
|
66
|
+
"default": "./constants.js"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"./defaults": {
|
|
70
|
+
"module": {
|
|
71
|
+
"types": "./defaults.d.ts",
|
|
72
|
+
"default": "./defaults.js"
|
|
73
|
+
},
|
|
74
|
+
"require": {
|
|
75
|
+
"types": "./cjs/defaults.d.ts",
|
|
76
|
+
"default": "./cjs/defaults.js"
|
|
77
|
+
},
|
|
78
|
+
"default": {
|
|
79
|
+
"types": "./defaults.d.ts",
|
|
80
|
+
"default": "./defaults.js"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"./Ledger": {
|
|
84
|
+
"module": {
|
|
85
|
+
"types": "./Ledger.d.ts",
|
|
86
|
+
"default": "./Ledger.js"
|
|
87
|
+
},
|
|
88
|
+
"require": {
|
|
89
|
+
"types": "./cjs/Ledger.d.ts",
|
|
90
|
+
"default": "./cjs/Ledger.js"
|
|
91
|
+
},
|
|
92
|
+
"default": {
|
|
93
|
+
"types": "./Ledger.d.ts",
|
|
94
|
+
"default": "./Ledger.js"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"./LedgerGeneric": {
|
|
98
|
+
"module": {
|
|
99
|
+
"types": "./LedgerGeneric.d.ts",
|
|
100
|
+
"default": "./LedgerGeneric.js"
|
|
101
|
+
},
|
|
102
|
+
"require": {
|
|
103
|
+
"types": "./cjs/LedgerGeneric.d.ts",
|
|
104
|
+
"default": "./cjs/LedgerGeneric.js"
|
|
105
|
+
},
|
|
106
|
+
"default": {
|
|
107
|
+
"types": "./LedgerGeneric.d.ts",
|
|
108
|
+
"default": "./LedgerGeneric.js"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"./package.json": {
|
|
112
|
+
"require": "./cjs/package.json",
|
|
113
|
+
"default": "./package.json"
|
|
114
|
+
},
|
|
115
|
+
"./packageDetect": {
|
|
116
|
+
"module": {
|
|
117
|
+
"types": "./packageDetect.d.ts",
|
|
118
|
+
"default": "./packageDetect.js"
|
|
119
|
+
},
|
|
120
|
+
"require": {
|
|
121
|
+
"types": "./cjs/packageDetect.d.ts",
|
|
122
|
+
"default": "./cjs/packageDetect.js"
|
|
123
|
+
},
|
|
124
|
+
"default": {
|
|
125
|
+
"types": "./packageDetect.d.ts",
|
|
126
|
+
"default": "./packageDetect.js"
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"./packageInfo.js": {
|
|
130
|
+
"module": {
|
|
131
|
+
"types": "./packageInfo.d.ts",
|
|
132
|
+
"default": "./packageInfo.js"
|
|
133
|
+
},
|
|
134
|
+
"require": {
|
|
135
|
+
"types": "./cjs/packageInfo.d.ts",
|
|
136
|
+
"default": "./cjs/packageInfo.js"
|
|
137
|
+
},
|
|
138
|
+
"default": {
|
|
139
|
+
"types": "./packageInfo.d.ts",
|
|
140
|
+
"default": "./packageInfo.js"
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
"./packageInfo": {
|
|
144
|
+
"module": {
|
|
145
|
+
"types": "./packageInfo.d.ts",
|
|
146
|
+
"default": "./packageInfo.js"
|
|
147
|
+
},
|
|
148
|
+
"require": {
|
|
149
|
+
"types": "./cjs/packageInfo.d.ts",
|
|
150
|
+
"default": "./cjs/packageInfo.js"
|
|
151
|
+
},
|
|
152
|
+
"default": {
|
|
153
|
+
"types": "./packageInfo.d.ts",
|
|
154
|
+
"default": "./packageInfo.js"
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
"./types": {
|
|
158
|
+
"module": {
|
|
159
|
+
"types": "./types.d.ts",
|
|
160
|
+
"default": "./types.js"
|
|
161
|
+
},
|
|
162
|
+
"require": {
|
|
163
|
+
"types": "./cjs/types.d.ts",
|
|
164
|
+
"default": "./cjs/types.js"
|
|
165
|
+
},
|
|
166
|
+
"default": {
|
|
167
|
+
"types": "./types.d.ts",
|
|
168
|
+
"default": "./types.js"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
},
|
|
22
172
|
"dependencies": {
|
|
23
173
|
"@pezkuwi/hw-ledger-transports": "14.0.1",
|
|
24
174
|
"@pezkuwi/util": "14.0.1",
|
package/build/Ledger.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { newSubstrateApp } from '@zondax/ledger-substrate';
|
|
2
|
-
import { transports } from '@pezkuwi/hw-ledger-transports';
|
|
3
|
-
import { hexAddPrefix, u8aToBuffer, u8aWrapBytes } from '@pezkuwi/util';
|
|
4
|
-
import { LEDGER_DEFAULT_ACCOUNT, LEDGER_DEFAULT_CHANGE, LEDGER_DEFAULT_INDEX, LEDGER_SUCCESS_CODE } from './constants.js';
|
|
5
|
-
import { ledgerApps } from './defaults.js';
|
|
6
|
-
export { packageInfo } from './packageInfo.js';
|
|
7
|
-
/** @internal Wraps a SubstrateApp call, checking the result for any errors which result in a rejection */
|
|
8
|
-
async function wrapError(promise) {
|
|
9
|
-
const result = await promise;
|
|
10
|
-
if (result.return_code !== LEDGER_SUCCESS_CODE) {
|
|
11
|
-
throw new Error(result.error_message);
|
|
12
|
-
}
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
/** @internal Wraps a sign/signRaw call and returns the associated signature */
|
|
16
|
-
function sign(method, message, accountOffset = 0, addressOffset = 0, { account = LEDGER_DEFAULT_ACCOUNT, addressIndex = LEDGER_DEFAULT_INDEX, change = LEDGER_DEFAULT_CHANGE } = {}) {
|
|
17
|
-
return async (app) => {
|
|
18
|
-
const { signature } = await wrapError(app[method](account + accountOffset, change, addressIndex + addressOffset, u8aToBuffer(message)));
|
|
19
|
-
return {
|
|
20
|
-
signature: hexAddPrefix(signature.toString('hex'))
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @name Ledger
|
|
26
|
-
*
|
|
27
|
-
* @description
|
|
28
|
-
* Legacy wrapper for a ledger app -
|
|
29
|
-
* - it connects automatically on use, creating an underlying interface as required
|
|
30
|
-
* - Promises reject with errors (unwrapped errors from @zondax/ledger-substrate)
|
|
31
|
-
* @deprecated Use LedgerGeneric for up to date integration with ledger
|
|
32
|
-
*/
|
|
33
|
-
export class Ledger {
|
|
34
|
-
#ledgerName;
|
|
35
|
-
#transportDef;
|
|
36
|
-
#app = null;
|
|
37
|
-
constructor(transport, chain) {
|
|
38
|
-
const ledgerName = ledgerApps[chain];
|
|
39
|
-
const transportDef = transports.find(({ type }) => type === transport);
|
|
40
|
-
if (!ledgerName) {
|
|
41
|
-
throw new Error(`Unsupported Ledger chain ${chain}`);
|
|
42
|
-
}
|
|
43
|
-
else if (!transportDef) {
|
|
44
|
-
throw new Error(`Unsupported Ledger transport ${transport}`);
|
|
45
|
-
}
|
|
46
|
-
this.#ledgerName = ledgerName;
|
|
47
|
-
this.#transportDef = transportDef;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Returns the address associated with a specific account & address offset. Optionally
|
|
51
|
-
* asks for on-device confirmation
|
|
52
|
-
*/
|
|
53
|
-
async getAddress(confirm = false, accountOffset = 0, addressOffset = 0, { account = LEDGER_DEFAULT_ACCOUNT, addressIndex = LEDGER_DEFAULT_INDEX, change = LEDGER_DEFAULT_CHANGE } = {}) {
|
|
54
|
-
return this.withApp(async (app) => {
|
|
55
|
-
const { address, pubKey } = await wrapError(app.getAddress(account + accountOffset, change, addressIndex + addressOffset, confirm));
|
|
56
|
-
return {
|
|
57
|
-
address,
|
|
58
|
-
publicKey: hexAddPrefix(pubKey)
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Returns the version of the Ledger application on the device
|
|
64
|
-
*/
|
|
65
|
-
async getVersion() {
|
|
66
|
-
return this.withApp(async (app) => {
|
|
67
|
-
const { device_locked: isLocked, major, minor, patch, test_mode: isTestMode } = await wrapError(app.getVersion());
|
|
68
|
-
return {
|
|
69
|
-
isLocked,
|
|
70
|
-
isTestMode,
|
|
71
|
-
version: [major, minor, patch]
|
|
72
|
-
};
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Signs a transaction on the Ledger device
|
|
77
|
-
*/
|
|
78
|
-
async sign(message, accountOffset, addressOffset, options) {
|
|
79
|
-
return this.withApp(sign('sign', message, accountOffset, addressOffset, options));
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Signs a message (non-transactional) on the Ledger device
|
|
83
|
-
*/
|
|
84
|
-
async signRaw(message, accountOffset, addressOffset, options) {
|
|
85
|
-
return this.withApp(sign('signRaw', u8aWrapBytes(message), accountOffset, addressOffset, options));
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* @internal
|
|
89
|
-
*
|
|
90
|
-
* Returns a created SubstrateApp to perform operations against. Generally
|
|
91
|
-
* this is only used internally, to ensure consistent bahavior.
|
|
92
|
-
*/
|
|
93
|
-
async withApp(fn) {
|
|
94
|
-
try {
|
|
95
|
-
if (!this.#app) {
|
|
96
|
-
const transport = await this.#transportDef.create();
|
|
97
|
-
// We need this override for the actual type passing - the Deno environment
|
|
98
|
-
// is quite a bit stricter and it yields invalids between the two (specifically
|
|
99
|
-
// since we mangle the imports from .default in the types for CJS/ESM and between
|
|
100
|
-
// esm.sh versions this yields problematic outputs)
|
|
101
|
-
//
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
103
|
-
this.#app = newSubstrateApp(transport, this.#ledgerName);
|
|
104
|
-
}
|
|
105
|
-
return await fn(this.#app);
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
this.#app = null;
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
package/build/LedgerGeneric.js
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { PolkadotGenericApp } from '@zondax/ledger-substrate';
|
|
2
|
-
import { transports } from '@pezkuwi/hw-ledger-transports';
|
|
3
|
-
import { hexAddPrefix, u8aToBuffer, u8aWrapBytes } from '@pezkuwi/util';
|
|
4
|
-
import { ledgerApps } from './defaults.js';
|
|
5
|
-
export { packageInfo } from './packageInfo.js';
|
|
6
|
-
/** @internal Wraps a PolkadotGenericApp call, checking the result for any errors which result in a rejection */
|
|
7
|
-
async function wrapError(promise) {
|
|
8
|
-
let result;
|
|
9
|
-
try {
|
|
10
|
-
result = await promise;
|
|
11
|
-
}
|
|
12
|
-
catch (e) {
|
|
13
|
-
// We check to see if the propogated error is the newer ResponseError type.
|
|
14
|
-
// The response code use to be part of the result, but with the latest breaking changes from 0.42.x
|
|
15
|
-
// the interface and it's types have completely changed.
|
|
16
|
-
if (e.returnCode) {
|
|
17
|
-
throw new Error(`${e.returnCode}: ${e.errorMessage}`);
|
|
18
|
-
}
|
|
19
|
-
throw new Error(e.message);
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
/** @internal Wraps a signEd25519/signRawEd25519 call and returns the associated signature */
|
|
24
|
-
function sign(method, message, slip44, accountIndex = 0, addressOffset = 0) {
|
|
25
|
-
const bip42Path = `m/44'/${slip44}'/${accountIndex}'/${0}'/${addressOffset}'`;
|
|
26
|
-
return async (app) => {
|
|
27
|
-
const { signature } = await wrapError(app[method](bip42Path, u8aToBuffer(message)));
|
|
28
|
-
return {
|
|
29
|
-
signature: hexAddPrefix(signature.toString('hex'))
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/** @internal Wraps a signEcdsa/signRawEcdsa call and returns the associated signature */
|
|
34
|
-
function signEcdsa(method, message, slip44, accountIndex = 0, addressOffset = 0) {
|
|
35
|
-
const bip42Path = `m/44'/${slip44}'/${accountIndex}'/${0}'/${addressOffset}'`;
|
|
36
|
-
return async (app) => {
|
|
37
|
-
const { r, s, v } = await wrapError(app[method](bip42Path, u8aToBuffer(message)));
|
|
38
|
-
const signature = Buffer.concat([r, s, v]);
|
|
39
|
-
return {
|
|
40
|
-
signature: hexAddPrefix(signature.toString('hex'))
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/** @internal Wraps a signWithMetadataEd25519 call and returns the associated signature */
|
|
45
|
-
function signWithMetadata(message, slip44, accountIndex = 0, addressOffset = 0, { metadata } = {}) {
|
|
46
|
-
const bip42Path = `m/44'/${slip44}'/${accountIndex}'/${0}'/${addressOffset}'`;
|
|
47
|
-
return async (app) => {
|
|
48
|
-
if (!metadata) {
|
|
49
|
-
throw new Error('The metadata option must be present when using signWithMetadata');
|
|
50
|
-
}
|
|
51
|
-
const bufferMsg = Buffer.from(message);
|
|
52
|
-
const { signature } = await wrapError(app.signWithMetadataEd25519(bip42Path, bufferMsg, metadata));
|
|
53
|
-
return {
|
|
54
|
-
signature: hexAddPrefix(signature.toString('hex'))
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
/** @internal Wraps a signWithMetadataEcdsa call and returns the associated signature */
|
|
59
|
-
function signWithMetadataEcdsa(message, slip44, accountIndex = 0, addressOffset = 0, { metadata } = {}) {
|
|
60
|
-
const bip42Path = `m/44'/${slip44}'/${accountIndex}'/${0}'/${addressOffset}'`;
|
|
61
|
-
return async (app) => {
|
|
62
|
-
if (!metadata) {
|
|
63
|
-
throw new Error('The metadata option must be present when using signWithMetadata');
|
|
64
|
-
}
|
|
65
|
-
const bufferMsg = Buffer.from(message);
|
|
66
|
-
const { r, s, v } = await wrapError(app.signWithMetadataEcdsa(bip42Path, bufferMsg, metadata));
|
|
67
|
-
const signature = Buffer.concat([r, s, v]);
|
|
68
|
-
return {
|
|
69
|
-
signature: hexAddPrefix(signature.toString('hex'))
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @name Ledger
|
|
75
|
-
*
|
|
76
|
-
* @description
|
|
77
|
-
* A very basic wrapper for a ledger app -
|
|
78
|
-
* - it connects automatically on use, creating an underlying interface as required
|
|
79
|
-
* - Promises reject with errors (unwrapped errors from @zondax/ledger-substrate-js)
|
|
80
|
-
*/
|
|
81
|
-
export class LedgerGeneric {
|
|
82
|
-
#transportDef;
|
|
83
|
-
#slip44;
|
|
84
|
-
/**
|
|
85
|
-
* The chainId is represented by the chains token in all lowercase. Example: Polkadot -> dot
|
|
86
|
-
*/
|
|
87
|
-
#chainId;
|
|
88
|
-
/**
|
|
89
|
-
* The metaUrl is seen as a server url that the underlying `PolkadotGenericApp` will use to
|
|
90
|
-
* retrieve the signature given a tx blob, and a chainId. It is important to note that if you would like to avoid
|
|
91
|
-
* having any network calls made, use `signWithMetadata`, and avoid `sign`.
|
|
92
|
-
*/
|
|
93
|
-
#metaUrl;
|
|
94
|
-
#app = null;
|
|
95
|
-
constructor(transport, chain, slip44, chainId, metaUrl) {
|
|
96
|
-
const ledgerName = ledgerApps[chain];
|
|
97
|
-
const transportDef = transports.find(({ type }) => type === transport);
|
|
98
|
-
if (!ledgerName) {
|
|
99
|
-
throw new Error(`Unsupported Ledger chain ${chain}`);
|
|
100
|
-
}
|
|
101
|
-
else if (!transportDef) {
|
|
102
|
-
throw new Error(`Unsupported Ledger transport ${transport}`);
|
|
103
|
-
}
|
|
104
|
-
this.#metaUrl = metaUrl;
|
|
105
|
-
this.#chainId = chainId;
|
|
106
|
-
this.#slip44 = slip44;
|
|
107
|
-
this.#transportDef = transportDef;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* @description Returns the address associated with a specific Ed25519 account & address offset. Optionally
|
|
111
|
-
* asks for on-device confirmation
|
|
112
|
-
*/
|
|
113
|
-
async getAddress(ss58Prefix, confirm = false, accountIndex = 0, addressOffset = 0) {
|
|
114
|
-
const bip42Path = `m/44'/${this.#slip44}'/${accountIndex}'/${0}'/${addressOffset}'`;
|
|
115
|
-
return this.withApp(async (app) => {
|
|
116
|
-
const { address, pubKey } = await wrapError(app.getAddressEd25519(bip42Path, ss58Prefix, confirm));
|
|
117
|
-
return {
|
|
118
|
-
address,
|
|
119
|
-
publicKey: hexAddPrefix(pubKey)
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* @description Returns the address associated with a specific ecdsa account & address offset. Optionally
|
|
125
|
-
* asks for on-device confirmation
|
|
126
|
-
*/
|
|
127
|
-
async getAddressEcdsa(confirm = false, accountIndex = 0, addressOffset = 0) {
|
|
128
|
-
const bip42Path = `m/44'/${this.#slip44}'/${accountIndex}'/${0}'/${addressOffset}'`;
|
|
129
|
-
return this.withApp(async (app) => {
|
|
130
|
-
const { address, pubKey } = await wrapError(app.getAddressEcdsa(bip42Path, confirm));
|
|
131
|
-
return {
|
|
132
|
-
address,
|
|
133
|
-
publicKey: hexAddPrefix(pubKey)
|
|
134
|
-
};
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* @description Returns the version of the Ledger application on the device
|
|
139
|
-
*/
|
|
140
|
-
async getVersion() {
|
|
141
|
-
return this.withApp(async (app) => {
|
|
142
|
-
const { deviceLocked: isLocked, major, minor, patch, testMode: isTestMode } = await wrapError(app.getVersion());
|
|
143
|
-
return {
|
|
144
|
-
isLocked: !!isLocked,
|
|
145
|
-
isTestMode: !!isTestMode,
|
|
146
|
-
version: [major || 0, minor || 0, patch || 0]
|
|
147
|
-
};
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* @description Signs a transaction on the Ledger device. This requires the LedgerGeneric class to be instantiated with `chainId`, and `metaUrl`
|
|
152
|
-
*/
|
|
153
|
-
async sign(message, accountIndex, addressOffset) {
|
|
154
|
-
return this.withApp(sign('signEd25519', message, this.#slip44, accountIndex, addressOffset));
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* @description Signs a message (non-transactional) on the Ledger device
|
|
158
|
-
*/
|
|
159
|
-
async signRaw(message, accountIndex, addressOffset) {
|
|
160
|
-
return this.withApp(sign('signRawEd25519', u8aWrapBytes(message), this.#slip44, accountIndex, addressOffset));
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* @description Signs a transaction on the Ledger device with Ecdsa. This requires the LedgerGeneric class to be instantiated with `chainId`, and `metaUrl`
|
|
164
|
-
*/
|
|
165
|
-
async signEcdsa(message, accountIndex, addressOffset) {
|
|
166
|
-
return this.withApp(signEcdsa('signEcdsa', u8aWrapBytes(message), this.#slip44, accountIndex, addressOffset));
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* @description Signs a message with Ecdsa (non-transactional) on the Ledger device
|
|
170
|
-
*/
|
|
171
|
-
async signRawEcdsa(message, accountIndex, addressOffset) {
|
|
172
|
-
return this.withApp(signEcdsa('signRawEcdsa', u8aWrapBytes(message), this.#slip44, accountIndex, addressOffset));
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* @description Signs a transaction on the ledger device provided some metadata.
|
|
176
|
-
*/
|
|
177
|
-
async signWithMetadata(message, accountIndex, addressOffset, options) {
|
|
178
|
-
return this.withApp(signWithMetadata(message, this.#slip44, accountIndex, addressOffset, options));
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* @description Signs a transaction on the ledger device for an ecdsa signature provided some metadata.
|
|
182
|
-
*/
|
|
183
|
-
async signWithMetadataEcdsa(message, accountIndex, addressOffset, options) {
|
|
184
|
-
return this.withApp(signWithMetadataEcdsa(message, this.#slip44, accountIndex, addressOffset, options));
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* @internal
|
|
188
|
-
*
|
|
189
|
-
* Returns a created PolkadotGenericApp to perform operations against. Generally
|
|
190
|
-
* this is only used internally, to ensure consistent bahavior.
|
|
191
|
-
*/
|
|
192
|
-
async withApp(fn) {
|
|
193
|
-
try {
|
|
194
|
-
if (!this.#app) {
|
|
195
|
-
const transport = await this.#transportDef.create();
|
|
196
|
-
// We need this override for the actual type passing - the Deno environment
|
|
197
|
-
// is quite a bit stricter and it yields invalids between the two (specifically
|
|
198
|
-
// since we mangle the imports from .default in the types for CJS/ESM and between
|
|
199
|
-
// esm.sh versions this yields problematic outputs)
|
|
200
|
-
//
|
|
201
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
202
|
-
this.#app = new PolkadotGenericApp(transport, this.#chainId, this.#metaUrl);
|
|
203
|
-
}
|
|
204
|
-
return await fn(this.#app);
|
|
205
|
-
}
|
|
206
|
-
catch (error) {
|
|
207
|
-
this.#app = null;
|
|
208
|
-
throw error;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
package/build/README.md
DELETED
package/build/bundle.js
DELETED
package/build/cjs/Ledger.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { SubstrateApp } from '@zondax/ledger-substrate';
|
|
2
|
-
import type { TransportType } from '@pezkuwi/hw-ledger-transports/types';
|
|
3
|
-
import type { AccountOptions, LedgerAddress, LedgerSignature, LedgerVersion } from './types.js';
|
|
4
|
-
import { ledgerApps } from './defaults.js';
|
|
5
|
-
export { packageInfo } from './packageInfo.js';
|
|
6
|
-
type Chain = keyof typeof ledgerApps;
|
|
7
|
-
/**
|
|
8
|
-
* @name Ledger
|
|
9
|
-
*
|
|
10
|
-
* @description
|
|
11
|
-
* Legacy wrapper for a ledger app -
|
|
12
|
-
* - it connects automatically on use, creating an underlying interface as required
|
|
13
|
-
* - Promises reject with errors (unwrapped errors from @zondax/ledger-substrate)
|
|
14
|
-
* @deprecated Use LedgerGeneric for up to date integration with ledger
|
|
15
|
-
*/
|
|
16
|
-
export declare class Ledger {
|
|
17
|
-
#private;
|
|
18
|
-
constructor(transport: TransportType, chain: Chain);
|
|
19
|
-
/**
|
|
20
|
-
* Returns the address associated with a specific account & address offset. Optionally
|
|
21
|
-
* asks for on-device confirmation
|
|
22
|
-
*/
|
|
23
|
-
getAddress(confirm?: boolean, accountOffset?: number, addressOffset?: number, { account, addressIndex, change }?: Partial<AccountOptions>): Promise<LedgerAddress>;
|
|
24
|
-
/**
|
|
25
|
-
* Returns the version of the Ledger application on the device
|
|
26
|
-
*/
|
|
27
|
-
getVersion(): Promise<LedgerVersion>;
|
|
28
|
-
/**
|
|
29
|
-
* Signs a transaction on the Ledger device
|
|
30
|
-
*/
|
|
31
|
-
sign(message: Uint8Array, accountOffset?: number, addressOffset?: number, options?: Partial<AccountOptions>): Promise<LedgerSignature>;
|
|
32
|
-
/**
|
|
33
|
-
* Signs a message (non-transactional) on the Ledger device
|
|
34
|
-
*/
|
|
35
|
-
signRaw(message: Uint8Array, accountOffset?: number, addressOffset?: number, options?: Partial<AccountOptions>): Promise<LedgerSignature>;
|
|
36
|
-
/**
|
|
37
|
-
* @internal
|
|
38
|
-
*
|
|
39
|
-
* Returns a created SubstrateApp to perform operations against. Generally
|
|
40
|
-
* this is only used internally, to ensure consistent bahavior.
|
|
41
|
-
*/
|
|
42
|
-
withApp<T>(fn: (app: SubstrateApp) => Promise<T>): Promise<T>;
|
|
43
|
-
}
|
package/build/cjs/Ledger.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Ledger = exports.packageInfo = void 0;
|
|
4
|
-
const ledger_substrate_1 = require("@zondax/ledger-substrate");
|
|
5
|
-
const hw_ledger_transports_1 = require("@pezkuwi/hw-ledger-transports");
|
|
6
|
-
const util_1 = require("@pezkuwi/util");
|
|
7
|
-
const constants_js_1 = require("./constants.js");
|
|
8
|
-
const defaults_js_1 = require("./defaults.js");
|
|
9
|
-
var packageInfo_js_1 = require("./packageInfo.js");
|
|
10
|
-
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
|
|
11
|
-
/** @internal Wraps a SubstrateApp call, checking the result for any errors which result in a rejection */
|
|
12
|
-
async function wrapError(promise) {
|
|
13
|
-
const result = await promise;
|
|
14
|
-
if (result.return_code !== constants_js_1.LEDGER_SUCCESS_CODE) {
|
|
15
|
-
throw new Error(result.error_message);
|
|
16
|
-
}
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
/** @internal Wraps a sign/signRaw call and returns the associated signature */
|
|
20
|
-
function sign(method, message, accountOffset = 0, addressOffset = 0, { account = constants_js_1.LEDGER_DEFAULT_ACCOUNT, addressIndex = constants_js_1.LEDGER_DEFAULT_INDEX, change = constants_js_1.LEDGER_DEFAULT_CHANGE } = {}) {
|
|
21
|
-
return async (app) => {
|
|
22
|
-
const { signature } = await wrapError(app[method](account + accountOffset, change, addressIndex + addressOffset, (0, util_1.u8aToBuffer)(message)));
|
|
23
|
-
return {
|
|
24
|
-
signature: (0, util_1.hexAddPrefix)(signature.toString('hex'))
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @name Ledger
|
|
30
|
-
*
|
|
31
|
-
* @description
|
|
32
|
-
* Legacy wrapper for a ledger app -
|
|
33
|
-
* - it connects automatically on use, creating an underlying interface as required
|
|
34
|
-
* - Promises reject with errors (unwrapped errors from @zondax/ledger-substrate)
|
|
35
|
-
* @deprecated Use LedgerGeneric for up to date integration with ledger
|
|
36
|
-
*/
|
|
37
|
-
class Ledger {
|
|
38
|
-
#ledgerName;
|
|
39
|
-
#transportDef;
|
|
40
|
-
#app = null;
|
|
41
|
-
constructor(transport, chain) {
|
|
42
|
-
const ledgerName = defaults_js_1.ledgerApps[chain];
|
|
43
|
-
const transportDef = hw_ledger_transports_1.transports.find(({ type }) => type === transport);
|
|
44
|
-
if (!ledgerName) {
|
|
45
|
-
throw new Error(`Unsupported Ledger chain ${chain}`);
|
|
46
|
-
}
|
|
47
|
-
else if (!transportDef) {
|
|
48
|
-
throw new Error(`Unsupported Ledger transport ${transport}`);
|
|
49
|
-
}
|
|
50
|
-
this.#ledgerName = ledgerName;
|
|
51
|
-
this.#transportDef = transportDef;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Returns the address associated with a specific account & address offset. Optionally
|
|
55
|
-
* asks for on-device confirmation
|
|
56
|
-
*/
|
|
57
|
-
async getAddress(confirm = false, accountOffset = 0, addressOffset = 0, { account = constants_js_1.LEDGER_DEFAULT_ACCOUNT, addressIndex = constants_js_1.LEDGER_DEFAULT_INDEX, change = constants_js_1.LEDGER_DEFAULT_CHANGE } = {}) {
|
|
58
|
-
return this.withApp(async (app) => {
|
|
59
|
-
const { address, pubKey } = await wrapError(app.getAddress(account + accountOffset, change, addressIndex + addressOffset, confirm));
|
|
60
|
-
return {
|
|
61
|
-
address,
|
|
62
|
-
publicKey: (0, util_1.hexAddPrefix)(pubKey)
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Returns the version of the Ledger application on the device
|
|
68
|
-
*/
|
|
69
|
-
async getVersion() {
|
|
70
|
-
return this.withApp(async (app) => {
|
|
71
|
-
const { device_locked: isLocked, major, minor, patch, test_mode: isTestMode } = await wrapError(app.getVersion());
|
|
72
|
-
return {
|
|
73
|
-
isLocked,
|
|
74
|
-
isTestMode,
|
|
75
|
-
version: [major, minor, patch]
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Signs a transaction on the Ledger device
|
|
81
|
-
*/
|
|
82
|
-
async sign(message, accountOffset, addressOffset, options) {
|
|
83
|
-
return this.withApp(sign('sign', message, accountOffset, addressOffset, options));
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Signs a message (non-transactional) on the Ledger device
|
|
87
|
-
*/
|
|
88
|
-
async signRaw(message, accountOffset, addressOffset, options) {
|
|
89
|
-
return this.withApp(sign('signRaw', (0, util_1.u8aWrapBytes)(message), accountOffset, addressOffset, options));
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* @internal
|
|
93
|
-
*
|
|
94
|
-
* Returns a created SubstrateApp to perform operations against. Generally
|
|
95
|
-
* this is only used internally, to ensure consistent bahavior.
|
|
96
|
-
*/
|
|
97
|
-
async withApp(fn) {
|
|
98
|
-
try {
|
|
99
|
-
if (!this.#app) {
|
|
100
|
-
const transport = await this.#transportDef.create();
|
|
101
|
-
// We need this override for the actual type passing - the Deno environment
|
|
102
|
-
// is quite a bit stricter and it yields invalids between the two (specifically
|
|
103
|
-
// since we mangle the imports from .default in the types for CJS/ESM and between
|
|
104
|
-
// esm.sh versions this yields problematic outputs)
|
|
105
|
-
//
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
107
|
-
this.#app = (0, ledger_substrate_1.newSubstrateApp)(transport, this.#ledgerName);
|
|
108
|
-
}
|
|
109
|
-
return await fn(this.#app);
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
this.#app = null;
|
|
113
|
-
throw error;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
exports.Ledger = Ledger;
|