@metamask-previews/eth-qr-keyring 1.0.0-e4f6caa → 1.1.0-9fbf2ff

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/dist/device.cjs +345 -0
  3. package/dist/device.cjs.map +1 -0
  4. package/dist/device.d.cts +175 -0
  5. package/dist/device.d.cts.map +1 -0
  6. package/dist/device.d.mts +175 -0
  7. package/dist/device.d.mts.map +1 -0
  8. package/dist/device.mjs +345 -0
  9. package/dist/device.mjs.map +1 -0
  10. package/dist/index.cjs +9 -16
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +3 -2
  13. package/dist/index.d.cts.map +1 -1
  14. package/dist/index.d.mts +3 -2
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +3 -2
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/qr-keyring-deferred-promise-bridge.cjs +76 -0
  19. package/dist/qr-keyring-deferred-promise-bridge.cjs.map +1 -0
  20. package/dist/qr-keyring-deferred-promise-bridge.d.cts +46 -0
  21. package/dist/qr-keyring-deferred-promise-bridge.d.cts.map +1 -0
  22. package/dist/qr-keyring-deferred-promise-bridge.d.mts +46 -0
  23. package/dist/qr-keyring-deferred-promise-bridge.d.mts.map +1 -0
  24. package/dist/qr-keyring-deferred-promise-bridge.mjs +72 -0
  25. package/dist/qr-keyring-deferred-promise-bridge.mjs.map +1 -0
  26. package/dist/qr-keyring-scanner-bridge.cjs +2 -2
  27. package/dist/qr-keyring-scanner-bridge.cjs.map +1 -1
  28. package/dist/qr-keyring-scanner-bridge.d.cts +3 -3
  29. package/dist/qr-keyring-scanner-bridge.d.mts +3 -3
  30. package/dist/qr-keyring-scanner-bridge.mjs +2 -2
  31. package/dist/qr-keyring-scanner-bridge.mjs.map +1 -1
  32. package/dist/qr-keyring.cjs +65 -137
  33. package/dist/qr-keyring.cjs.map +1 -1
  34. package/dist/qr-keyring.d.cts +17 -4
  35. package/dist/qr-keyring.d.cts.map +1 -1
  36. package/dist/qr-keyring.d.mts +17 -4
  37. package/dist/qr-keyring.d.mts.map +1 -1
  38. package/dist/qr-keyring.mjs +66 -138
  39. package/dist/qr-keyring.mjs.map +1 -1
  40. package/package.json +6 -5
  41. package/dist/airgapped-signer.cjs +0 -270
  42. package/dist/airgapped-signer.cjs.map +0 -1
  43. package/dist/airgapped-signer.d.cts +0 -140
  44. package/dist/airgapped-signer.d.cts.map +0 -1
  45. package/dist/airgapped-signer.d.mts +0 -140
  46. package/dist/airgapped-signer.d.mts.map +0 -1
  47. package/dist/airgapped-signer.mjs +0 -270
  48. package/dist/airgapped-signer.mjs.map +0 -1
