@airgap/crypto 0.13.45-beta.1 → 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/derive.d.ts
CHANGED
package/derive.js
CHANGED
|
@@ -1,80 +1,29 @@
|
|
|
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.derive = void 0;
|
|
40
|
-
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
41
|
-
var derive_1 = require("./ed25519/derive");
|
|
42
|
-
var derive_2 = require("./sapling/derive");
|
|
43
|
-
var derive_3 = require("./secp256k1/derive");
|
|
44
|
-
var derive_4 = require("./sr25519/derive");
|
|
45
|
-
var factory_1 = require("./utils/factory");
|
|
46
|
-
function derive(crypto, seed, derivationPath) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var node;
|
|
49
|
-
return __generator(this, function (_a) {
|
|
50
|
-
switch (_a.label) {
|
|
51
|
-
case 0: return [4 /*yield*/, deriveNode(crypto, seed, derivationPath)];
|
|
52
|
-
case 1:
|
|
53
|
-
node = _a.sent();
|
|
54
|
-
return [2 /*return*/, (0, factory_1.newCryptoDerivativeFromNode)(node)];
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
3
|
exports.derive = derive;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
4
|
+
const coinlib_core_1 = require("@airgap/coinlib-core");
|
|
5
|
+
const derive_1 = require("./ed25519/derive");
|
|
6
|
+
const derive_2 = require("./sapling/derive");
|
|
7
|
+
const derive_3 = require("./secp256k1/derive");
|
|
8
|
+
const derive_4 = require("./sr25519/derive");
|
|
9
|
+
const factory_1 = require("./utils/factory");
|
|
10
|
+
async function derive(crypto, seed, derivationPath) {
|
|
11
|
+
const node = await deriveNode(crypto, seed, derivationPath);
|
|
12
|
+
return (0, factory_1.newCryptoDerivativeFromNode)(node);
|
|
13
|
+
}
|
|
14
|
+
async function deriveNode(crypto, seed, derivationPath) {
|
|
15
|
+
switch (crypto.algorithm) {
|
|
16
|
+
case 'ed25519':
|
|
17
|
+
return (0, derive_1.deriveEd25519)(seed, derivationPath, crypto.key);
|
|
18
|
+
case 'sr25519':
|
|
19
|
+
return (0, derive_4.deriveSr25519)(crypto.compatibility, seed, derivationPath);
|
|
20
|
+
case 'secp256k1':
|
|
21
|
+
return (0, derive_3.deriveSecp256K1)(seed, derivationPath, crypto.key);
|
|
22
|
+
case 'sapling':
|
|
23
|
+
return (0, derive_2.deriveSapling)(seed, derivationPath);
|
|
24
|
+
default:
|
|
25
|
+
(0, coinlib_core_1.assertNever)(crypto);
|
|
26
|
+
throw new Error('Crypto algorithm not supported');
|
|
27
|
+
}
|
|
79
28
|
}
|
|
80
29
|
//# sourceMappingURL=derive.js.map
|
package/derive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../src/derive.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../src/derive.ts"],"names":[],"mappings":";;AAUA,wBAIC;AAdD,uDAAkD;AAGlD,6CAAgD;AAChD,6CAAgD;AAChD,+CAAoD;AACpD,6CAAgD;AAEhD,6CAA6D;AAEtD,KAAK,UAAU,MAAM,CAAC,MAA2B,EAAE,IAAY,EAAE,cAAuB;IAC7F,MAAM,IAAI,GAAmB,MAAM,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,cAAc,CAAC,CAAA;IAE3E,OAAO,IAAA,qCAA2B,EAAC,IAAI,CAAC,CAAA;AAC1C,CAAC;AAED,KAAK,UAAU,UAAU,CAAC,MAA2B,EAAE,IAAY,EAAE,cAAuB;IAC1F,QAAQ,MAAM,CAAC,SAAS,EAAE,CAAC;QACzB,KAAK,SAAS;YACZ,OAAO,IAAA,sBAAa,EAAC,IAAI,EAAE,cAAc,EAAE,MAAM,CAAC,GAAG,CAAC,CAAA;QACxD,KAAK,SAAS;YACZ,OAAO,IAAA,sBAAa,EAAC,MAAM,CAAC,aAAa,EAAE,IAAI,EAAE,cAAc,CAAC,CAAA;QAClE,KAAK,WAAW;YACd,OAAO,IAAA,wBAAe,EAAC,IAAI,EAAE,cAAc,EAAE,MAAM,CAAC,GAAG,CAAC,CAAA;QAC1D,KAAK,SAAS;YACZ,OAAO,IAAA,sBAAa,EAAC,IAAI,EAAE,cAAc,CAAC,CAAA;QAC5C;YACE,IAAA,0BAAW,EAAC,MAAM,CAAC,CAAA;YACnB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;IACrD,CAAC;AACH,CAAC"}
|
package/ed25519/derive.d.ts
CHANGED
package/ed25519/derive.js
CHANGED
|
@@ -1,56 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deriveEd25519 =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function deriveEd25519(seed, derivationPath, key) {
|
|
11
|
-
|
|
12
|
-
var masterNode = masterNodeFromSeed(seed, key);
|
|
3
|
+
exports.deriveEd25519 = deriveEd25519;
|
|
4
|
+
const ed25519_1 = require("@airgap/coinlib-core/dependencies/src/@stablelib/ed25519-1.0.3/packages/ed25519/ed25519");
|
|
5
|
+
const sha512_1 = require("@airgap/coinlib-core/dependencies/src/@stablelib/sha512-1.0.1/packages/sha512/sha512");
|
|
6
|
+
const hmac_1 = require("@stablelib/hmac");
|
|
7
|
+
const derivation_1 = require("../utils/derivation");
|
|
8
|
+
const hash_1 = require("../utils/hash");
|
|
9
|
+
const ED25519_KEY = 'ed25519 seed';
|
|
10
|
+
function deriveEd25519(seed, derivationPath, key = ED25519_KEY) {
|
|
11
|
+
const masterNode = masterNodeFromSeed(seed, key);
|
|
13
12
|
return derivationPath !== undefined ? derive(masterNode, derivationPath) : masterNode;
|
|
14
13
|
}
|
|
15
|
-
exports.deriveEd25519 = deriveEd25519;
|
|
16
14
|
function masterNodeFromSeed(seed, key) {
|
|
17
|
-
|
|
15
|
+
const { key: secretKey, chainCode } = getKey(seed, Buffer.from(key, 'utf-8'));
|
|
18
16
|
return {
|
|
19
17
|
depth: 0,
|
|
20
18
|
parentFingerprint: 0x00000000,
|
|
21
19
|
index: 0,
|
|
22
|
-
chainCode
|
|
23
|
-
secretKey
|
|
20
|
+
chainCode,
|
|
21
|
+
secretKey,
|
|
24
22
|
publicKey: getPublicKey(secretKey)
|
|
25
23
|
};
|
|
26
24
|
}
|
|
27
25
|
function derive(masterNode, derivationPath) {
|
|
28
|
-
|
|
29
|
-
return derivationIndices.reduce(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
const derivationIndices = (0, derivation_1.splitDerivationPath)(derivationPath);
|
|
27
|
+
return derivationIndices.reduce((derivedNode, next) => {
|
|
28
|
+
const parentFingerprint = (0, hash_1.hash160)(derivedNode.publicKey).readUInt32BE(0);
|
|
29
|
+
const index = next.masked;
|
|
30
|
+
const indexBuffer = Buffer.alloc(4);
|
|
33
31
|
indexBuffer.writeUInt32BE(index);
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const data = Buffer.concat([Buffer.alloc(1, 0), derivedNode.secretKey, indexBuffer]);
|
|
33
|
+
const { key: secretKey, chainCode } = getKey(data, derivedNode.chainCode);
|
|
36
34
|
return {
|
|
37
35
|
depth: derivedNode.depth + 1,
|
|
38
|
-
parentFingerprint
|
|
39
|
-
index
|
|
40
|
-
chainCode
|
|
41
|
-
secretKey
|
|
36
|
+
parentFingerprint,
|
|
37
|
+
index,
|
|
38
|
+
chainCode,
|
|
39
|
+
secretKey,
|
|
42
40
|
publicKey: getPublicKey(secretKey)
|
|
43
41
|
};
|
|
44
42
|
}, masterNode);
|
|
45
43
|
}
|
|
46
44
|
function getKey(data, key) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
const I = Buffer.from((0, hmac_1.hmac)(sha512_1.SHA512, key, data));
|
|
46
|
+
const IL = I.slice(0, 32);
|
|
47
|
+
const IR = I.slice(32);
|
|
50
48
|
return { key: IL, chainCode: IR };
|
|
51
49
|
}
|
|
52
50
|
function getPublicKey(privateKey) {
|
|
53
|
-
|
|
51
|
+
const { publicKey } = (0, ed25519_1.generateKeyPairFromSeed)(privateKey);
|
|
54
52
|
return Buffer.from(publicKey);
|
|
55
53
|
}
|
|
56
54
|
//# sourceMappingURL=derive.js.map
|
package/ed25519/derive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../../src/ed25519/derive.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../../src/ed25519/derive.ts"],"names":[],"mappings":";;AAUA,sCAIC;AAdD,qHAAiI;AACjI,iHAA6G;AAC7G,0CAAsC;AAGtC,oDAAyD;AACzD,wCAAuC;AAEvC,MAAM,WAAW,GAAW,cAAc,CAAA;AAE1C,SAAgB,aAAa,CAAC,IAAY,EAAE,cAAuB,EAAE,MAAc,WAAW;IAC5F,MAAM,UAAU,GAAmB,kBAAkB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAEhE,OAAO,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,UAAU,CAAA;AACvF,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAY,EAAE,GAAW;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CAAC,CAAA;AAChB,CAAC;AAED,SAAS,MAAM,CAAC,IAAY,EAAE,GAAW;IACvC,MAAM,CAAC,GAAW,MAAM,CAAC,IAAI,CAAC,IAAA,WAAI,EAAC,eAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAA;IACtD,MAAM,EAAE,GAAW,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IACjC,MAAM,EAAE,GAAW,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAE9B,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAA;AACnC,CAAC;AAED,SAAS,YAAY,CAAC,UAAkB;IACtC,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,iCAAuB,EAAC,UAAU,CAAC,CAAA;IAEzD,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;AAC/B,CAAC"}
|
package/encoding.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Bip32Node, Version } from './utils/bip32';
|
|
|
3
3
|
import { BytesNode } from './utils/bytes';
|
|
4
4
|
import { HexNode } from './utils/hex';
|
|
5
5
|
import { Zip32Node } from './utils/zip32';
|
|
6
|
-
|
|
6
|
+
type EncodedNode = BytesNode | HexNode | Bip32Node | Zip32Node;
|
|
7
7
|
export declare function encodeDerivative(type: BytesNode['type'], derivative: CryptoDerivative): BytesNode;
|
|
8
8
|
export declare function encodeDerivative(type: HexNode['type'], derivative: CryptoDerivative): HexNode;
|
|
9
9
|
export declare function encodeDerivative(type: Bip32Node['type'], derivative: CryptoDerivative, version?: Version): Bip32Node;
|
package/encoding.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
exports.encodeDerivative = encodeDerivative;
|
|
4
|
+
exports.decodeDerivative = decodeDerivative;
|
|
5
|
+
const coinlib_core_1 = require("@airgap/coinlib-core");
|
|
6
|
+
const bip32_1 = require("./utils/bip32");
|
|
7
|
+
const bytes_1 = require("./utils/bytes");
|
|
8
|
+
const factory_1 = require("./utils/factory");
|
|
9
|
+
const hex_1 = require("./utils/hex");
|
|
10
|
+
const zip32_1 = require("./utils/zip32");
|
|
10
11
|
function encodeDerivative(type, derivative, bip39VersionOrUndefined) {
|
|
11
|
-
|
|
12
|
+
const node = (0, factory_1.newDerivationNodeFromDerivative)(derivative);
|
|
12
13
|
return encodeNode(type, node, bip39VersionOrUndefined);
|
|
13
14
|
}
|
|
14
|
-
exports.encodeDerivative = encodeDerivative;
|
|
15
15
|
function encodeNode(type, node, bip39VersionOrUndefined) {
|
|
16
16
|
switch (type) {
|
|
17
17
|
case 'bytes':
|
|
@@ -28,10 +28,9 @@ function encodeNode(type, node, bip39VersionOrUndefined) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
function decodeDerivative(node) {
|
|
31
|
-
|
|
31
|
+
const decodedNode = decodeNode(node);
|
|
32
32
|
return (0, factory_1.newCryptoDerivativeFromNode)(decodedNode);
|
|
33
33
|
}
|
|
34
|
-
exports.decodeDerivative = decodeDerivative;
|
|
35
34
|
function decodeNode(node) {
|
|
36
35
|
switch (node.type) {
|
|
37
36
|
case 'bytes':
|
package/encoding.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../src/encoding.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../src/encoding.ts"],"names":[],"mappings":";;AAiBA,4CAIC;AAkBD,4CAIC;AA3CD,uDAAkD;AAIlD,yCAAoF;AACpF,yCAA2E;AAC3E,6CAA8F;AAC9F,qCAAmE;AACnE,yCAA2E;AAS3E,SAAgB,gBAAgB,CAAC,IAAkB,E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CAAC,+BAA+B,CAAC,CAAA;IACpD,CAAC;AACH,CAAC"}
|
package/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decodeDerivative = exports.encodeDerivative = exports.mnemonicToSeed = exports.deriveSr25519 = exports.deriveEd25519 = exports.derive = void 0;
|
|
4
|
-
|
|
4
|
+
const derive_1 = require("./derive");
|
|
5
5
|
Object.defineProperty(exports, "derive", { enumerable: true, get: function () { return derive_1.derive; } });
|
|
6
|
-
|
|
6
|
+
const derive_2 = require("./ed25519/derive");
|
|
7
7
|
Object.defineProperty(exports, "deriveEd25519", { enumerable: true, get: function () { return derive_2.deriveEd25519; } });
|
|
8
|
-
|
|
8
|
+
const encoding_1 = require("./encoding");
|
|
9
9
|
Object.defineProperty(exports, "decodeDerivative", { enumerable: true, get: function () { return encoding_1.decodeDerivative; } });
|
|
10
10
|
Object.defineProperty(exports, "encodeDerivative", { enumerable: true, get: function () { return encoding_1.encodeDerivative; } });
|
|
11
|
-
|
|
11
|
+
const secret_1 = require("./secret");
|
|
12
12
|
Object.defineProperty(exports, "mnemonicToSeed", { enumerable: true, get: function () { return secret_1.mnemonicToSeed; } });
|
|
13
|
-
|
|
13
|
+
const derive_3 = require("./sr25519/derive");
|
|
14
14
|
Object.defineProperty(exports, "deriveSr25519", { enumerable: true, get: function () { return derive_3.deriveSr25519; } });
|
|
15
15
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AAQxB,uFARA,eAAM,OAQA;AAPf,6CAAgD;AAO/B,8FAPR,sBAAa,OAOQ;AAN9B,yCAA+D;AAcpC,iGAdlB,2BAAgB,OAckB;AAAlC,iGAdkB,2BAAgB,OAclB;AAbzB,qCAAyC;AAShC,+FATA,uBAAc,OASA;AARvB,6CAAgD;AAIhB,8FAJvB,sBAAa,OAIuB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airgap/crypto",
|
|
3
|
-
"version": "0.13.45-beta.
|
|
3
|
+
"version": "0.13.45-beta.3",
|
|
4
4
|
"description": "The @airgap/crypto packages provides common crypto functionalities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"airgap",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"author": "Papers AG <contact@papers.ch> (https://papers.ch)",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@airgap/coinlib-core": "^0.13.45-beta.
|
|
34
|
-
"@airgap/module-kit": "^0.13.45-beta.
|
|
33
|
+
"@airgap/coinlib-core": "^0.13.45-beta.3",
|
|
34
|
+
"@airgap/module-kit": "^0.13.45-beta.3",
|
|
35
35
|
"@airgap/sapling-wasm": "^0.0.9",
|
|
36
36
|
"@polkadot/wasm-crypto": "0.20.1",
|
|
37
37
|
"@stablelib/hmac": "^1.0.1"
|
package/sapling/derive.d.ts
CHANGED
package/sapling/derive.js
CHANGED
|
@@ -1,63 +1,15 @@
|
|
|
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.deriveSapling =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
function deriveSapling(seed, derivationPath) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
xsk = _a.sent();
|
|
50
|
-
return [4 /*yield*/, (0, sapling_wasm_1.getExtendedFullViewingKeyFromSpendingKey)(xsk)];
|
|
51
|
-
case 2:
|
|
52
|
-
xfvk = _a.sent();
|
|
53
|
-
return [2 /*return*/, (0, zip32_1.zip32DecodeNode)({
|
|
54
|
-
type: 'zip32bytes',
|
|
55
|
-
secretKey: xsk,
|
|
56
|
-
publicKey: xfvk
|
|
57
|
-
})];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
3
|
+
exports.deriveSapling = deriveSapling;
|
|
4
|
+
const sapling_wasm_1 = require("@airgap/sapling-wasm");
|
|
5
|
+
const zip32_1 = require("../utils/zip32");
|
|
6
|
+
async function deriveSapling(seed, derivationPath) {
|
|
7
|
+
const xsk = await (0, sapling_wasm_1.getExtendedSpendingKey)(seed, derivationPath ?? 'm/');
|
|
8
|
+
const xfvk = await (0, sapling_wasm_1.getExtendedFullViewingKeyFromSpendingKey)(xsk);
|
|
9
|
+
return (0, zip32_1.zip32DecodeNode)({
|
|
10
|
+
type: 'zip32bytes',
|
|
11
|
+
secretKey: xsk,
|
|
12
|
+
publicKey: xfvk
|
|
60
13
|
});
|
|
61
14
|
}
|
|
62
|
-
exports.deriveSapling = deriveSapling;
|
|
63
15
|
//# sourceMappingURL=derive.js.map
|
package/sapling/derive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../../src/sapling/derive.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../../src/sapling/derive.ts"],"names":[],"mappings":";;AAKA,sCASC;AAdD,uDAAuG;AAGvG,0CAAgD;AAEzC,KAAK,UAAU,aAAa,CAAC,IAAY,EAAE,cAAuB;IACvE,MAAM,GAAG,GAAW,MAAM,IAAA,qCAAsB,EAAC,IAAI,EAAE,cAAc,IAAI,IAAI,CAAC,CAAA;IAC9E,MAAM,IAAI,GAAW,MAAM,IAAA,uDAAwC,EAAC,GAAG,CAAC,CAAA;IAExE,OAAO,IAAA,uBAAe,EAAC;QACrB,IAAI,EAAE,YAAY;QAClB,SAAS,EAAE,GAAG;QACd,SAAS,EAAE,IAAI;KAChB,CAAC,CAAA;AACJ,CAAC"}
|
package/secp256k1/derive.d.ts
CHANGED
package/secp256k1/derive.js
CHANGED
|
@@ -3,67 +3,65 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.deriveSecp256K1 =
|
|
7
|
-
|
|
6
|
+
exports.deriveSecp256K1 = deriveSecp256K1;
|
|
7
|
+
const sha512_1 = require("@airgap/coinlib-core/dependencies/src/@stablelib/sha512-1.0.1/packages/sha512/sha512");
|
|
8
8
|
// @ts-ignore
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function deriveSecp256K1(seed, derivationPath, key) {
|
|
15
|
-
|
|
16
|
-
var masterNode = masterNodeFromSeed(seed, key);
|
|
9
|
+
const elliptic_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/secp256k1-4.0.2/elliptic"));
|
|
10
|
+
const hmac_1 = require("@stablelib/hmac");
|
|
11
|
+
const derivation_1 = require("../utils/derivation");
|
|
12
|
+
const hash_1 = require("../utils/hash");
|
|
13
|
+
const BITCOIN_KEY = 'Bitcoin seed';
|
|
14
|
+
function deriveSecp256K1(seed, derivationPath, key = BITCOIN_KEY) {
|
|
15
|
+
const masterNode = masterNodeFromSeed(seed, key);
|
|
17
16
|
return derivationPath !== undefined ? derive(masterNode, derivationPath) : masterNode;
|
|
18
17
|
}
|
|
19
|
-
exports.deriveSecp256K1 = deriveSecp256K1;
|
|
20
18
|
function masterNodeFromSeed(seed, key) {
|
|
21
|
-
|
|
19
|
+
const { key: secretKey, chainCode } = getKey(seed, Buffer.from(key, 'utf-8'));
|
|
22
20
|
return {
|
|
23
21
|
depth: 0,
|
|
24
22
|
parentFingerprint: 0x00000000,
|
|
25
23
|
index: 0,
|
|
26
|
-
chainCode
|
|
27
|
-
secretKey
|
|
24
|
+
chainCode,
|
|
25
|
+
secretKey,
|
|
28
26
|
publicKey: getPublicKey(secretKey)
|
|
29
27
|
};
|
|
30
28
|
}
|
|
31
29
|
function derive(masterNode, derivationPath) {
|
|
32
|
-
|
|
30
|
+
const derivationIndices = (0, derivation_1.splitDerivationPath)(derivationPath);
|
|
33
31
|
return derivationIndices.reduce(deriveChild, masterNode);
|
|
34
32
|
}
|
|
35
33
|
function deriveChild(node, derivationIndex) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
const parentFingerprint = (0, hash_1.hash160)(node.publicKey).readUInt32BE(0);
|
|
35
|
+
const index = derivationIndex.masked;
|
|
36
|
+
const indexBuffer = Buffer.alloc(4);
|
|
39
37
|
indexBuffer.writeUInt32BE(index);
|
|
40
|
-
|
|
38
|
+
const data = derivationIndex.isHardened
|
|
41
39
|
? Buffer.concat([Buffer.alloc(1, 0), node.secretKey, indexBuffer])
|
|
42
40
|
: Buffer.concat([node.publicKey, indexBuffer]);
|
|
43
|
-
|
|
41
|
+
const { key, chainCode } = getKey(data, node.chainCode);
|
|
44
42
|
try {
|
|
45
|
-
|
|
43
|
+
const ki = Buffer.from(elliptic_1.default.privateKeyTweakAdd(Buffer.from(node.secretKey), key));
|
|
46
44
|
return {
|
|
47
45
|
depth: node.depth + 1,
|
|
48
|
-
parentFingerprint
|
|
49
|
-
index
|
|
50
|
-
chainCode
|
|
46
|
+
parentFingerprint,
|
|
47
|
+
index,
|
|
48
|
+
chainCode,
|
|
51
49
|
secretKey: ki,
|
|
52
50
|
publicKey: getPublicKey(ki)
|
|
53
51
|
};
|
|
54
52
|
}
|
|
55
|
-
catch
|
|
53
|
+
catch {
|
|
56
54
|
return deriveChild(node, (0, derivation_1.incIndex)(derivationIndex));
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
57
|
function getKey(data, key) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
const I = Buffer.from((0, hmac_1.hmac)(sha512_1.SHA512, key, data));
|
|
59
|
+
const IL = I.slice(0, 32);
|
|
60
|
+
const IR = I.slice(32);
|
|
63
61
|
return { key: IL, chainCode: IR };
|
|
64
62
|
}
|
|
65
63
|
function getPublicKey(privateKey) {
|
|
66
|
-
|
|
64
|
+
const publicKey = elliptic_1.default.publicKeyCreate(privateKey, true);
|
|
67
65
|
return Buffer.from(publicKey);
|
|
68
66
|
}
|
|
69
67
|
//# sourceMappingURL=derive.js.map
|
package/secp256k1/derive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../../src/secp256k1/derive.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../../src/secp256k1/derive.ts"],"names":[],"mappings":";;;;;AAWA,0CAIC;AAfD,iHAA6G;AAC7G,aAAa;AACb,8GAAsF;AACtF,0CAAsC;AAGtC,oDAAmE;AACnE,wCAAuC;AAEvC,MAAM,WAAW,GAAW,cAAc,CAAA;AAE1C,SAAgB,eAAe,CAAC,IAAY,EAAE,cAAuB,EAAE,MAAc,WAAW;IAC9F,MAAM,UAAU,GAAmB,kBAAkB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAEhE,OAAO,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,UAAU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