@transia/ripple-keypairs 1.1.6-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +48 -0
- package/dist/Sha512.d.ts +10 -0
- package/dist/Sha512.d.ts.map +1 -0
- package/dist/Sha512.js +57 -0
- package/dist/Sha512.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +133 -0
- package/dist/index.js.map +1 -0
- package/dist/secp256k1.d.ts +15 -0
- package/dist/secp256k1.d.ts.map +1 -0
- package/dist/secp256k1.js +97 -0
- package/dist/secp256k1.js.map +1 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +51 -0
- package/dist/utils.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2012-2015 Ripple Labs Inc.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# ripple-keypairs [](https://npmjs.org/package/ripple-keypairs) [](https://travis-ci.org/ripple/ripple-keypairs) 
|
|
2
|
+
|
|
3
|
+
An implementation of XRP Ledger keypairs & wallet generation using
|
|
4
|
+
[elliptic](https://github.com/indutny/elliptic) which supports rfc6979 and
|
|
5
|
+
eddsa deterministic signatures.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.org/package/ripple-keypairs)
|
|
8
|
+
|
|
9
|
+
## API Methods
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
generateSeed({entropy?: Array<integer>, algorithm?: string}) -> string
|
|
13
|
+
```
|
|
14
|
+
Generate a seed that can be used to generate keypairs. Entropy can be provided as an array of bytes expressed as integers in the range 0-255. If provided, it must be 16 bytes long (additional bytes are ignored). If not provided, entropy will be automatically generated. The "algorithm" defaults to "ecdsa-secp256k1", but can also be set to "ed25519". The result is a seed encoded in base58, starting with "s".
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
deriveKeypair(seed: string) -> {privateKey: string, publicKey: string}
|
|
18
|
+
```
|
|
19
|
+
Derive a public and private key from a seed. The keys are represented as 33-byte hexadecimal strings.
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
sign(messageHex: string, privateKey: string) -> string
|
|
23
|
+
```
|
|
24
|
+
Sign an arbitrary hex-encoded message with a private key. Returns the signature as a hexadecimal string.
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
verify(messageHex: string, signature: string, publicKey: string) -> boolean
|
|
28
|
+
```
|
|
29
|
+
Verify a signature for a given hex-encoded message and public key. Returns true if the signature is valid, false otherwise.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
deriveAddress(publicKey: string) -> string
|
|
33
|
+
```
|
|
34
|
+
Derive an XRP Ledger classic address from a public key.
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
deriveNodeAddress(publicKey: string) -> string
|
|
38
|
+
```
|
|
39
|
+
Derive a node address from a public key.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Generate a random XRP Ledger address
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
const seed = generateSeed();
|
|
46
|
+
const keypair = deriveKeypair(seed);
|
|
47
|
+
const address = deriveAddress(keypair.publicKey);
|
|
48
|
+
```
|
package/dist/Sha512.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sha512.d.ts","sourceRoot":"","sources":["../src/Sha512.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,OAAO,OAAO,MAAM;IAEzB,IAAI,EAAE,GAAG,CAAA;;IAMT,GAAG,CAAC,KAAK,KAAA;IAKT,MAAM,CAAC,CAAC,KAAA;IASR,MAAM;IAIN,QAAQ;IAIR,UAAU;CAGX"}
|
package/dist/Sha512.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
/* eslint-disable no-bitwise --
|
|
27
|
+
* lots of bitwise operators necessary for this */
|
|
28
|
+
const hashjs = __importStar(require("hash.js"));
|
|
29
|
+
const BigNum = require("bn.js");
|
|
30
|
+
class Sha512 {
|
|
31
|
+
constructor() {
|
|
32
|
+
this.hash = hashjs.sha512();
|
|
33
|
+
}
|
|
34
|
+
add(bytes) {
|
|
35
|
+
this.hash.update(bytes);
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
addU32(i) {
|
|
39
|
+
return this.add([
|
|
40
|
+
(i >>> 24) & 0xff,
|
|
41
|
+
(i >>> 16) & 0xff,
|
|
42
|
+
(i >>> 8) & 0xff,
|
|
43
|
+
i & 0xff,
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
finish() {
|
|
47
|
+
return this.hash.digest();
|
|
48
|
+
}
|
|
49
|
+
first256() {
|
|
50
|
+
return this.finish().slice(0, 32);
|
|
51
|
+
}
|
|
52
|
+
first256BN() {
|
|
53
|
+
return new BigNum(this.first256());
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.default = Sha512;
|
|
57
|
+
//# sourceMappingURL=Sha512.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sha512.js","sourceRoot":"","sources":["../src/Sha512.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;kDACkD;AAClD,gDAAiC;AACjC,gCAAgC;AAEhC,MAAqB,MAAM;IAIzB;QACE,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,CAAA;IAC7B,CAAC;IAED,GAAG,CAAC,KAAK;QACP,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACvB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,CAAC,CAAC;QACN,OAAO,IAAI,CAAC,GAAG,CAAC;YACd,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;YACjB,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;YACjB,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI;YAChB,CAAC,GAAG,IAAI;SACT,CAAC,CAAA;IACJ,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAA;IAC3B,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IACnC,CAAC;IAED,UAAU;QACR,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;IACpC,CAAC;CACF;AAjCD,yBAiCC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as addressCodec from 'ripple-address-codec';
|
|
2
|
+
declare function generateSeed(options?: {
|
|
3
|
+
entropy?: Uint8Array;
|
|
4
|
+
algorithm?: 'ed25519' | 'ecdsa-secp256k1';
|
|
5
|
+
}): string;
|
|
6
|
+
declare function deriveKeypair(seed: string, options?: object): {
|
|
7
|
+
publicKey: string;
|
|
8
|
+
privateKey: string;
|
|
9
|
+
};
|
|
10
|
+
declare function sign(messageHex: any, privateKey: any): string;
|
|
11
|
+
declare function verify(messageHex: any, signature: any, publicKey: any): boolean;
|
|
12
|
+
declare function deriveAddress(publicKey: any): string;
|
|
13
|
+
declare function deriveNodeAddress(publicKey: any): string;
|
|
14
|
+
declare const decodeSeed: typeof addressCodec.decodeSeed;
|
|
15
|
+
export { generateSeed, deriveKeypair, sign, verify, deriveAddress, deriveNodeAddress, decodeSeed, };
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,YAAY,MAAM,sBAAsB,CAAA;AAUpD,iBAAS,YAAY,CACnB,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,UAAU,CAAA;IACpB,SAAS,CAAC,EAAE,SAAS,GAAG,iBAAiB,CAAA;CACrC,GACL,MAAM,CAQR;AA4ED,iBAAS,aAAa,CACpB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,GACf;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;CACnB,CAYA;AASD,iBAAS,IAAI,CAAC,UAAU,KAAA,EAAE,UAAU,KAAA,GAAG,MAAM,CAG5C;AAED,iBAAS,MAAM,CAAC,UAAU,KAAA,EAAE,SAAS,KAAA,EAAE,SAAS,KAAA,GAAG,OAAO,CAGzD;AAQD,iBAAS,aAAa,CAAC,SAAS,KAAA,GAAG,MAAM,CAExC;AAED,iBAAS,iBAAiB,CAAC,SAAS,KAAA,GAAG,MAAM,CAI5C;AAED,QAAA,MAAQ,UAAU,gCAAiB,CAAA;AAEnC,OAAO,EACL,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,UAAU,GACX,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.decodeSeed = exports.deriveNodeAddress = exports.deriveAddress = exports.verify = exports.sign = exports.deriveKeypair = exports.generateSeed = void 0;
|
|
27
|
+
const assert = __importStar(require("assert"));
|
|
28
|
+
const brorand = require("brorand");
|
|
29
|
+
const hashjs = __importStar(require("hash.js"));
|
|
30
|
+
const elliptic = __importStar(require("elliptic"));
|
|
31
|
+
const addressCodec = __importStar(require("ripple-address-codec"));
|
|
32
|
+
const secp256k1_1 = require("./secp256k1");
|
|
33
|
+
const utils = __importStar(require("./utils"));
|
|
34
|
+
const Ed25519 = elliptic.eddsa('ed25519');
|
|
35
|
+
const Secp256k1 = elliptic.ec('secp256k1');
|
|
36
|
+
const { hexToBytes } = utils;
|
|
37
|
+
const { bytesToHex } = utils;
|
|
38
|
+
function generateSeed(options = {}) {
|
|
39
|
+
assert.ok(!options.entropy || options.entropy.length >= 16, 'entropy too short');
|
|
40
|
+
const entropy = options.entropy ? options.entropy.slice(0, 16) : brorand(16);
|
|
41
|
+
const type = options.algorithm === 'ed25519' ? 'ed25519' : 'secp256k1';
|
|
42
|
+
return addressCodec.encodeSeed(Buffer.from(entropy), type);
|
|
43
|
+
}
|
|
44
|
+
exports.generateSeed = generateSeed;
|
|
45
|
+
function hash(message) {
|
|
46
|
+
return hashjs.sha512().update(message).digest().slice(0, 32);
|
|
47
|
+
}
|
|
48
|
+
const secp256k1 = {
|
|
49
|
+
deriveKeypair(entropy, options) {
|
|
50
|
+
const prefix = '00';
|
|
51
|
+
const privateKey = prefix + (0, secp256k1_1.derivePrivateKey)(entropy, options).toString(16, 64).toUpperCase();
|
|
52
|
+
const publicKey = bytesToHex(Secp256k1.keyFromPrivate(privateKey.slice(2))
|
|
53
|
+
.getPublic()
|
|
54
|
+
.encodeCompressed());
|
|
55
|
+
return { privateKey, publicKey };
|
|
56
|
+
},
|
|
57
|
+
sign(message, privateKey) {
|
|
58
|
+
return bytesToHex(Secp256k1.sign(hash(message), hexToBytes(privateKey), {
|
|
59
|
+
canonical: true,
|
|
60
|
+
}).toDER());
|
|
61
|
+
},
|
|
62
|
+
verify(message, signature, publicKey) {
|
|
63
|
+
return Secp256k1.verify(hash(message), signature, hexToBytes(publicKey));
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
const ed25519 = {
|
|
67
|
+
deriveKeypair(entropy) {
|
|
68
|
+
const prefix = 'ED';
|
|
69
|
+
const rawPrivateKey = hash(entropy);
|
|
70
|
+
const privateKey = prefix + bytesToHex(rawPrivateKey);
|
|
71
|
+
const publicKey = prefix + bytesToHex(Ed25519.keyFromSecret(rawPrivateKey).pubBytes());
|
|
72
|
+
return { privateKey, publicKey };
|
|
73
|
+
},
|
|
74
|
+
sign(message, privateKey) {
|
|
75
|
+
// caution: Ed25519.sign interprets all strings as hex, stripping
|
|
76
|
+
// any non-hex characters without warning
|
|
77
|
+
assert.ok(Array.isArray(message), 'message must be array of octets');
|
|
78
|
+
return bytesToHex(Ed25519.sign(message, hexToBytes(privateKey).slice(1)).toBytes());
|
|
79
|
+
},
|
|
80
|
+
verify(message, signature, publicKey) {
|
|
81
|
+
return Ed25519.verify(message, hexToBytes(signature), hexToBytes(publicKey).slice(1));
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
function select(algorithm) {
|
|
85
|
+
const methods = { 'ecdsa-secp256k1': secp256k1, ed25519 };
|
|
86
|
+
return methods[algorithm];
|
|
87
|
+
}
|
|
88
|
+
function deriveKeypair(seed, options) {
|
|
89
|
+
const decoded = addressCodec.decodeSeed(seed);
|
|
90
|
+
const algorithm = decoded.type === 'ed25519' ? 'ed25519' : 'ecdsa-secp256k1';
|
|
91
|
+
const method = select(algorithm);
|
|
92
|
+
const keypair = method.deriveKeypair(decoded.bytes, options);
|
|
93
|
+
const messageToVerify = hash('This test message should verify.');
|
|
94
|
+
const signature = method.sign(messageToVerify, keypair.privateKey);
|
|
95
|
+
/* istanbul ignore if */
|
|
96
|
+
if (method.verify(messageToVerify, signature, keypair.publicKey) !== true) {
|
|
97
|
+
throw new Error('derived keypair did not generate verifiable signature');
|
|
98
|
+
}
|
|
99
|
+
return keypair;
|
|
100
|
+
}
|
|
101
|
+
exports.deriveKeypair = deriveKeypair;
|
|
102
|
+
function getAlgorithmFromKey(key) {
|
|
103
|
+
const bytes = hexToBytes(key);
|
|
104
|
+
return bytes.length === 33 && bytes[0] === 0xed
|
|
105
|
+
? 'ed25519'
|
|
106
|
+
: 'ecdsa-secp256k1';
|
|
107
|
+
}
|
|
108
|
+
function sign(messageHex, privateKey) {
|
|
109
|
+
const algorithm = getAlgorithmFromKey(privateKey);
|
|
110
|
+
return select(algorithm).sign(hexToBytes(messageHex), privateKey);
|
|
111
|
+
}
|
|
112
|
+
exports.sign = sign;
|
|
113
|
+
function verify(messageHex, signature, publicKey) {
|
|
114
|
+
const algorithm = getAlgorithmFromKey(publicKey);
|
|
115
|
+
return select(algorithm).verify(hexToBytes(messageHex), signature, publicKey);
|
|
116
|
+
}
|
|
117
|
+
exports.verify = verify;
|
|
118
|
+
function deriveAddressFromBytes(publicKeyBytes) {
|
|
119
|
+
return addressCodec.encodeAccountID(utils.computePublicKeyHash(publicKeyBytes));
|
|
120
|
+
}
|
|
121
|
+
function deriveAddress(publicKey) {
|
|
122
|
+
return deriveAddressFromBytes(Buffer.from(hexToBytes(publicKey)));
|
|
123
|
+
}
|
|
124
|
+
exports.deriveAddress = deriveAddress;
|
|
125
|
+
function deriveNodeAddress(publicKey) {
|
|
126
|
+
const generatorBytes = addressCodec.decodeNodePublic(publicKey);
|
|
127
|
+
const accountPublicBytes = (0, secp256k1_1.accountPublicFromPublicGenerator)(generatorBytes);
|
|
128
|
+
return deriveAddressFromBytes(accountPublicBytes);
|
|
129
|
+
}
|
|
130
|
+
exports.deriveNodeAddress = deriveNodeAddress;
|
|
131
|
+
const { decodeSeed } = addressCodec;
|
|
132
|
+
exports.decodeSeed = decodeSeed;
|
|
133
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,mCAAmC;AACnC,gDAAiC;AACjC,mDAAoC;AAEpC,mEAAoD;AACpD,2CAAgF;AAChF,+CAAgC;AAEhC,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;AACzC,MAAM,SAAS,GAAG,QAAQ,CAAC,EAAE,CAAC,WAAW,CAAC,CAAA;AAE1C,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAA;AAC5B,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAA;AAE5B,SAAS,YAAY,CACnB,UAGI,EAAE;IAEN,MAAM,CAAC,EAAE,CACP,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,EAChD,mBAAmB,CACpB,CAAA;IACD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,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SAAS,EAAE,SAAS;IAC9C,MAAM,SAAS,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAA;IAChD,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;AAC/E,CAAC;AAwBC,wBAAM;AAtBR,SAAS,sBAAsB,CAAC,cAAsB;IACpD,OAAO,YAAY,CAAC,eAAe,CACjC,KAAK,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAC3C,CAAA;AACH,CAAC;AAED,SAAS,aAAa,CAAC,SAAS;IAC9B,OAAO,sBAAsB,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;AACnE,CAAC;AAeC,sCAAa;AAbf,SAAS,iBAAiB,CAAC,SAAS;IAClC,MAAM,cAAc,GAAG,YAAY,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAA;IAC/D,MAAM,kBAAkB,GAAG,IAAA,4CAAgC,EAAC,cAAc,CAAC,CAAA;IAC3E,OAAO,sBAAsB,CAAC,kBAAkB,CAAC,CAAA;AACnD,CAAC;AAUC,8CAAiB;AARnB,MAAM,EAAE,UAAU,EAAE,GAAG,YAAY,CAAA;AASjC,gCAAU"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param seed - Bytes.
|
|
3
|
+
* @param [opts] - Object.
|
|
4
|
+
* @param [opts.accountIndex=0] - The account number to generate.
|
|
5
|
+
* @param [opts.validator=false] - Generate root key-pair,
|
|
6
|
+
* as used by validators.
|
|
7
|
+
* @returns {bn.js} 256 bit scalar value.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
export declare function derivePrivateKey(seed: any, opts?: {
|
|
11
|
+
validator?: boolean;
|
|
12
|
+
accountIndex?: number;
|
|
13
|
+
}): any;
|
|
14
|
+
export declare function accountPublicFromPublicGenerator(publicGenBytes: any): any;
|
|
15
|
+
//# sourceMappingURL=secp256k1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secp256k1.d.ts","sourceRoot":"","sources":["../src/secp256k1.ts"],"names":[],"mappings":"AAmCA;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,KAAA,EACJ,IAAI,GAAE;IACJ,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;CACjB,OAmBP;AAED,wBAAgB,gCAAgC,CAAC,cAAc,KAAA,OAM9D"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.accountPublicFromPublicGenerator = exports.derivePrivateKey = void 0;
|
|
30
|
+
const elliptic = __importStar(require("elliptic"));
|
|
31
|
+
const Sha512_1 = __importDefault(require("./Sha512"));
|
|
32
|
+
const secp256k1 = elliptic.ec('secp256k1');
|
|
33
|
+
function deriveScalar(bytes, discrim) {
|
|
34
|
+
const order = secp256k1.curve.n;
|
|
35
|
+
for (let i = 0; i <= 0xffffffff; i++) {
|
|
36
|
+
// We hash the bytes to find a 256 bit number, looping until we are sure it
|
|
37
|
+
// is less than the order of the curve.
|
|
38
|
+
const hasher = new Sha512_1.default().add(bytes);
|
|
39
|
+
// If the optional discriminator index was passed in, update the hash.
|
|
40
|
+
if (discrim !== undefined) {
|
|
41
|
+
hasher.addU32(discrim);
|
|
42
|
+
}
|
|
43
|
+
hasher.addU32(i);
|
|
44
|
+
const key = hasher.first256BN();
|
|
45
|
+
/* istanbul ignore else */
|
|
46
|
+
if (key.cmpn(0) > 0 && key.cmp(order) < 0) {
|
|
47
|
+
return key;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// This error is practically impossible to reach.
|
|
51
|
+
// The order of the curve describes the (finite) amount of points on the curve
|
|
52
|
+
// https://github.com/indutny/elliptic/blob/master/lib/elliptic/curves.js#L182
|
|
53
|
+
// How often will an (essentially) random number generated by Sha512 be larger than that?
|
|
54
|
+
// There's 2^32 chances (the for loop) to get a number smaller than the order,
|
|
55
|
+
// and it's rare that you'll even get past the first loop iteration.
|
|
56
|
+
// Note that in TypeScript we actually need the throw, otherwise the function signature would be BN | undefined
|
|
57
|
+
//
|
|
58
|
+
/* istanbul ignore next */
|
|
59
|
+
throw new Error('impossible unicorn ;)');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @param seed - Bytes.
|
|
63
|
+
* @param [opts] - Object.
|
|
64
|
+
* @param [opts.accountIndex=0] - The account number to generate.
|
|
65
|
+
* @param [opts.validator=false] - Generate root key-pair,
|
|
66
|
+
* as used by validators.
|
|
67
|
+
* @returns {bn.js} 256 bit scalar value.
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
70
|
+
function derivePrivateKey(seed, opts = {}) {
|
|
71
|
+
const root = opts.validator;
|
|
72
|
+
const order = secp256k1.curve.n;
|
|
73
|
+
// This private generator represents the `root` private key, and is what's
|
|
74
|
+
// used by validators for signing when a keypair is generated from a seed.
|
|
75
|
+
const privateGen = deriveScalar(seed);
|
|
76
|
+
if (root) {
|
|
77
|
+
// As returned by validation_create for a given seed
|
|
78
|
+
return privateGen;
|
|
79
|
+
}
|
|
80
|
+
const publicGen = secp256k1.g.mul(privateGen);
|
|
81
|
+
// A seed can generate many keypairs as a function of the seed and a uint32.
|
|
82
|
+
// Almost everyone just uses the first account, `0`.
|
|
83
|
+
const accountIndex = opts.accountIndex || 0;
|
|
84
|
+
return deriveScalar(publicGen.encodeCompressed(), accountIndex)
|
|
85
|
+
.add(privateGen)
|
|
86
|
+
.mod(order);
|
|
87
|
+
}
|
|
88
|
+
exports.derivePrivateKey = derivePrivateKey;
|
|
89
|
+
function accountPublicFromPublicGenerator(publicGenBytes) {
|
|
90
|
+
const rootPubPoint = secp256k1.curve.decodePoint(publicGenBytes);
|
|
91
|
+
const scalar = deriveScalar(publicGenBytes, 0);
|
|
92
|
+
const point = secp256k1.g.mul(scalar);
|
|
93
|
+
const offset = rootPubPoint.add(point);
|
|
94
|
+
return offset.encodeCompressed();
|
|
95
|
+
}
|
|
96
|
+
exports.accountPublicFromPublicGenerator = accountPublicFromPublicGenerator;
|
|
97
|
+
//# sourceMappingURL=secp256k1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secp256k1.js","sourceRoot":"","sources":["../src/secp256k1.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAA;IACrC,IAAI,IAAI,EAAE;QACR,oDAAoD;QACpD,OAAO,UAAU,CAAA;KAClB;IACD,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IAC7C,4EAA4E;IAC5E,oDAAoD;IACpD,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,IAAI,CAAC,CAAA;IAC3C,OAAO,YAAY,CAAC,SAAS,CAAC,gBAAgB,EAAE,EAAE,YAAY,CAAC;SAC5D,GAAG,CAAC,UAAU,CAAC;SACf,GAAG,CAAC,KAAK,CAAC,CAAA;AACf,CAAC;AAxBD,4CAwBC;AAED,SAAgB,gCAAgC,CAAC,cAAc;IAC7D,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,cAAc,CAAC,CAAA;IAChE,MAAM,MAAM,GAAG,YAAY,CAAC,cAAc,EAAE,CAAC,CAAC,CAAA;IAC9C,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACrC,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACtC,OAAO,MAAM,CAAC,gBAAgB,EAAE,CAAA;AAClC,CAAC;AAND,4EAMC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
declare function bytesToHex(a: Iterable<number> | ArrayLike<number>): string;
|
|
3
|
+
declare function hexToBytes(a: any): number[];
|
|
4
|
+
declare function computePublicKeyHash(publicKeyBytes: Buffer): Buffer;
|
|
5
|
+
export { bytesToHex, hexToBytes, computePublicKeyHash };
|
|
6
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAIA,iBAAS,UAAU,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAKnE;AAED,iBAAS,UAAU,CAAC,CAAC,KAAA,GAAG,MAAM,EAAE,CAM/B;AAED,iBAAS,oBAAoB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAK5D;AAED,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAA"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.computePublicKeyHash = exports.hexToBytes = exports.bytesToHex = void 0;
|
|
27
|
+
const assert = __importStar(require("assert"));
|
|
28
|
+
const hashjs = __importStar(require("hash.js"));
|
|
29
|
+
const BN = require("bn.js");
|
|
30
|
+
function bytesToHex(a) {
|
|
31
|
+
return Array.from(a, (byteValue) => {
|
|
32
|
+
const hex = byteValue.toString(16).toUpperCase();
|
|
33
|
+
return hex.length > 1 ? hex : `0${hex}`;
|
|
34
|
+
}).join('');
|
|
35
|
+
}
|
|
36
|
+
exports.bytesToHex = bytesToHex;
|
|
37
|
+
function hexToBytes(a) {
|
|
38
|
+
assert.ok(a.length % 2 === 0);
|
|
39
|
+
// Special-case length zero to return [].
|
|
40
|
+
// BN.toArray intentionally returns [0] rather than [] for length zero,
|
|
41
|
+
// which may make sense for BigNum data, but not for byte strings.
|
|
42
|
+
return a.length === 0 ? [] : new BN(a, 16).toArray(null, a.length / 2);
|
|
43
|
+
}
|
|
44
|
+
exports.hexToBytes = hexToBytes;
|
|
45
|
+
function computePublicKeyHash(publicKeyBytes) {
|
|
46
|
+
const hash256 = hashjs.sha256().update(publicKeyBytes).digest();
|
|
47
|
+
const hash160 = hashjs.ripemd160().update(hash256).digest();
|
|
48
|
+
return Buffer.from(hash160);
|
|
49
|
+
}
|
|
50
|
+
exports.computePublicKeyHash = computePublicKeyHash;
|
|
51
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,gDAAiC;AACjC,4BAA4B;AAE5B,SAAS,UAAU,CAAC,CAAuC;IACzD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE;QACjC,MAAM,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAA;QAChD,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAA;IACzC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACb,CAAC;AAiBQ,gCAAU;AAfnB,SAAS,UAAU,CAAC,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;IAC7B,yCAAyC;IACzC,uEAAuE;IACvE,kEAAkE;IAClE,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AACxE,CAAC;AASoB,gCAAU;AAP/B,SAAS,oBAAoB,CAAC,cAAsB;IAClD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,MAAM,EAAE,CAAA;IAE/D,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAA;IAC3D,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AAC7B,CAAC;AAEgC,oDAAoB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@transia/ripple-keypairs",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "1.1.6-alpha.0",
|
|
7
|
+
"description": "Cryptographic key pairs for the XRP Ledger",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc -b",
|
|
10
|
+
"test": "jest --verbose false --silent=false ./test/*.test.ts",
|
|
11
|
+
"clean": "rm -rf ./dist && rm -rf tsconfig.tsbuildinfo",
|
|
12
|
+
"lint": "eslint . --ext .ts",
|
|
13
|
+
"prepublish": "npm run lint && npm test"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/*"
|
|
17
|
+
],
|
|
18
|
+
"main": "dist/",
|
|
19
|
+
"directories": {
|
|
20
|
+
"test": "test"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"bn.js": "^5.1.1",
|
|
24
|
+
"brorand": "^1.0.5",
|
|
25
|
+
"elliptic": "^6.5.4",
|
|
26
|
+
"hash.js": "^1.0.3",
|
|
27
|
+
"ripple-address-codec": "^4.2.5"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git@github.com/Transia-RnD/xrpl.js/tree/beta"
|
|
32
|
+
},
|
|
33
|
+
"license": "ISC",
|
|
34
|
+
"prettier": "@xrplf/prettier-config",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">= 10"
|
|
37
|
+
},
|
|
38
|
+
"gitHead": "05bea18d66e528686e3822f559abbeed8086c8d8"
|
|
39
|
+
}
|