@@ -1,270 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
- if (kind === "m") throw new TypeError("Private method is not writable");
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- var _AirgappedSigner_instances, _AirgappedSigner_source, _AirgappedSigner_initFromUR, _AirgappedSigner_decodeUR;
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.AirgappedSigner = exports.KeyringMode = exports.SUPPORTED_UR_TYPE = void 0;
19
- const util_1 = require("@ethereumjs/util");
20
- const bc_ur_registry_eth_1 = require("@keystonehq/bc-ur-registry-eth");
21
- const utils_1 = require("@metamask/utils");
22
- // eslint-disable-next-line @typescript-eslint/naming-convention
23
- const hdkey_1 = __importDefault(require("hdkey"));
24
- exports.SUPPORTED_UR_TYPE = {
25
- CRYPTO_HDKEY: 'crypto-hdkey',
26
- CRYPTO_ACCOUNT: 'crypto-account',
27
- ETH_SIGNATURE: 'eth-signature',
28
- };
29
- var KeyringMode;
30
- (function (KeyringMode) {
31
- KeyringMode["HD"] = "hd";
32
- KeyringMode["ACCOUNT"] = "account";
33
- })(KeyringMode || (exports.KeyringMode = KeyringMode = {}));
34
- const DEFAULT_CHILDREN_PATH = '0/*';
35
- const MAX_INDEX = 1000;
36
- /**
37
- * Get the fingerprint of the source CryptoAccount or CryptoHDKey
38
- *
39
- * @param source - The source CryptoAccount or CryptoHDKey
40
- * @returns The fingerprint of the source
41
- */
42
- function getFingerprintFromSource(source) {
43
- return source instanceof bc_ur_registry_eth_1.CryptoAccount
44
- ? source.getMasterFingerprint()?.toString('hex')
45
- : source.getParentFingerprint()?.toString('hex');
46
- }
47
- /**
48
- * Get fingerprint, account paths and names from the a CryptoAccount
49
- *
50
- * Note: This function emulates the behavior of the `@keystonehq/base-eth-keyring`
51
- * library when dealing with CryptoAccount objects (for backwards compatibility
52
- * reasons). Though, the way it retrieves `name` and `keyringAccount` is questionable,
53
- * as `name` and `keyringAccount` are updated after each descriptor discovery, effectively
54
- * returning the last descriptor's `name` and `keyringAccount`.
55
- *
56
- * @param source - The source CryptoAccount
57
- * @returns The paths
58
- */
59
- function readCryptoAccountOutputDescriptors(source) {
60
- const descriptors = source.getOutputDescriptors();
61
- if (!descriptors || descriptors.length === 0) {
62
- throw new Error('No output descriptors found in CryptoAccount');
63
- }
64
- let name = '';
65
- let keyringAccount = '';
66
- const paths = descriptors.reduce((descriptorsPaths, current) => {
67
- const hdKey = current.getHDKey();
68
- if (hdKey) {
69
- const path = `M/${hdKey.getOrigin().getPath()}`;
70
- const address = (0, utils_1.getChecksumAddress)((0, utils_1.add0x)(Buffer.from((0, util_1.publicToAddress)(hdKey.getKey(), true)).toString('hex')));
71
- descriptorsPaths[address] = path;
72
- name = hdKey.getName();
73
- keyringAccount = hdKey.getNote();
74
- }
75
- return descriptorsPaths;
76
- }, {});
77
- return {
78
- paths,
79
- name,
80
- keyringAccount,
81
- xfp: getFingerprintFromSource(source),
82
- };
83
- }
84
- class AirgappedSigner {
85
- constructor() {
86
- _AirgappedSigner_instances.add(this);
87
- _AirgappedSigner_source.set(this, void 0);
88
- }
89
- /**
90
- * Initialize the AirgappedSigner with a source.
91
- *
92
- * @param source - The signer source, in the form of details object, or a UR string
93
- */
94
- init(source) {
95
- if (typeof source === 'string' || 'cbor' in source) {
96
- __classPrivateFieldGet(this, _AirgappedSigner_instances, "m", _AirgappedSigner_initFromUR).call(this, source);
97
- }
98
- else {
99
- __classPrivateFieldSet(this, _AirgappedSigner_source, source, "f");
100
- }
101
- }
102
- /**
103
- * Check if the AirgappedSigner is initialized
104
- *
105
- * @returns True if the AirgappedSigner is initialized, false otherwise
106
- */
107
- isInitialized() {
108
- return __classPrivateFieldGet(this, _AirgappedSigner_source, "f") !== undefined;
109
- }
110
- /**
111
- * Derive an address from the source at a given index
112
- *
113
- * @param index - The index to derive the address from
114
- * @returns The derived address in hex format
115
- * @throws Will throw an error if the source is not initialized
116
- */
117
- addressFromIndex(index) {
118
- if (!__classPrivateFieldGet(this, _AirgappedSigner_source, "f")) {
119
- throw new Error('UR not initialized');
120
- }
121
- if (__classPrivateFieldGet(this, _AirgappedSigner_source, "f").keyringMode === KeyringMode.ACCOUNT) {
122
- const address = Object.keys(__classPrivateFieldGet(this, _AirgappedSigner_source, "f").paths)[index];
123
- if (!address) {
124
- throw new Error(`Address not found for index ${index}`);
125
- }
126
- return (0, utils_1.add0x)(address);
127
- }
128
- const childPath = `m/${__classPrivateFieldGet(this, _AirgappedSigner_source, "f").childrenPath.replace('*', index.toString())}`;
129
- const hdKey = hdkey_1.default.fromExtendedKey(__classPrivateFieldGet(this, _AirgappedSigner_source, "f").xpub);
130
- const childKey = hdKey.derive(childPath);
131
- const address = Buffer.from((0, util_1.publicToAddress)(childKey.publicKey, true)).toString('hex');
132
- const normalizedAddress = (0, utils_1.getChecksumAddress)((0, utils_1.add0x)(address));
133
- __classPrivateFieldGet(this, _AirgappedSigner_source, "f").indexes[normalizedAddress] = index;
134
- return normalizedAddress;
135
- }
136
- /**
137
- * Retrieve the path of an address derived from the source.
138
- *
139
- * @param address - The address to retrieve the path for
140
- * @returns The path of the address
141
- */
142
- pathFromAddress(address) {
143
- if (!__classPrivateFieldGet(this, _AirgappedSigner_source, "f")) {
144
- throw new Error('UR not initialized');
145
- }
146
- const normalizedAddress = (0, utils_1.getChecksumAddress)((0, utils_1.add0x)(address));
147
- if (__classPrivateFieldGet(this, _AirgappedSigner_source, "f").keyringMode === KeyringMode.ACCOUNT) {
148
- const path = __classPrivateFieldGet(this, _AirgappedSigner_source, "f").paths[normalizedAddress];
149
- if (path === undefined) {
150
- throw new Error(`Unknown address ${normalizedAddress}`);
151
- }
152
- return path;
153
- }
154
- const index = this.indexFromAddress(normalizedAddress);
155
- return `${__classPrivateFieldGet(this, _AirgappedSigner_source, "f").hdPath}/${__classPrivateFieldGet(this, _AirgappedSigner_source, "f").childrenPath
156
- .replace('*', index.toString())
157
- .replace(/\*/gu, '0')}`;
158
- }
159
- /**
160
- * Retrieve the index of an address from the source
161
- *
162
- * @param address - The normalized address to retrieve the index for
163
- * @returns The index of the address
164
- */
165
- indexFromAddress(address) {
166
- if (!__classPrivateFieldGet(this, _AirgappedSigner_source, "f")) {
167
- throw new Error('UR not initialized');
168
- }
169
- const cachedIndex = __classPrivateFieldGet(this, _AirgappedSigner_source, "f").indexes[address];
170
- if (cachedIndex !== undefined) {
171
- return Number(cachedIndex);
172
- }
173
- if (__classPrivateFieldGet(this, _AirgappedSigner_source, "f").keyringMode === KeyringMode.ACCOUNT) {
174
- const path = __classPrivateFieldGet(this, _AirgappedSigner_source, "f").paths[address];
175
- if (path === undefined) {
176
- throw new Error(`Unknown address`);
177
- }
178
- const index = path.split('/').pop();
179
- if (index === undefined) {
180
- throw new Error(`Invalid path for address ${address}`);
181
- }
182
- return Number(index);
183
- }
184
- for (let i = 0; i < MAX_INDEX; i++) {
185
- const derivedAddress = this.addressFromIndex(i);
186
- if (derivedAddress === address) {
187
- return i;
188
- }
189
- }
190
- throw new Error(`Address ${address} not found`);
191
- }
192
- /**
193
- * Get a page of addresses derived from the source.
194
- *
195
- * @param page - The page number to retrieve
196
- * @param pageSize - The number of addresses per page
197
- * @returns An array of IndexedAddress objects, each containing the address and its index
198
- * @throws Will throw an error if the source is not initialized
199
- */
200
- getAddressesPage(page, pageSize = 5) {
201
- const startIndex = page * pageSize;
202
- const endIndex = startIndex + pageSize;
203
- const addresses = [];
204
- for (let i = startIndex; i < endIndex; i++) {
205
- const address = this.addressFromIndex(i);
206
- addresses.push({ address, index: i });
207
- }
208
- return addresses;
209
- }
210
- /**
211
- * Gets the source details of the AirgappedSigner.
212
- *
213
- * @returns The source details, or undefined if not initialized
214
- */
215
- getSourceDetails() {
216
- return __classPrivateFieldGet(this, _AirgappedSigner_source, "f");
217
- }
218
- /**
219
- * Clear the source details.
220
- */
221
- clear() {
222
- __classPrivateFieldSet(this, _AirgappedSigner_source, undefined, "f");
223
- }
224
- }
225
- exports.AirgappedSigner = AirgappedSigner;
226
- _AirgappedSigner_source = new WeakMap(), _AirgappedSigner_instances = new WeakSet(), _AirgappedSigner_initFromUR = function _AirgappedSigner_initFromUR(ur) {
227
- const source = __classPrivateFieldGet(this, _AirgappedSigner_instances, "m", _AirgappedSigner_decodeUR).call(this, ur);
228
- const fingerprint = getFingerprintFromSource(source);
229
- if (source instanceof bc_ur_registry_eth_1.CryptoAccount) {
230
- const { name, xfp, paths, keyringAccount } = readCryptoAccountOutputDescriptors(source);
231
- __classPrivateFieldSet(this, _AirgappedSigner_source, {
232
- keyringMode: KeyringMode.ACCOUNT,
233
- keyringAccount,
234
- name,
235
- xfp,
236
- paths,
237
- indexes: {},
238
- }, "f");
239
- }
240
- else {
241
- const { getBip32Key, getOrigin, getChildren, getName, getNote } = source;
242
- __classPrivateFieldSet(this, _AirgappedSigner_source, {
243
- keyringMode: KeyringMode.HD,
244
- keyringAccount: getNote(),
245
- name: getName(),
246
- xfp: fingerprint,
247
- hdPath: `m/${getOrigin().getPath()}`,
248
- childrenPath: getChildren()?.getPath() || DEFAULT_CHILDREN_PATH,
249
- xpub: getBip32Key(),
250
- indexes: {},
251
- }, "f");
252
- }
253
- }, _AirgappedSigner_decodeUR = function _AirgappedSigner_decodeUR(ur) {
254
- const decodedUR = typeof ur === 'string'
255
- ? bc_ur_registry_eth_1.URRegistryDecoder.decode(ur)
256
- : {
257
- type: ur.type,
258
- cbor: Buffer.from(ur.cbor, 'hex'),
259
- };
260
- const { type, cbor } = decodedUR;
261
- switch (type) {
262
- case exports.SUPPORTED_UR_TYPE.CRYPTO_HDKEY:
263
- return bc_ur_registry_eth_1.CryptoHDKey.fromCBOR(cbor);
264
- case exports.SUPPORTED_UR_TYPE.CRYPTO_ACCOUNT:
265
- return bc_ur_registry_eth_1.CryptoAccount.fromCBOR(cbor);
266
- default:
267
- throw new Error('Unsupported UR type');
268
- }
269
- };
270
- //# sourceMappingURL=airgapped-signer.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"airgapped-signer.cjs","sourceRoot":"","sources":["../src/airgapped-signer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAmD;AACnD,uEAIwC;AACxC,2CAAsE;AACtE,gEAAgE;AAChE,kDAA0B;AAIb,QAAA,iBAAiB,GAAG;IAC/B,YAAY,EAAE,cAAc;IAC5B,cAAc,EAAE,gBAAgB;IAChC,aAAa,EAAE,eAAe;CAC/B,CAAC;AAEF,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,wBAAS,CAAA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,\n CryptoHDKey,\n URRegistryDecoder,\n} from '@keystonehq/bc-ur-registry-eth';\nimport { add0x, getChecksumAddress, type Hex } from '@metamask/utils';\n// eslint-disable-next-line @typescript-eslint/naming-convention\nimport HdKey from 'hdkey';\n\nimport type { SerializedUR } from './qr-keyring';\n\nexport const SUPPORTED_UR_TYPE = {\n CRYPTO_HDKEY: 'crypto-hdkey',\n CRYPTO_ACCOUNT: 'crypto-account',\n ETH_SIGNATURE: 'eth-signature',\n};\n\nexport enum KeyringMode {\n HD = 'hd',\n ACCOUNT = 'account',\n}\n\nconst DEFAULT_CHILDREN_PATH = '0/*';\n\nconst MAX_INDEX = 1_000;\n\n/**\n * Common details for the signer source, which can be either a CryptoAccount or CryptoHDKey.\n */\nexport type CommonSignerDetails = {\n /**\n * Value take out from the device note field, if available.\n */\n keyringAccount: string;\n /**\n * The name of the device\n */\n name: string;\n /**\n * The device fingerprint, hex-encoded\n */\n xfp: string;\n /**\n * Indexes of the accounts derived from the device\n * in the form of a map from address to index\n */\n indexes: Record<Hex, number>;\n};\n\n/**\n * Details for the HD mode of the AirgappedSigner. This mode derives\n * accounts from a root public key (xpub) and a derivation path.\n */\nexport type HDModeSignerDetails = {\n /**\n * The keyring mode is HD, indicating that it derives accounts from a\n * root public key (xpub) and a derivation path.\n */\n keyringMode: KeyringMode.HD;\n /**\n * The xpub of the HD key\n */\n xpub: string;\n /**\n * The derivation path of the HD key\n */\n hdPath: string;\n /**\n * The path used to derive child accounts\n */\n childrenPath: string;\n};\n\n/**\n * Details for the Account mode of the AirgappedSigner. This mode derives\n * accounts from a set of addresses and their corresponding paths.\n */\nexport type AccountModeSignerDetails = {\n /**\n * The keyring mode is ACCOUNT, indicating that it derives accounts from\n * a set of addresses and their corresponding paths.\n */\n keyringMode: KeyringMode.ACCOUNT;\n /**\n * The derivation paths for each hex-encoded address in the device\n */\n paths: Record<Hex, string>;\n};\n\n/**\n * An address with its corresponding index.\n */\nexport type IndexedAddress = {\n address: Hex;\n index: number;\n};\n\n/**\n * The details of the source CryptoAccount or CryptoHDKey\n * that the AirgappedSigner uses to derive accounts.\n */\nexport type AirgappedSignerDetails = CommonSignerDetails &\n (HDModeSignerDetails | AccountModeSignerDetails);\n\n/**\n * Get the fingerprint of the source CryptoAccount or CryptoHDKey\n *\n * @param source - The source CryptoAccount or CryptoHDKey\n * @returns The fingerprint of the source\n */\nfunction getFingerprintFromSource(source: CryptoAccount | CryptoHDKey): string {\n return source instanceof CryptoAccount\n ? source.getMasterFingerprint()?.toString('hex')\n : source.getParentFingerprint()?.toString('hex');\n}\n\n/**\n * Get fingerprint, account paths and names from the a CryptoAccount\n *\n * Note: This function emulates the behavior of the `@keystonehq/base-eth-keyring`\n * library when dealing with CryptoAccount objects (for backwards compatibility\n * reasons). Though, the way it retrieves `name` and `keyringAccount` is questionable,\n * as `name` and `keyringAccount` are updated after each descriptor discovery, effectively\n * returning the last descriptor's `name` and `keyringAccount`.\n *\n * @param source - The source CryptoAccount\n * @returns The paths\n */\nfunction readCryptoAccountOutputDescriptors(source: CryptoAccount): {\n xfp: string;\n paths: Record<Hex, string>;\n name: string;\n keyringAccount: string;\n} {\n const descriptors = source.getOutputDescriptors();\n\n if (!descriptors || descriptors.length === 0) {\n throw new Error('No output descriptors found in CryptoAccount');\n }\n\n let name = '';\n let keyringAccount = '';\n const paths = descriptors.reduce(\n (descriptorsPaths: Record<Hex, string>, current) => {\n const hdKey = current.getHDKey();\n if (hdKey) {\n const path = `M/${hdKey.getOrigin().getPath()}`;\n const address = getChecksumAddress(\n add0x(\n Buffer.from(publicToAddress(hdKey.getKey(), true)).toString('hex'),\n ),\n );\n descriptorsPaths[address] = path;\n name = hdKey.getName();\n keyringAccount = hdKey.getNote();\n }\n return descriptorsPaths;\n },\n {},\n );\n\n return {\n paths,\n name,\n keyringAccount,\n xfp: getFingerprintFromSource(source),\n };\n}\n\nexport class AirgappedSigner {\n #source?: AirgappedSignerDetails | undefined;\n\n /**\n * Initialize the AirgappedSigner with a source.\n *\n * @param source - The signer source, in the form of details object, or a UR string\n */\n init(source: AirgappedSignerDetails | string | SerializedUR): void {\n if (typeof source === 'string' || 'cbor' in source) {\n this.#initFromUR(source);\n } else {\n this.#source = source;\n }\n }\n\n /**\n * Check if the AirgappedSigner is initialized\n *\n * @returns True if the AirgappedSigner is initialized, false otherwise\n */\n isInitialized(): boolean {\n return this.#source !== undefined;\n }\n\n /**\n * Derive an address from the source at a given index\n *\n * @param index - The index to derive the address from\n * @returns The derived address in hex format\n * @throws Will throw an error if the source is not initialized\n */\n addressFromIndex(index: number): Hex {\n if (!this.#source) {\n throw new Error('UR not initialized');\n }\n\n if (this.#source.keyringMode === KeyringMode.ACCOUNT) {\n const address = Object.keys(this.#source.paths)[index];\n if (!address) {\n throw new Error(`Address not found for index ${index}`);\n }\n return add0x(address);\n }\n const childPath = `m/${this.#source.childrenPath.replace(\n '*',\n index.toString(),\n )}`;\n\n const hdKey = HdKey.fromExtendedKey(this.#source.xpub);\n const childKey = hdKey.derive(childPath);\n\n const address = Buffer.from(\n publicToAddress(childKey.publicKey, true),\n ).toString('hex');\n\n const normalizedAddress = getChecksumAddress(add0x(address));\n\n this.#source.indexes[normalizedAddress] = index;\n\n return normalizedAddress;\n }\n\n /**\n * Retrieve the path of an address derived from the source.\n *\n * @param address - The address to retrieve the path for\n * @returns The path of the address\n */\n pathFromAddress(address: Hex): string {\n if (!this.#source) {\n throw new Error('UR not initialized');\n }\n\n const normalizedAddress = getChecksumAddress(add0x(address));\n\n if (this.#source.keyringMode === KeyringMode.ACCOUNT) {\n const path = this.#source.paths[normalizedAddress];\n if (path === undefined) {\n throw new Error(`Unknown address ${normalizedAddress}`);\n }\n return path;\n }\n\n const index = this.indexFromAddress(normalizedAddress);\n return `${this.#source.hdPath}/${this.#source.childrenPath\n .replace('*', index.toString())\n .replace(/\\*/gu, '0')}`;\n }\n\n /**\n * Retrieve the index of an address from the source\n *\n * @param address - The normalized address to retrieve the index for\n * @returns The index of the address\n */\n indexFromAddress(address: Hex): number {\n if (!this.#source) {\n throw new Error('UR not initialized');\n }\n\n const cachedIndex = this.#source.indexes[address];\n if (cachedIndex !== undefined) {\n return Number(cachedIndex);\n }\n\n if (this.#source.keyringMode === KeyringMode.ACCOUNT) {\n const path = this.#source.paths[address];\n if (path === undefined) {\n throw new Error(`Unknown address`);\n }\n\n const index = path.split('/').pop();\n if (index === undefined) {\n throw new Error(`Invalid path for address ${address}`);\n }\n\n return Number(index);\n }\n\n for (let i = 0; i < MAX_INDEX; i++) {\n const derivedAddress = this.addressFromIndex(i);\n if (derivedAddress === address) {\n return i;\n }\n }\n\n throw new Error(`Address ${address} not found`);\n }\n\n /**\n * Get a page of addresses derived from the source.\n *\n * @param page - The page number to retrieve\n * @param pageSize - The number of addresses per page\n * @returns An array of IndexedAddress objects, each containing the address and its index\n * @throws Will throw an error if the source is not initialized\n */\n getAddressesPage(page: number, pageSize = 5): IndexedAddress[] {\n const startIndex = page * pageSize;\n const endIndex = startIndex + pageSize;\n const addresses: IndexedAddress[] = [];\n\n for (let i = startIndex; i < endIndex; i++) {\n const address = this.addressFromIndex(i);\n addresses.push({ address, index: i });\n }\n\n return addresses;\n }\n\n /**\n * Gets the source details of the AirgappedSigner.\n *\n * @returns The source details, or undefined if not initialized\n */\n getSourceDetails(): AirgappedSignerDetails | undefined {\n return this.#source;\n }\n\n /**\n * Clear the source details.\n */\n clear(): void {\n this.#source = undefined;\n }\n\n /**\n * Set the root account from a UR string\n *\n * @param ur - The UR string to set the root account from\n */\n #initFromUR(ur: string | SerializedUR): void {\n const source = this.#decodeUR(ur);\n const fingerprint = getFingerprintFromSource(source);\n\n if (source instanceof CryptoAccount) {\n const { name, xfp, paths, keyringAccount } =\n readCryptoAccountOutputDescriptors(source);\n this.#source = {\n keyringMode: KeyringMode.ACCOUNT,\n keyringAccount,\n name,\n xfp,\n paths,\n indexes: {},\n };\n } else {\n const { getBip32Key, getOrigin, getChildren, getName, getNote } = source;\n this.#source = {\n keyringMode: KeyringMode.HD,\n keyringAccount: getNote(),\n name: getName(),\n xfp: fingerprint,\n hdPath: `m/${getOrigin().getPath()}`,\n childrenPath: getChildren()?.getPath() || DEFAULT_CHILDREN_PATH,\n xpub: getBip32Key(),\n indexes: {},\n };\n }\n }\n\n /**\n * Decodes a UR\n *\n * @param ur - The UR to decode\n * @returns The decoded CryptoAccount or CryptoHDKey\n * @throws Will throw an error if the UR type is not supported\n */\n #decodeUR(ur: string | SerializedUR): CryptoAccount | CryptoHDKey {\n const decodedUR =\n typeof ur === 'string'\n ? URRegistryDecoder.decode(ur)\n : {\n type: ur.type,\n cbor: Buffer.from(ur.cbor, 'hex'),\n };\n\n const { type, cbor } = decodedUR;\n\n switch (type) {\n case SUPPORTED_UR_TYPE.CRYPTO_HDKEY:\n return CryptoHDKey.fromCBOR(cbor);\n case SUPPORTED_UR_TYPE.CRYPTO_ACCOUNT:\n return CryptoAccount.fromCBOR(cbor);\n default:\n throw new Error('Unsupported UR type');\n }\n }\n}\n"]}
@@ -1,140 +0,0 @@
1
- import { type Hex } from "@metamask/utils";
2
- import type { SerializedUR } from "./qr-keyring.cjs";
3
- export declare const SUPPORTED_UR_TYPE: {
4
- CRYPTO_HDKEY: string;
5
- CRYPTO_ACCOUNT: string;
6
- ETH_SIGNATURE: string;
7
- };
8
- export declare enum KeyringMode {
9
- HD = "hd",
10
- ACCOUNT = "account"
11
- }
12
- /**
13
- * Common details for the signer source, which can be either a CryptoAccount or CryptoHDKey.
14
- */
15
- export type CommonSignerDetails = {
16
- /**
17
- * Value take out from the device note field, if available.
18
- */
19
- keyringAccount: string;
20
- /**
21
- * The name of the device
22
- */
23
- name: string;
24
- /**
25
- * The device fingerprint, hex-encoded
26
- */
27
- xfp: string;
28
- /**
29
- * Indexes of the accounts derived from the device
30
- * in the form of a map from address to index
31
- */
32
- indexes: Record<Hex, number>;
33
- };
34
- /**
35
- * Details for the HD mode of the AirgappedSigner. This mode derives
36
- * accounts from a root public key (xpub) and a derivation path.
37
- */
38
- export type HDModeSignerDetails = {
39
- /**
40
- * The keyring mode is HD, indicating that it derives accounts from a
41
- * root public key (xpub) and a derivation path.
42
- */
43
- keyringMode: KeyringMode.HD;
44
- /**
45
- * The xpub of the HD key
46
- */
47
- xpub: string;
48
- /**
49
- * The derivation path of the HD key
50
- */
51
- hdPath: string;
52
- /**
53
- * The path used to derive child accounts
54
- */
55
- childrenPath: string;
56
- };
57
- /**
58
- * Details for the Account mode of the AirgappedSigner. This mode derives
59
- * accounts from a set of addresses and their corresponding paths.
60
- */
61
- export type AccountModeSignerDetails = {
62
- /**
63
- * The keyring mode is ACCOUNT, indicating that it derives accounts from
64
- * a set of addresses and their corresponding paths.
65
- */
66
- keyringMode: KeyringMode.ACCOUNT;
67
- /**
68
- * The derivation paths for each hex-encoded address in the device
69
- */
70
- paths: Record<Hex, string>;
71
- };
72
- /**
73
- * An address with its corresponding index.
74
- */
75
- export type IndexedAddress = {
76
- address: Hex;
77
- index: number;
78
- };
79
- /**
80
- * The details of the source CryptoAccount or CryptoHDKey
81
- * that the AirgappedSigner uses to derive accounts.
82
- */
83
- export type AirgappedSignerDetails = CommonSignerDetails & (HDModeSignerDetails | AccountModeSignerDetails);
84
- export declare class AirgappedSigner {
85
- #private;
86
- /**
87
- * Initialize the AirgappedSigner with a source.
88
- *
89
- * @param source - The signer source, in the form of details object, or a UR string
90
- */
91
- init(source: AirgappedSignerDetails | string | SerializedUR): void;
92
- /**
93
- * Check if the AirgappedSigner is initialized
94
- *
95
- * @returns True if the AirgappedSigner is initialized, false otherwise
96
- */
97
- isInitialized(): boolean;
98
- /**
99
- * Derive an address from the source at a given index
100
- *
101
- * @param index - The index to derive the address from
102
- * @returns The derived address in hex format
103
- * @throws Will throw an error if the source is not initialized
104
- */
105
- addressFromIndex(index: number): Hex;
106
- /**
107
- * Retrieve the path of an address derived from the source.
108
- *
109
- * @param address - The address to retrieve the path for
110
- * @returns The path of the address
111
- */
112
- pathFromAddress(address: Hex): string;
113
- /**
114
- * Retrieve the index of an address from the source
115
- *
116
- * @param address - The normalized address to retrieve the index for
117
- * @returns The index of the address
118
- */
119
- indexFromAddress(address: Hex): number;
120
- /**
121
- * Get a page of addresses derived from the source.
122
- *
123
- * @param page - The page number to retrieve
124
- * @param pageSize - The number of addresses per page
125
- * @returns An array of IndexedAddress objects, each containing the address and its index
126
- * @throws Will throw an error if the source is not initialized
127
- */
128
- getAddressesPage(page: number, pageSize?: number): IndexedAddress[];
129
- /**
130
- * Gets the source details of the AirgappedSigner.
131
- *
132
- * @returns The source details, or undefined if not initialized
133
- */
134
- getSourceDetails(): AirgappedSignerDetails | undefined;
135
- /**
136
- * Clear the source details.
137
- */
138
- clear(): void;
139
- }
140
- //# sourceMappingURL=airgapped-signer.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"airgapped-signer.d.cts","sourceRoot":"","sources":["../src/airgapped-signer.ts"],"names":[],"mappings":"AAMA,OAAO,EAA6B,KAAK,GAAG,EAAE,wBAAwB;AAItE,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAqB;AAEjD,eAAO,MAAM,iBAAiB;;;;CAI7B,CAAC;AAEF,oBAAY,WAAW;IACrB,EAAE,OAAO;IACT,OAAO,YAAY;CACpB;AAMD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;OAGG;IACH,WAAW,EAAE,WAAW,CAAC,EAAE,CAAC;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC;IACjC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,GAAG,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,mBAAmB,GACtD,CAAC,mBAAmB,GAAG,wBAAwB,CAAC,CAAC;AAmEnD,qBAAa,eAAe;;IAG1B;;;;OAIG;IACH,IAAI,CAAC,MAAM,EAAE,sBAAsB,GAAG,MAAM,GAAG,YAAY,GAAG,IAAI;IAQlE;;;;OAIG;IACH,aAAa,IAAI,OAAO;IAIxB;;;;;;OAMG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG;IA+BpC;;;;;OAKG;IACH,eAAe,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM;IAqBrC;;;;;OAKG;IACH,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM;IAkCtC;;;;;;;OAOG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,SAAI,GAAG,cAAc,EAAE;IAa9D;;;;OAIG;IACH,gBAAgB,IAAI,sBAAsB,GAAG,SAAS;IAItD;;OAEG;IACH,KAAK,IAAI,IAAI;CAkEd"}
@@ -1,140 +0,0 @@
1
- import { type Hex } from "@metamask/utils";
2
- import type { SerializedUR } from "./qr-keyring.mjs";
3
- export declare const SUPPORTED_UR_TYPE: {
4
- CRYPTO_HDKEY: string;
5
- CRYPTO_ACCOUNT: string;
6
- ETH_SIGNATURE: string;
7
- };
8
- export declare enum KeyringMode {
9
- HD = "hd",
10
- ACCOUNT = "account"
11
- }
12
- /**
13
- * Common details for the signer source, which can be either a CryptoAccount or CryptoHDKey.
14
- */
15
- export type CommonSignerDetails = {
16
- /**
17
- * Value take out from the device note field, if available.
18
- */
19
- keyringAccount: string;
20
- /**
21
- * The name of the device
22
- */
23
- name: string;
24
- /**
25
- * The device fingerprint, hex-encoded
26
- */
27
- xfp: string;
28
- /**
29
- * Indexes of the accounts derived from the device
30
- * in the form of a map from address to index
31
- */
32
- indexes: Record<Hex, number>;
33
- };
34
- /**
35
- * Details for the HD mode of the AirgappedSigner. This mode derives
36
- * accounts from a root public key (xpub) and a derivation path.
37
- */
38
- export type HDModeSignerDetails = {
39
- /**
40
- * The keyring mode is HD, indicating that it derives accounts from a
41
- * root public key (xpub) and a derivation path.
42
- */
43
- keyringMode: KeyringMode.HD;
44
- /**
45
- * The xpub of the HD key
46
- */
47
- xpub: string;
48
- /**
49
- * The derivation path of the HD key
50
- */
51
- hdPath: string;
52
- /**
53
- * The path used to derive child accounts
54
- */
55
- childrenPath: string;
56
- };
57
- /**
58
- * Details for the Account mode of the AirgappedSigner. This mode derives
59
- * accounts from a set of addresses and their corresponding paths.
60
- */
61
- export type AccountModeSignerDetails = {
62
- /**
63
- * The keyring mode is ACCOUNT, indicating that it derives accounts from
64
- * a set of addresses and their corresponding paths.
65
- */
66
- keyringMode: KeyringMode.ACCOUNT;
67
- /**
68
- * The derivation paths for each hex-encoded address in the device
69
- */
70
- paths: Record<Hex, string>;
71
- };
72
- /**
73
- * An address with its corresponding index.
74
- */
75
- export type IndexedAddress = {
76
- address: Hex;
77
- index: number;
78
- };
79
- /**
80
- * The details of the source CryptoAccount or CryptoHDKey
81
- * that the AirgappedSigner uses to derive accounts.
82
- */
83
- export type AirgappedSignerDetails = CommonSignerDetails & (HDModeSignerDetails | AccountModeSignerDetails);
84
- export declare class AirgappedSigner {
85
- #private;
86
- /**
87
- * Initialize the AirgappedSigner with a source.
88
- *
89
- * @param source - The signer source, in the form of details object, or a UR string
90
- */
91
- init(source: AirgappedSignerDetails | string | SerializedUR): void;
92
- /**
93
- * Check if the AirgappedSigner is initialized
94
- *
95
- * @returns True if the AirgappedSigner is initialized, false otherwise
96
- */
97
- isInitialized(): boolean;
98
- /**
99
- * Derive an address from the source at a given index
100
- *
101
- * @param index - The index to derive the address from
102
- * @returns The derived address in hex format
103
- * @throws Will throw an error if the source is not initialized
104
- */
105
- addressFromIndex(index: number): Hex;
106
- /**
107
- * Retrieve the path of an address derived from the source.
108
- *
109
- * @param address - The address to retrieve the path for
110
- * @returns The path of the address
111
- */
112
- pathFromAddress(address: Hex): string;
113
- /**
114
- * Retrieve the index of an address from the source
115
- *
116
- * @param address - The normalized address to retrieve the index for
117
- * @returns The index of the address
118
- */
119
- indexFromAddress(address: Hex): number;
120
- /**
121
- * Get a page of addresses derived from the source.
122
- *
123
- * @param page - The page number to retrieve
124
- * @param pageSize - The number of addresses per page
125
- * @returns An array of IndexedAddress objects, each containing the address and its index
126
- * @throws Will throw an error if the source is not initialized
127
- */
128
- getAddressesPage(page: number, pageSize?: number): IndexedAddress[];
129
- /**
130
- * Gets the source details of the AirgappedSigner.
131
- *
132
- * @returns The source details, or undefined if not initialized
133
- */
134
- getSourceDetails(): AirgappedSignerDetails | undefined;
135
- /**
136
- * Clear the source details.
137
- */
138
- clear(): void;
139
- }
140
- //# sourceMappingURL=airgapped-signer.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"airgapped-signer.d.mts","sourceRoot":"","sources":["../src/airgapped-signer.ts"],"names":[],"mappings":"AAMA,OAAO,EAA6B,KAAK,GAAG,EAAE,wBAAwB;AAItE,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAqB;AAEjD,eAAO,MAAM,iBAAiB;;;;CAI7B,CAAC;AAEF,oBAAY,WAAW;IACrB,EAAE,OAAO;IACT,OAAO,YAAY;CACpB;AAMD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;O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