@pezkuwi/hw-ledger 14.0.1 → 14.0.4
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/LICENSE +201 -0
- package/Ledger.d.ts +43 -0
- package/Ledger.js +112 -0
- package/LedgerGeneric.d.ts +63 -0
- package/LedgerGeneric.js +211 -0
- package/README.md +1 -1
- package/bundle-polkadot-hw-ledger.js +9708 -0
- package/bundle.d.ts +2 -0
- package/bundle.js +2 -0
- package/cjs/Ledger.d.ts +43 -0
- package/cjs/Ledger.js +117 -0
- package/cjs/LedgerGeneric.d.ts +63 -0
- package/cjs/LedgerGeneric.js +216 -0
- package/cjs/bundle.d.ts +2 -0
- package/cjs/bundle.js +7 -0
- package/cjs/constants.d.ts +4 -0
- package/cjs/constants.js +7 -0
- package/cjs/defaults.d.ts +14 -0
- package/cjs/defaults.js +61 -0
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +5 -0
- package/cjs/package.json +3 -0
- package/cjs/packageDetect.d.ts +1 -0
- package/cjs/packageDetect.js +7 -0
- package/cjs/packageInfo.d.ts +6 -0
- package/cjs/packageInfo.js +4 -0
- package/cjs/types.d.ts +34 -0
- package/cjs/types.js +2 -0
- package/constants.d.ts +4 -0
- package/{src/constants.ts → constants.js} +0 -6
- package/defaults.d.ts +14 -0
- package/defaults.js +58 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +156 -6
- package/packageDetect.d.ts +1 -0
- package/{src/packageDetect.ts → packageDetect.js} +0 -8
- package/packageInfo.d.ts +6 -0
- package/packageInfo.js +1 -0
- package/types.d.ts +34 -0
- package/types.js +1 -0
- package/src/Ledger.ts +0 -144
- package/src/LedgerGeneric.ts +0 -275
- package/src/bundle.ts +0 -8
- 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/packageInfo.ts +0 -6
- package/src/types.ts +0 -42
- package/tsconfig.build.json +0 -16
- package/tsconfig.spec.json +0 -16
package/defaults.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const prevLedgerRecord: Record<string, string>;
|
|
2
|
+
export declare const genericLedgerApps: {
|
|
3
|
+
bittensor: string;
|
|
4
|
+
creditcoin3: string;
|
|
5
|
+
dentnet: string;
|
|
6
|
+
encointer: string;
|
|
7
|
+
frequency: string;
|
|
8
|
+
integritee: string;
|
|
9
|
+
liberland: string;
|
|
10
|
+
mythos: string;
|
|
11
|
+
polimec: string;
|
|
12
|
+
vara: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const ledgerApps: Record<string, string>;
|
package/defaults.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const prevLedgerRecord = {
|
|
2
|
+
acala: 'Acala',
|
|
3
|
+
ajuna: 'Ajuna',
|
|
4
|
+
'aleph-node': 'AlephZero',
|
|
5
|
+
astar: 'Astar',
|
|
6
|
+
bifrost: 'Bifrost',
|
|
7
|
+
'bifrost-kusama': 'BifrostKusama',
|
|
8
|
+
centrifuge: 'Centrifuge',
|
|
9
|
+
composable: 'Composable',
|
|
10
|
+
darwinia: 'Darwinia',
|
|
11
|
+
'dock-mainnet': 'Dock',
|
|
12
|
+
edgeware: 'Edgeware',
|
|
13
|
+
enjin: 'Enjin',
|
|
14
|
+
equilibrium: 'Equilibrium',
|
|
15
|
+
genshiro: 'Genshiro',
|
|
16
|
+
hydradx: 'HydraDX',
|
|
17
|
+
'interlay-parachain': 'Interlay',
|
|
18
|
+
karura: 'Karura',
|
|
19
|
+
khala: 'Khala',
|
|
20
|
+
kusama: 'Kusama',
|
|
21
|
+
matrixchain: 'Matrixchain',
|
|
22
|
+
nodle: 'Nodle',
|
|
23
|
+
origintrail: 'OriginTrail',
|
|
24
|
+
parallel: 'Parallel',
|
|
25
|
+
peaq: 'Peaq',
|
|
26
|
+
pendulum: 'Pendulum',
|
|
27
|
+
phala: 'Phala',
|
|
28
|
+
picasso: 'Picasso',
|
|
29
|
+
polkadex: 'Polkadex',
|
|
30
|
+
polkadot: 'Polkadot',
|
|
31
|
+
polymesh: 'Polymesh',
|
|
32
|
+
quartz: 'Quartz',
|
|
33
|
+
sora: 'Sora',
|
|
34
|
+
stafi: 'Stafi',
|
|
35
|
+
statemine: 'Statemine',
|
|
36
|
+
statemint: 'Statemint',
|
|
37
|
+
ternoa: 'Ternoa',
|
|
38
|
+
unique: 'Unique',
|
|
39
|
+
vtb: 'VTB',
|
|
40
|
+
xxnetwork: 'XXNetwork',
|
|
41
|
+
zeitgeist: 'Zeitgeist'
|
|
42
|
+
};
|
|
43
|
+
export const genericLedgerApps = {
|
|
44
|
+
bittensor: 'Bittensor',
|
|
45
|
+
creditcoin3: 'Creditcoin3',
|
|
46
|
+
dentnet: 'DENTNet',
|
|
47
|
+
encointer: 'Encointer',
|
|
48
|
+
frequency: 'Frequency',
|
|
49
|
+
integritee: 'Integritee',
|
|
50
|
+
liberland: 'Liberland',
|
|
51
|
+
mythos: 'Mythos',
|
|
52
|
+
polimec: 'Polimec',
|
|
53
|
+
vara: 'Vara'
|
|
54
|
+
};
|
|
55
|
+
export const ledgerApps = {
|
|
56
|
+
...prevLedgerRecord,
|
|
57
|
+
...genericLedgerApps
|
|
58
|
+
};
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,24 +1,174 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Jaco Greeff <jacogr@gmail.com>",
|
|
3
|
-
"bugs": "https://github.com/
|
|
3
|
+
"bugs": "https://github.com/polkadot-js/common/issues",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
7
|
-
"homepage": "https://github.com/
|
|
7
|
+
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/hw-ledger#readme",
|
|
8
8
|
"license": "Apache-2.0",
|
|
9
9
|
"name": "@pezkuwi/hw-ledger",
|
|
10
10
|
"repository": {
|
|
11
11
|
"directory": "packages/hw-ledger",
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/polkadot-js/common.git"
|
|
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.4",
|
|
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",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/hw-ledger authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
// Do not edit, auto-generated by @polkadot/dev
|
|
5
|
-
// (packageInfo imports will be kept as-is, user-editable)
|
|
6
|
-
|
|
7
1
|
import { packageInfo as transportInfo } from '@pezkuwi/hw-ledger-transports/packageInfo';
|
|
8
2
|
import { detectPackage } from '@pezkuwi/util';
|
|
9
3
|
import { packageInfo as utilInfo } from '@pezkuwi/util/packageInfo';
|
|
10
|
-
|
|
11
4
|
import { packageInfo } from './packageInfo.js';
|
|
12
|
-
|
|
13
5
|
detectPackage(packageInfo, null, [transportInfo, utilInfo]);
|
package/packageInfo.d.ts
ADDED
package/packageInfo.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const packageInfo = { name: '@pezkuwi/hw-ledger', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '14.0.1' };
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { HexString } from '@polkadot/util/types';
|
|
2
|
+
/**
|
|
3
|
+
* Legacy Type that works with the `Ledger` class.
|
|
4
|
+
*/
|
|
5
|
+
export interface AccountOptions {
|
|
6
|
+
/** The index of the account */
|
|
7
|
+
account: number;
|
|
8
|
+
/** The index of the address */
|
|
9
|
+
addressIndex: number;
|
|
10
|
+
/** The change to apply */
|
|
11
|
+
change: number;
|
|
12
|
+
}
|
|
13
|
+
export interface AccountOptionsGeneric extends AccountOptions {
|
|
14
|
+
/** Option for PolkadotGenericApp.signWithMetadata */
|
|
15
|
+
metadata: Buffer;
|
|
16
|
+
}
|
|
17
|
+
export interface LedgerAddress {
|
|
18
|
+
/** The ss58 encoded address */
|
|
19
|
+
address: string;
|
|
20
|
+
/** The hex-encoded publicKey */
|
|
21
|
+
publicKey: HexString;
|
|
22
|
+
}
|
|
23
|
+
export interface LedgerSignature {
|
|
24
|
+
/** A hex-encoded signature, as generated by the device */
|
|
25
|
+
signature: HexString;
|
|
26
|
+
}
|
|
27
|
+
export interface LedgerVersion {
|
|
28
|
+
/** Indicator flag for locked status */
|
|
29
|
+
isLocked: boolean;
|
|
30
|
+
/** Indicator flag for testmode status */
|
|
31
|
+
isTestMode: boolean;
|
|
32
|
+
/** The software version for this device */
|
|
33
|
+
version: [major: number, minor: number, patch: number];
|
|
34
|
+
}
|
package/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/src/Ledger.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/hw-ledger authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { SubstrateApp } from '@zondax/ledger-substrate';
|
|
5
|
-
import type { TransportDef, TransportType } from '@pezkuwi/hw-ledger-transports/types';
|
|
6
|
-
import type { AccountOptions, LedgerAddress, LedgerSignature, LedgerVersion } from './types.js';
|
|
7
|
-
|
|
8
|
-
import { newSubstrateApp } from '@zondax/ledger-substrate';
|
|
9
|
-
|
|
10
|
-
import { transports } from '@pezkuwi/hw-ledger-transports';
|
|
11
|
-
import { hexAddPrefix, u8aToBuffer, u8aWrapBytes } from '@pezkuwi/util';
|
|
12
|
-
|
|
13
|
-
import { LEDGER_DEFAULT_ACCOUNT, LEDGER_DEFAULT_CHANGE, LEDGER_DEFAULT_INDEX, LEDGER_SUCCESS_CODE } from './constants.js';
|
|
14
|
-
import { ledgerApps } from './defaults.js';
|
|
15
|
-
|
|
16
|
-
export { packageInfo } from './packageInfo.js';
|
|
17
|
-
|
|
18
|
-
type Chain = keyof typeof ledgerApps;
|
|
19
|
-
|
|
20
|
-
type WrappedResult = Awaited<ReturnType<SubstrateApp['getAddress' | 'getVersion' | 'sign']>>;
|
|
21
|
-
|
|
22
|
-
/** @internal Wraps a SubstrateApp call, checking the result for any errors which result in a rejection */
|
|
23
|
-
async function wrapError <T extends WrappedResult> (promise: Promise<T>): Promise<T> {
|
|
24
|
-
const result = await promise;
|
|
25
|
-
|
|
26
|
-
if (result.return_code !== LEDGER_SUCCESS_CODE) {
|
|
27
|
-
throw new Error(result.error_message);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** @internal Wraps a sign/signRaw call and returns the associated signature */
|
|
34
|
-
function sign (method: 'sign' | 'signRaw', message: Uint8Array, accountOffset = 0, addressOffset = 0, { account = LEDGER_DEFAULT_ACCOUNT, addressIndex = LEDGER_DEFAULT_INDEX, change = LEDGER_DEFAULT_CHANGE }: Partial<AccountOptions> = {}): (app: SubstrateApp) => Promise<LedgerSignature> {
|
|
35
|
-
return async (app: SubstrateApp): Promise<LedgerSignature> => {
|
|
36
|
-
const { signature } = await wrapError(app[method](account + accountOffset, change, addressIndex + addressOffset, u8aToBuffer(message)));
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
signature: hexAddPrefix(signature.toString('hex'))
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @name Ledger
|
|
46
|
-
*
|
|
47
|
-
* @description
|
|
48
|
-
* Legacy wrapper for a ledger app -
|
|
49
|
-
* - it connects automatically on use, creating an underlying interface as required
|
|
50
|
-
* - Promises reject with errors (unwrapped errors from @zondax/ledger-substrate)
|
|
51
|
-
* @deprecated Use LedgerGeneric for up to date integration with ledger
|
|
52
|
-
*/
|
|
53
|
-
export class Ledger {
|
|
54
|
-
readonly #ledgerName: string;
|
|
55
|
-
readonly #transportDef: TransportDef;
|
|
56
|
-
|
|
57
|
-
#app: SubstrateApp | null = null;
|
|
58
|
-
|
|
59
|
-
constructor (transport: TransportType, chain: Chain) {
|
|
60
|
-
const ledgerName = ledgerApps[chain];
|
|
61
|
-
const transportDef = transports.find(({ type }) => type === transport);
|
|
62
|
-
|
|
63
|
-
if (!ledgerName) {
|
|
64
|
-
throw new Error(`Unsupported Ledger chain ${chain}`);
|
|
65
|
-
} else if (!transportDef) {
|
|
66
|
-
throw new Error(`Unsupported Ledger transport ${transport}`);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
this.#ledgerName = ledgerName;
|
|
70
|
-
this.#transportDef = transportDef;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Returns the address associated with a specific account & address offset. Optionally
|
|
75
|
-
* asks for on-device confirmation
|
|
76
|
-
*/
|
|
77
|
-
public async getAddress (confirm = false, accountOffset = 0, addressOffset = 0, { account = LEDGER_DEFAULT_ACCOUNT, addressIndex = LEDGER_DEFAULT_INDEX, change = LEDGER_DEFAULT_CHANGE }: Partial<AccountOptions> = {}): Promise<LedgerAddress> {
|
|
78
|
-
return this.withApp(async (app: SubstrateApp): Promise<LedgerAddress> => {
|
|
79
|
-
const { address, pubKey } = await wrapError(app.getAddress(account + accountOffset, change, addressIndex + addressOffset, confirm));
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
address,
|
|
83
|
-
publicKey: hexAddPrefix(pubKey)
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Returns the version of the Ledger application on the device
|
|
90
|
-
*/
|
|
91
|
-
public async getVersion (): Promise<LedgerVersion> {
|
|
92
|
-
return this.withApp(async (app: SubstrateApp): Promise<LedgerVersion> => {
|
|
93
|
-
const { device_locked: isLocked, major, minor, patch, test_mode: isTestMode } = await wrapError(app.getVersion());
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
isLocked,
|
|
97
|
-
isTestMode,
|
|
98
|
-
version: [major, minor, patch]
|
|
99
|
-
};
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Signs a transaction on the Ledger device
|
|
105
|
-
*/
|
|
106
|
-
public async sign (message: Uint8Array, accountOffset?: number, addressOffset?: number, options?: Partial<AccountOptions>): Promise<LedgerSignature> {
|
|
107
|
-
return this.withApp(sign('sign', message, accountOffset, addressOffset, options));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Signs a message (non-transactional) on the Ledger device
|
|
112
|
-
*/
|
|
113
|
-
public async signRaw (message: Uint8Array, accountOffset?: number, addressOffset?: number, options?: Partial<AccountOptions>): Promise<LedgerSignature> {
|
|
114
|
-
return this.withApp(sign('signRaw', u8aWrapBytes(message), accountOffset, addressOffset, options));
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* @internal
|
|
119
|
-
*
|
|
120
|
-
* Returns a created SubstrateApp to perform operations against. Generally
|
|
121
|
-
* this is only used internally, to ensure consistent bahavior.
|
|
122
|
-
*/
|
|
123
|
-
async withApp <T> (fn: (app: SubstrateApp) => Promise<T>): Promise<T> {
|
|
124
|
-
try {
|
|
125
|
-
if (!this.#app) {
|
|
126
|
-
const transport = await this.#transportDef.create();
|
|
127
|
-
|
|
128
|
-
// We need this override for the actual type passing - the Deno environment
|
|
129
|
-
// is quite a bit stricter and it yields invalids between the two (specifically
|
|
130
|
-
// since we mangle the imports from .default in the types for CJS/ESM and between
|
|
131
|
-
// esm.sh versions this yields problematic outputs)
|
|
132
|
-
//
|
|
133
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
134
|
-
this.#app = newSubstrateApp(transport as any, this.#ledgerName);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return await fn(this.#app);
|
|
138
|
-
} catch (error) {
|
|
139
|
-
this.#app = null;
|
|
140
|
-
|
|
141
|
-
throw error;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|