@airgap/crypto 0.13.45-beta.2 → 0.13.45-beta.3
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/derive.d.ts +0 -1
- package/derive.js +24 -75
- package/derive.js.map +1 -1
- package/ed25519/derive.d.ts +0 -1
- package/ed25519/derive.js +27 -29
- package/ed25519/derive.js.map +1 -1
- package/encoding.d.ts +1 -1
- package/encoding.js +10 -11
- package/encoding.js.map +1 -1
- package/index.js +5 -5
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/sapling/derive.d.ts +0 -1
- package/sapling/derive.js +10 -58
- package/sapling/derive.js.map +1 -1
- package/secp256k1/derive.d.ts +0 -1
- package/secp256k1/derive.js +27 -29
- package/secp256k1/derive.js.map +1 -1
- package/secret.d.ts +0 -1
- package/secret.js +23 -90
- package/secret.js.map +1 -1
- package/sr25519/derive.d.ts +0 -1
- package/sr25519/derive.js +47 -119
- package/sr25519/derive.js.map +1 -1
- package/types/derivation.d.ts +1 -2
- package/types/key.d.ts +0 -1
- package/utils/bip32.js +45 -40
- package/utils/bip32.js.map +1 -1
- package/utils/bytes.d.ts +0 -1
- package/utils/bytes.js +20 -21
- package/utils/bytes.js.map +1 -1
- package/utils/derivation.js +11 -12
- package/utils/derivation.js.map +1 -1
- package/utils/factory.js +5 -6
- package/utils/factory.js.map +1 -1
- package/utils/hash.d.ts +0 -1
- package/utils/hash.js +4 -5
- package/utils/hash.js.map +1 -1
- package/utils/hex.js +4 -5
- package/utils/hex.js.map +1 -1
- package/utils/zip32.d.ts +0 -1
- package/utils/zip32.js +9 -18
- package/utils/zip32.js.map +1 -1
package/secret.js
CHANGED
|
@@ -1,106 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.mnemonicToSeed =
|
|
40
|
-
|
|
3
|
+
exports.mnemonicToSeed = mnemonicToSeed;
|
|
4
|
+
const coinlib_core_1 = require("@airgap/coinlib-core");
|
|
41
5
|
// @ts-ignore
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function mnemonicToSeed(crypto, mnemonic, password) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
case 1:
|
|
55
|
-
if (!(crypto.compatibility === 'substrate')) return [3 /*break*/, 3];
|
|
56
|
-
return [4 /*yield*/, mnemonicToSubstrateSeed(mnemonic, password)];
|
|
57
|
-
case 2:
|
|
58
|
-
_c = _d.sent();
|
|
59
|
-
return [3 /*break*/, 4];
|
|
60
|
-
case 3:
|
|
61
|
-
_c = undefined;
|
|
62
|
-
_d.label = 4;
|
|
63
|
-
case 4:
|
|
64
|
-
_b = _c;
|
|
65
|
-
_d.label = 5;
|
|
66
|
-
case 5:
|
|
67
|
-
seed = _b;
|
|
68
|
-
if (seed === undefined) {
|
|
69
|
-
throw new Error('Invalid crypto configuration');
|
|
70
|
-
}
|
|
71
|
-
return [2 /*return*/, seed];
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
});
|
|
6
|
+
const bip39_2_5_0_1 = require("@airgap/coinlib-core/dependencies/src/bip39-2.5.0");
|
|
7
|
+
const wasm_crypto_1 = require("@polkadot/wasm-crypto");
|
|
8
|
+
async function mnemonicToSeed(crypto, mnemonic, password) {
|
|
9
|
+
const seed = crypto.algorithm !== 'sr25519'
|
|
10
|
+
? mnemonicToBip39Seed(crypto.secretType ?? 'secret', mnemonic, password)
|
|
11
|
+
: crypto.compatibility === 'substrate'
|
|
12
|
+
? await mnemonicToSubstrateSeed(mnemonic, password)
|
|
13
|
+
: undefined;
|
|
14
|
+
if (seed === undefined) {
|
|
15
|
+
throw new Error('Invalid crypto configuration');
|
|
16
|
+
}
|
|
17
|
+
return seed;
|
|
75
18
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return __generator(this, function (_a) {
|
|
81
|
-
switch (_a.label) {
|
|
82
|
-
case 0: return [4 /*yield*/, (0, wasm_crypto_1.waitReady)()];
|
|
83
|
-
case 1:
|
|
84
|
-
_a.sent();
|
|
85
|
-
secret = (0, wasm_crypto_1.bip39ToMiniSecret)(mnemonic, password || '');
|
|
86
|
-
return [2 /*return*/, Buffer.from(secret)];
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
});
|
|
19
|
+
async function mnemonicToSubstrateSeed(mnemonic, password) {
|
|
20
|
+
await (0, wasm_crypto_1.waitReady)();
|
|
21
|
+
const secret = (0, wasm_crypto_1.bip39ToMiniSecret)(mnemonic, password || '');
|
|
22
|
+
return Buffer.from(secret);
|
|
90
23
|
}
|
|
91
24
|
function mnemonicToBip39Seed(secretType, mnemonic, password) {
|
|
92
|
-
|
|
25
|
+
const seed = (0, bip39_2_5_0_1.mnemonicToSeed)(mnemonic, password);
|
|
93
26
|
switch (secretType) {
|
|
94
27
|
case 'secret':
|
|
95
28
|
return seed;
|
|
96
29
|
case 'miniSecretXor':
|
|
97
|
-
|
|
98
|
-
|
|
30
|
+
const first32 = seed.slice(0, 32);
|
|
31
|
+
const second32 = seed.slice(32);
|
|
99
32
|
// tslint:disable-next-line: no-bitwise
|
|
100
|
-
return Buffer.from(first32.map(
|
|
33
|
+
return Buffer.from(first32.map((byte, index) => byte ^ second32[index]));
|
|
101
34
|
default:
|
|
102
35
|
(0, coinlib_core_1.assertNever)(secretType);
|
|
103
|
-
throw new Error(
|
|
36
|
+
throw new Error(`Secret type ${secretType} is not supported`);
|
|
104
37
|
}
|
|
105
38
|
}
|
|
106
39
|
//# sourceMappingURL=secret.js.map
|
package/secret.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secret.js","sourceRoot":"","sources":["../src/secret.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"secret.js","sourceRoot":"","sources":["../src/secret.ts"],"names":[],"mappings":";;AAMA,wCAaC;AAnBD,uDAAkD;AAClD,aAAa;AACb,mFAAyG;AAEzG,uDAAoE;AAE7D,KAAK,UAAU,cAAc,CAAC,MAA2B,EAAE,QAAgB,EAAE,QAAiB;IACnG,MAAM,IAAI,GACR,MAAM,CAAC,SAAS,KAAK,SAAS;QAC5B,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,UAAU,IAAI,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC;QACxE,CAAC,CAAC,MAAM,CAAC,aAAa,KAAK,WAAW;YACtC,CAAC,CAAC,MAAM,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,CAAC;YACnD,CAAC,CAAC,SAAS,CAAA;IAEf,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED,KAAK,UAAU,uBAAuB,CAAC,QAAgB,EAAE,QAAiB;IACxE,MAAM,IAAA,uBAAS,GAAE,CAAA;IACjB,MAAM,MAAM,GAAe,IAAA,+BAAiB,EAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;IAEtE,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AAC5B,CAAC;AAED,SAAS,mBAAmB,CAAC,UAA4B,EAAE,QAAgB,EAAE,QAAiB;IAC5F,MAAM,IAAI,GAAW,IAAA,4BAAmB,EAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAE5D,QAAQ,UAAU,EAAE,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,IAAI,CAAA;QACb,KAAK,eAAe;YAClB,MAAM,OAAO,GAAW,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;YACzC,MAAM,QAAQ,GAAW,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;YAEvC,uCAAuC;YACvC,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,KAAa,EAAE,EAAE,CAAC,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAC1F;YACE,IAAA,0BAAW,EAAC,UAAU,CAAC,CAAA;YACvB,MAAM,IAAI,KAAK,CAAC,eAAe,UAAU,mBAAmB,CAAC,CAAA;IACjE,CAAC;AACH,CAAC"}
|
package/sr25519/derive.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Sr25519CryptoConfiguration } from '@airgap/module-kit';
|
|
3
2
|
import { DerivationNode } from '../types/derivation';
|
|
4
3
|
export declare function deriveSr25519(compatibility: Sr25519CryptoConfiguration['compatibility'], seed: Buffer, derivationPath?: string): Promise<DerivationNode>;
|
package/sr25519/derive.js
CHANGED
|
@@ -1,129 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.deriveSr25519 = void 0;
|
|
40
|
-
var wasm_crypto_1 = require("@polkadot/wasm-crypto");
|
|
41
|
-
var derivation_1 = require("../utils/derivation");
|
|
42
|
-
var hash_1 = require("../utils/hash");
|
|
43
|
-
function deriveSr25519(compatibility, seed, derivationPath) {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
-
return __generator(this, function (_a) {
|
|
46
|
-
return [2 /*return*/, compatibility === 'substrate' ? deriveSr25519Substrate(seed, derivationPath) : deriveSr25519Standard(seed, derivationPath)];
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
3
|
exports.deriveSr25519 = deriveSr25519;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
4
|
+
const wasm_crypto_1 = require("@polkadot/wasm-crypto");
|
|
5
|
+
const derivation_1 = require("../utils/derivation");
|
|
6
|
+
const hash_1 = require("../utils/hash");
|
|
7
|
+
async function deriveSr25519(compatibility, seed, derivationPath) {
|
|
8
|
+
return compatibility === 'substrate' ? deriveSr25519Substrate(seed, derivationPath) : deriveSr25519Standard(seed, derivationPath);
|
|
9
|
+
}
|
|
10
|
+
async function deriveSr25519Standard(seed, derivationPath) {
|
|
11
|
+
throw new Error('Not implemented');
|
|
57
12
|
}
|
|
58
|
-
function deriveSr25519Substrate(seed, derivationPath) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return __generator(this, function (_a) {
|
|
62
|
-
switch (_a.label) {
|
|
63
|
-
case 0: return [4 /*yield*/, substrateMasterKeyFromSeed(seed)];
|
|
64
|
-
case 1:
|
|
65
|
-
masterNode = _a.sent();
|
|
66
|
-
return [2 /*return*/, derivationPath !== undefined ? deriveSubstrate(masterNode, derivationPath) : masterNode];
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
13
|
+
async function deriveSr25519Substrate(seed, derivationPath) {
|
|
14
|
+
const masterNode = await substrateMasterKeyFromSeed(seed);
|
|
15
|
+
return derivationPath !== undefined ? deriveSubstrate(masterNode, derivationPath) : masterNode;
|
|
70
16
|
}
|
|
71
|
-
function substrateMasterKeyFromSeed(seed) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
parentFingerprint: 0x00000000,
|
|
84
|
-
index: 0,
|
|
85
|
-
chainCode: Buffer.alloc(32, 0),
|
|
86
|
-
secretKey: secretKey,
|
|
87
|
-
publicKey: publicKey
|
|
88
|
-
}];
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
});
|
|
17
|
+
async function substrateMasterKeyFromSeed(seed) {
|
|
18
|
+
await (0, wasm_crypto_1.waitReady)();
|
|
19
|
+
const keyPair = (0, wasm_crypto_1.sr25519KeypairFromSeed)(seed.slice(0, 32));
|
|
20
|
+
const { secretKey, publicKey } = splitKeyPair(keyPair);
|
|
21
|
+
return {
|
|
22
|
+
depth: 0,
|
|
23
|
+
parentFingerprint: 0x00000000,
|
|
24
|
+
index: 0,
|
|
25
|
+
chainCode: Buffer.alloc(32, 0),
|
|
26
|
+
secretKey,
|
|
27
|
+
publicKey
|
|
28
|
+
};
|
|
92
29
|
}
|
|
93
|
-
function deriveSubstrate(masterNode, derivationPath) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
index: next.masked,
|
|
114
|
-
chainCode: index,
|
|
115
|
-
secretKey: secretKey,
|
|
116
|
-
publicKey: publicKey
|
|
117
|
-
};
|
|
118
|
-
}, masterNode)];
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
});
|
|
30
|
+
async function deriveSubstrate(masterNode, derivationPath) {
|
|
31
|
+
await (0, wasm_crypto_1.waitReady)();
|
|
32
|
+
const derivationIndices = (0, derivation_1.splitDerivationPath)(derivationPath);
|
|
33
|
+
return derivationIndices.reduce((derivedKey, next) => {
|
|
34
|
+
const parentFingerprint = (0, hash_1.hash160)(derivedKey.publicKey).readUInt32BE(0);
|
|
35
|
+
const deriveKeyPair = next.isHardened ? wasm_crypto_1.sr25519DeriveKeypairHard : wasm_crypto_1.sr25519DeriveKeypairSoft;
|
|
36
|
+
const keyPair = Buffer.concat([derivedKey.secretKey, derivedKey.publicKey]);
|
|
37
|
+
const index = Buffer.alloc(32, 0);
|
|
38
|
+
index.writeUInt32LE(next.value);
|
|
39
|
+
const derivedKeyPair = deriveKeyPair(keyPair, index);
|
|
40
|
+
const { secretKey, publicKey } = splitKeyPair(derivedKeyPair);
|
|
41
|
+
return {
|
|
42
|
+
depth: derivedKey.depth + 1,
|
|
43
|
+
parentFingerprint,
|
|
44
|
+
index: next.masked,
|
|
45
|
+
chainCode: index,
|
|
46
|
+
secretKey,
|
|
47
|
+
publicKey
|
|
48
|
+
};
|
|
49
|
+
}, masterNode);
|
|
122
50
|
}
|
|
123
51
|
function splitKeyPair(keyPair) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return { secretKey
|
|
52
|
+
const keyPairBuffer = Buffer.from(keyPair);
|
|
53
|
+
const secretKey = keyPairBuffer.slice(0, 64);
|
|
54
|
+
const publicKey = keyPairBuffer.slice(64);
|
|
55
|
+
return { secretKey, publicKey };
|
|
128
56
|
}
|
|
129
57
|
//# sourceMappingURL=derive.js.map
|
package/sr25519/derive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../../src/sr25519/derive.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../../src/sr25519/derive.ts"],"names":[],"mappings":";;AAOA,sCAMC;AAZD,uDAA6H;AAG7H,oDAAyD;AACzD,wCAAuC;AAEhC,KAAK,UAAU,aAAa,CACjC,aAA0D,EAC1D,IAAY,EACZ,cAAuB;IAEvB,OAAO,aAAa,KAAK,WAAW,CAAC,CAAC,CAAC,sBAAsB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAA;AACnI,CAAC;AAED,KAAK,UAAU,qBAAqB,CAAC,IAAY,EAAE,cAAuB;IACxE,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;AACpC,CAAC;AAED,KAAK,UAAU,sBAAsB,CAAC,IAAY,EAAE,cAAuB;IACzE,MAAM,UAAU,GAAmB,MAAM,0BAA0B,CAAC,IAAI,CAAC,CAAA;IAEzE,OAAO,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,UAAU,CAAA;AAChG,CAAC;AAED,KAAK,UAAU,0BAA0B,CAAC,IAAY;IACpD,MAAM,IAAA,uBAAS,GAAE,CAAA;IAEjB,MAAM,OAAO,GAAe,IAAA,oCAAsB,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;IACrE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;IAEtD,OAAO;QACL,KAAK,EAAE,CAAC;QACR,iBAAiB,EAAE,UAAU;QAC7B,KAAK,EAAE,CAAC;QACR,SAAS,EAAE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OAAO,CAAC,CAAA;IAElD,MAAM,SAAS,GAAW,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IACpD,MAAM,SAAS,GAAW,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAEjD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAA;AACjC,CAAC"}
|
package/types/derivation.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
export interface DerivationIndex {
|
|
3
2
|
value: number;
|
|
4
3
|
masked: number;
|
|
@@ -19,4 +18,4 @@ export interface DerivationNode {
|
|
|
19
18
|
secretKey: Buffer;
|
|
20
19
|
publicKey: Buffer;
|
|
21
20
|
}
|
|
22
|
-
export
|
|
21
|
+
export type DerivationKeyType = Extract<keyof DerivationNode, 'secretKey' | 'publicKey'>;
|
package/types/key.d.ts
CHANGED
package/utils/bip32.js
CHANGED
|
@@ -15,65 +15,70 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
36
|
+
exports.bip32EncodeNode = bip32EncodeNode;
|
|
37
|
+
exports.bip32DecodeNode = bip32DecodeNode;
|
|
27
38
|
// @ts-ignore
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function bip32EncodeNode(node, version) {
|
|
33
|
-
var _a, _b;
|
|
34
|
-
if (version === void 0) { version = {}; }
|
|
39
|
+
const bs58check = __importStar(require("@airgap/coinlib-core/dependencies/src/bs58check-2.1.2/index"));
|
|
40
|
+
const factory_1 = require("./factory");
|
|
41
|
+
const XPRV_VERSION = '0488ade4';
|
|
42
|
+
const XPUB_VERSION = '0488b21e';
|
|
43
|
+
function bip32EncodeNode(node, version = {}) {
|
|
35
44
|
return {
|
|
36
45
|
type: 'bip32',
|
|
37
|
-
secretKey: encodeKey(node,
|
|
38
|
-
publicKey: encodeKey(node,
|
|
46
|
+
secretKey: encodeKey(node, version.secretKey ?? XPRV_VERSION, 'secretKey'),
|
|
47
|
+
publicKey: encodeKey(node, version.publicKey ?? XPUB_VERSION, 'publicKey')
|
|
39
48
|
};
|
|
40
49
|
}
|
|
41
|
-
exports.bip32EncodeNode = bip32EncodeNode;
|
|
42
50
|
function encodeKey(node, version, keyType) {
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
const versionBuffer = Buffer.from(version, 'hex');
|
|
52
|
+
const depth = Buffer.alloc(1);
|
|
45
53
|
depth.writeUInt8(node.depth);
|
|
46
|
-
|
|
54
|
+
const parentFingerprint = Buffer.alloc(4);
|
|
47
55
|
parentFingerprint.writeUInt32BE(node.parentFingerprint);
|
|
48
|
-
|
|
56
|
+
const index = Buffer.alloc(4);
|
|
49
57
|
index.writeUInt32BE(node.index);
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
const chainCode = node.chainCode;
|
|
59
|
+
const key = keyType === 'secretKey' ? Buffer.concat([Buffer.alloc(1, 0), node[keyType]]) : node[keyType];
|
|
52
60
|
return bs58check.encode(Buffer.concat([versionBuffer, depth, parentFingerprint, index, chainCode, key]));
|
|
53
61
|
}
|
|
54
|
-
function bip32DecodeNode(node, version) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var xprvDecoded = decodeKey(node.secretKey, (_a = version.secretKey) !== null && _a !== void 0 ? _a : XPRV_VERSION, 'secretKey');
|
|
58
|
-
var xpubDecoded = decodeKey(node.publicKey, (_b = version.publicKey) !== null && _b !== void 0 ? _b : XPUB_VERSION, 'publicKey');
|
|
62
|
+
function bip32DecodeNode(node, version = {}) {
|
|
63
|
+
const xprvDecoded = decodeKey(node.secretKey, version.secretKey ?? XPRV_VERSION, 'secretKey');
|
|
64
|
+
const xpubDecoded = decodeKey(node.publicKey, version.publicKey ?? XPUB_VERSION, 'publicKey');
|
|
59
65
|
return (0, factory_1.newDerivationNodeFromKeys)(xprvDecoded, xpubDecoded);
|
|
60
66
|
}
|
|
61
|
-
exports.bip32DecodeNode = bip32DecodeNode;
|
|
62
67
|
function decodeKey(key, version, keyType) {
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
const buffer = bs58check.decode(key);
|
|
69
|
+
const versionBuffer = buffer.slice(0, 4);
|
|
65
70
|
if (versionBuffer.toString('hex') !== version) {
|
|
66
71
|
throw new Error('Invalid Bip32 version');
|
|
67
72
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
const depth = buffer.readUInt8(4);
|
|
74
|
+
const parentFingerprint = buffer.readUInt32BE(5);
|
|
75
|
+
const index = buffer.readUInt32BE(9);
|
|
76
|
+
const chainCode = buffer.slice(13, 45);
|
|
72
77
|
return {
|
|
73
|
-
depth
|
|
74
|
-
parentFingerprint
|
|
75
|
-
index
|
|
76
|
-
chainCode
|
|
78
|
+
depth,
|
|
79
|
+
parentFingerprint,
|
|
80
|
+
index,
|
|
81
|
+
chainCode,
|
|
77
82
|
key: keyType === 'secretKey' ? buffer.slice(46) : buffer.slice(45)
|
|
78
83
|
};
|
|
79
84
|
}
|
package/utils/bip32.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bip32.js","sourceRoot":"","sources":["../../src/utils/bip32.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bip32.js","sourceRoot":"","sources":["../../src/utils/bip32.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,0CAMC;AAoBD,0CAKC;AApDD,aAAa;AACb,uGAAwF;AAIxF,uCAAqD;AAErD,MAAM,YAAY,GAAW,UAAU,CAAA;AACvC,MAAM,YAAY,GAAW,UAAU,CAAA;AAavC,SAAgB,eAAe,CAAC,IAAoB,EAAE,UAAmB,EAAE;IACzE,OAAO;QACL,IAAI,EAAE,OAAO;QACb,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,IAAI,YAAY,EAAE,WAAW,CAAC;QAC1E,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,IAAI,YAAY,EAAE,WAAW,CAAC;KAC3E,CAAA;AACH,CAAC;AAED,SAAS,SAAS,CAAC,IAAoB,EAAE,OAAe,EAAE,OAA0B;IAClF,MAAM,aAAa,GAAW,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAEzD,MAAM,KAAK,GAAW,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACrC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAE5B,MAAM,iBAAiB,GAAW,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACjD,iBAAiB,CAAC,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IAEvD,MAAM,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AuB,CAAC,CAAA;IAC1C,CAAC;IAED,MAAM,KAAK,GAAW,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IACzC,MAAM,iBAAiB,GAAW,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IACxD,MAAM,KAAK,GAAW,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IAC5C,MAAM,SAAS,GAAW,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;IAE9C,OAAO;QACL,KAAK;QACL,iBAAiB;QACjB,KAAK;QACL,SAAS;QACT,GAAG,EAAE,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;KACnE,CAAA;AACH,CAAC"}
|
package/utils/bytes.d.ts
CHANGED
package/utils/bytes.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.bytesEncodeNode = bytesEncodeNode;
|
|
4
|
+
exports.bytesDecodeNode = bytesDecodeNode;
|
|
5
|
+
const factory_1 = require("./factory");
|
|
5
6
|
function bytesEncodeNode(node) {
|
|
6
7
|
return {
|
|
7
8
|
type: 'bytes',
|
|
@@ -9,36 +10,34 @@ function bytesEncodeNode(node) {
|
|
|
9
10
|
publicKey: encodeKey(node, 'publicKey')
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
|
-
exports.bytesEncodeNode = bytesEncodeNode;
|
|
13
13
|
function encodeKey(node, keyType) {
|
|
14
|
-
|
|
14
|
+
const depth = Buffer.alloc(1);
|
|
15
15
|
depth.writeUInt8(node.depth);
|
|
16
|
-
|
|
16
|
+
const parentFingerprint = Buffer.alloc(4);
|
|
17
17
|
parentFingerprint.writeUInt32BE(node.parentFingerprint);
|
|
18
|
-
|
|
18
|
+
const index = Buffer.alloc(4);
|
|
19
19
|
index.writeUInt32BE(node.index);
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const chainCode = node.chainCode;
|
|
21
|
+
const key = node[keyType];
|
|
22
22
|
return Buffer.concat([depth, parentFingerprint, index, chainCode, key]);
|
|
23
23
|
}
|
|
24
24
|
function bytesDecodeNode(node) {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const xprvDecoded = decodeKey(node.secretKey);
|
|
26
|
+
const xpubDecoded = decodeKey(node.publicKey);
|
|
27
27
|
return (0, factory_1.newDerivationNodeFromKeys)(xprvDecoded, xpubDecoded);
|
|
28
28
|
}
|
|
29
|
-
exports.bytesDecodeNode = bytesDecodeNode;
|
|
30
29
|
function decodeKey(buffer) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const depth = buffer.readUInt8(0);
|
|
31
|
+
const parentFingerprint = buffer.readUInt32BE(1);
|
|
32
|
+
const index = buffer.readUInt32BE(5);
|
|
33
|
+
const chainCode = buffer.slice(9, 41);
|
|
34
|
+
const key = buffer.slice(41);
|
|
36
35
|
return {
|
|
37
|
-
depth
|
|
38
|
-
parentFingerprint
|
|
39
|
-
index
|
|
40
|
-
chainCode
|
|
41
|
-
key
|
|
36
|
+
depth,
|
|
37
|
+
parentFingerprint,
|
|
38
|
+
index,
|
|
39
|
+
chainCode,
|
|
40
|
+
key
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
43
|
//# sourceMappingURL=bytes.js.map
|
package/utils/bytes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/utils/bytes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/utils/bytes.ts"],"names":[],"mappings":";;AAUA,0CAMC;AAkBD,0CAKC;AArCD,uCAAqD;AAQrD,SAAgB,e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,CAAC,CAAC,CAAC,CAAA;IACxD,MAAM,KAAK,GAAW,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IAC5C,MAAM,SAAS,GAAW,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAC7C,MAAM,GAAG,GAAW,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAEpC,OAAO;QACL,KAAK;QACL,iBAAiB;QACjB,KAAK;QACL,SAAS;QACT,GAAG;KACJ,CAAA;AACH,CAAC"}
|
package/utils/derivation.js
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.createDerivationIndexFromNumber = createDerivationIndexFromNumber;
|
|
4
|
+
exports.createDerivationIndexFromString = createDerivationIndexFromString;
|
|
5
|
+
exports.splitDerivationPath = splitDerivationPath;
|
|
6
|
+
exports.incIndex = incIndex;
|
|
7
|
+
const MASK_HARD_DERIVATION = 0x80000000;
|
|
8
|
+
const MASK_SOFT_DERIVATION = 0x00000000;
|
|
6
9
|
function createDerivationIndexFromNumber(value, isHardened) {
|
|
7
|
-
|
|
10
|
+
const mask = isHardened ? MASK_HARD_DERIVATION : MASK_SOFT_DERIVATION;
|
|
8
11
|
return {
|
|
9
|
-
value
|
|
12
|
+
value,
|
|
10
13
|
// tslint:disable-next-line: no-bitwise
|
|
11
14
|
masked: parseInt((BigInt(mask) | BigInt(value)).toString(), 10),
|
|
12
|
-
isHardened
|
|
15
|
+
isHardened
|
|
13
16
|
};
|
|
14
17
|
}
|
|
15
|
-
exports.createDerivationIndexFromNumber = createDerivationIndexFromNumber;
|
|
16
18
|
function createDerivationIndexFromString(value) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
const isHardened = ['h', `'`].includes(value.slice(-1));
|
|
20
|
+
const index = parseInt(isHardened ? value.slice(0, -1) : value, 10);
|
|
19
21
|
return createDerivationIndexFromNumber(index, isHardened);
|
|
20
22
|
}
|
|
21
|
-
exports.createDerivationIndexFromString = createDerivationIndexFromString;
|
|
22
23
|
function splitDerivationPath(path) {
|
|
23
24
|
if (path.length === 0 || !path.startsWith('m/') || path === 'm/') {
|
|
24
25
|
return [];
|
|
25
26
|
}
|
|
26
27
|
return path.slice(2).split('/').map(createDerivationIndexFromString);
|
|
27
28
|
}
|
|
28
|
-
exports.splitDerivationPath = splitDerivationPath;
|
|
29
29
|
function incIndex(current) {
|
|
30
30
|
return createDerivationIndexFromNumber(current.value + 1, current.isHardened);
|
|
31
31
|
}
|
|
32
|
-
exports.incIndex = incIndex;
|
|
33
32
|
//# sourceMappingURL=derivation.js.map
|
package/utils/derivation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derivation.js","sourceRoot":"","sources":["../../src/utils/derivation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"derivation.js","sourceRoot":"","sources":["../../src/utils/derivation.ts"],"names":[],"mappings":";;AAKA,0EASC;AAED,0EAKC;AAED,kDAMC;AAED,4BAEC;AA/BD,MAAM,oBAAoB,GAAW,UAAU,CAAA;AAC/C,MAAM,oBAAoB,GAAW,UAAU,CAAA;AAE/C,SAAgB,+BAA+B,CAAC,KAAa,EAAE,UAAmB;IAChF,MAAM,IAAI,GAAW,UAAU,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,oBAAoB,CAAA;IAE7E,OAAO;QACL,KAAK;QACL,uCAAuC;QACvC,MAAM,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC;QAC/D,UAAU;KACX,CAAA;AACH,CAAC;AAED,SAAgB,+BAA+B,CAAC,KAAa;IAC3D,MAAM,UAAU,GAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CA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