@dxos/crypto 2.33.7-dev.c2ba88fb → 2.33.8-dev.6bc74570

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 (42) hide show
  1. package/dist/src/human-hash.js +1 -1
  2. package/dist/src/human-hash.js.map +1 -1
  3. package/dist/src/index.d.ts +0 -2
  4. package/dist/src/index.d.ts.map +1 -1
  5. package/dist/src/index.js +0 -2
  6. package/dist/src/index.js.map +1 -1
  7. package/dist/src/keys.d.ts +2 -14
  8. package/dist/src/keys.d.ts.map +1 -1
  9. package/dist/src/keys.js +11 -35
  10. package/dist/src/keys.js.map +1 -1
  11. package/dist/src/keys.test.js +2 -8
  12. package/dist/src/keys.test.js.map +1 -1
  13. package/dist/src/validator.d.ts.map +1 -1
  14. package/dist/src/validator.js +2 -2
  15. package/dist/src/validator.js.map +1 -1
  16. package/dist/tsconfig.tsbuildinfo +1 -1
  17. package/package.json +3 -3
  18. package/src/human-hash.ts +1 -1
  19. package/src/index.ts +0 -2
  20. package/src/keys.test.ts +3 -11
  21. package/src/keys.ts +8 -38
  22. package/src/validator.ts +2 -2
  23. package/dist/src/public-key.d.ts +0 -79
  24. package/dist/src/public-key.d.ts.map +0 -1
  25. package/dist/src/public-key.js +0 -147
  26. package/dist/src/public-key.js.map +0 -1
  27. package/dist/src/public-key.test.d.ts +0 -2
  28. package/dist/src/public-key.test.d.ts.map +0 -1
  29. package/dist/src/public-key.test.js +0 -41
  30. package/dist/src/public-key.test.js.map +0 -1
  31. package/dist/src/seedphrase.d.ts +0 -9
  32. package/dist/src/seedphrase.d.ts.map +0 -1
  33. package/dist/src/seedphrase.js +0 -28
  34. package/dist/src/seedphrase.js.map +0 -1
  35. package/dist/src/seedphrase.test.d.ts +0 -2
  36. package/dist/src/seedphrase.test.d.ts.map +0 -1
  37. package/dist/src/seedphrase.test.js +0 -21
  38. package/dist/src/seedphrase.test.js.map +0 -1
  39. package/src/public-key.test.ts +0 -60
  40. package/src/public-key.ts +0 -165
  41. package/src/seedphrase.test.ts +0 -23
  42. package/src/seedphrase.ts +0 -24
@@ -1,79 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { inspect } from 'util';
4
- export declare class PublicKey {
5
- private readonly _value;
6
- /**
7
- * Creates new instance of PublicKey automatically determining the input format.
8
- */
9
- static from(source: PublicKeyLike): PublicKey;
10
- /**
11
- * Creates new instance of PublicKey from hex string.
12
- */
13
- static fromHex(hex: string): PublicKey;
14
- static random(): PublicKey;
15
- /**
16
- * Tests if provided values is an instance of PublicKey.
17
- */
18
- static isPublicKey(value: any): value is PublicKey;
19
- /**
20
- * Asserts that provided values is an instance of PublicKey.
21
- */
22
- static assertValidPublicKey(value: any): asserts value is PublicKey;
23
- /**
24
- * Tests two keys for equality.
25
- */
26
- static equals(left: PublicKeyLike, right: PublicKeyLike): boolean;
27
- constructor(_value: Uint8Array);
28
- /**
29
- * Return underlying Uint8Array representation.
30
- */
31
- asUint8Array(): Uint8Array;
32
- /**
33
- * Covert this key to buffer.
34
- */
35
- asBuffer(): Buffer;
36
- /**
37
- * Convert this key to hex-encoded string.
38
- */
39
- toHex(): string;
40
- /**
41
- * Convert this key to human-readable representation.
42
- */
43
- humanize(): string;
44
- /**
45
- * Same as `PublicKey.humanize()`.
46
- */
47
- toString(): string;
48
- /**
49
- * Same as `PublicKey.humanize()`.
50
- */
51
- toJSON(): string;
52
- /**
53
- * Used by NodeJS to get textual representation of this object when it's printed with a `console.log` statement.
54
- */
55
- [inspect.custom](): string;
56
- /**
57
- * Test this key for equality with some other key.
58
- */
59
- equals(other: PublicKeyLike): boolean;
60
- }
61
- /**
62
- * All representations that can be converted to a PublicKey.
63
- */
64
- export declare type PublicKeyLike = PublicKey | Buffer | Uint8Array | string;
65
- export declare const publicKeySubstitutions: {
66
- 'dxos.halo.keys.PubKey': {
67
- encode: (value: PublicKey) => {
68
- data: Uint8Array;
69
- };
70
- decode: (value: any) => PublicKey;
71
- };
72
- 'dxos.halo.keys.PrivKey': {
73
- encode: (value: Buffer) => {
74
- data: Uint8Array;
75
- };
76
- decode: (value: any) => Buffer;
77
- };
78
- };
79
- //# sourceMappingURL=public-key.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"public-key.d.ts","sourceRoot":"","sources":["../../src/public-key.ts"],"names":[],"mappings":";;AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAI/B,qBAAa,SAAS;IA2DlB,OAAO,CAAC,QAAQ,CAAC,MAAM;IA1DzB;;OAEG;IACH,MAAM,CAAC,IAAI,CAAE,MAAM,EAAE,aAAa,GAAG,SAAS;IAgB9C;;OAEG;IACH,MAAM,CAAC,OAAO,CAAE,GAAG,EAAE,MAAM;IAQ3B,MAAM,CAAC,MAAM,IAAK,SAAS;IAI3B;;OAEG;IACH,MAAM,CAAC,WAAW,CAAE,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,SAAS;IAInD;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,IAAI,SAAS;IAMpE;;OAEG;IACH,MAAM,CAAC,MAAM,CAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa;gBAKrC,MAAM,EAAE,UAAU;IAOrC;;OAEG;IACH,YAAY,IAAK,UAAU;IAI3B;;OAEG;IACH,QAAQ,IAAK,MAAM;IAInB;;OAEG;IACH,KAAK,IAAK,MAAM;IAIhB;;OAEG;IACH,QAAQ,IAAK,MAAM;IAInB;;OAEG;IACH,QAAQ,IAAK,MAAM;IAInB;;OAEG;IACH,MAAM;IAIN;;OAEG;IACH,CAAC,OAAO,CAAC,MAAM,CAAC;IAIhB;;OAEG;IACH,MAAM,CAAE,KAAK,EAAE,aAAa;CAY7B;AAED;;GAEG;AAEH,oBAAY,aAAa,GACrB,SAAS,GACT,MAAM,GACN,UAAU,GACV,MAAM,CAAA;AAIV,eAAO,MAAM,sBAAsB;;wBAGf,SAAS;;;wBACT,GAAG;;;wBAIH,MAAM;;;wBACN,GAAG;;CAEtB,CAAC"}
@@ -1,147 +0,0 @@
1
- "use strict";
2
- //
3
- // Copyright 2020 DXOS.org
4
- //
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.publicKeySubstitutions = exports.PublicKey = void 0;
10
- const hypercore_crypto_1 = __importDefault(require("hypercore-crypto"));
11
- const util_1 = require("util");
12
- const human_hash_1 = require("./human-hash");
13
- class PublicKey {
14
- constructor(_value) {
15
- this._value = _value;
16
- if (!(_value instanceof Uint8Array)) {
17
- throw new TypeError(`Expected Uint8Array, got: ${_value}`);
18
- }
19
- }
20
- /**
21
- * Creates new instance of PublicKey automatically determining the input format.
22
- */
23
- static from(source) {
24
- if (source instanceof PublicKey) {
25
- return source;
26
- }
27
- else if (source instanceof Buffer) {
28
- return new PublicKey(new Uint8Array(source));
29
- }
30
- else if (source instanceof Uint8Array) {
31
- return new PublicKey(source);
32
- }
33
- else if (typeof source === 'string') {
34
- return PublicKey.fromHex(source);
35
- }
36
- else if (source.asUint8Array) {
37
- return new PublicKey(source.asUint8Array());
38
- }
39
- else {
40
- throw new TypeError(`Unable to create PublicKey from ${source}`);
41
- }
42
- }
43
- /**
44
- * Creates new instance of PublicKey from hex string.
45
- */
46
- static fromHex(hex) {
47
- if (hex.startsWith('0x')) {
48
- hex = hex.slice(2);
49
- }
50
- return new PublicKey(new Uint8Array(Buffer.from(hex, 'hex')));
51
- }
52
- static random() {
53
- return PublicKey.from(hypercore_crypto_1.default.randomBytes(32));
54
- }
55
- /**
56
- * Tests if provided values is an instance of PublicKey.
57
- */
58
- static isPublicKey(value) {
59
- return value instanceof PublicKey;
60
- }
61
- /**
62
- * Asserts that provided values is an instance of PublicKey.
63
- */
64
- static assertValidPublicKey(value) {
65
- if (!this.isPublicKey(value)) {
66
- throw new TypeError('Invalid PublicKey');
67
- }
68
- }
69
- /**
70
- * Tests two keys for equality.
71
- */
72
- static equals(left, right) {
73
- return PublicKey.from(left).equals(right);
74
- }
75
- /**
76
- * Return underlying Uint8Array representation.
77
- */
78
- asUint8Array() {
79
- return this._value;
80
- }
81
- /**
82
- * Covert this key to buffer.
83
- */
84
- asBuffer() {
85
- return Buffer.from(this._value);
86
- }
87
- /**
88
- * Convert this key to hex-encoded string.
89
- */
90
- toHex() {
91
- return this.asBuffer().toString('hex');
92
- }
93
- /**
94
- * Convert this key to human-readable representation.
95
- */
96
- humanize() {
97
- return hasher.humanize(this.toHex());
98
- }
99
- /**
100
- * Same as `PublicKey.humanize()`.
101
- */
102
- toString() {
103
- return this.toHex();
104
- }
105
- /**
106
- * Same as `PublicKey.humanize()`.
107
- */
108
- toJSON() {
109
- return this.toHex();
110
- }
111
- /**
112
- * Used by NodeJS to get textual representation of this object when it's printed with a `console.log` statement.
113
- */
114
- [util_1.inspect.custom]() {
115
- return `<PublicKey ${this.humanize()}>`;
116
- }
117
- /**
118
- * Test this key for equality with some other key.
119
- */
120
- equals(other) {
121
- const otherConverted = PublicKey.from(other);
122
- if (this._value.length !== otherConverted._value.length) {
123
- return false;
124
- }
125
- let equal = true;
126
- this._value;
127
- for (let i = 0; i < this._value.length; i++) {
128
- equal && (equal = this._value[i] === otherConverted._value[i]);
129
- }
130
- return equal;
131
- }
132
- }
133
- exports.PublicKey = PublicKey;
134
- const hasher = new human_hash_1.HumanHasher();
135
- exports.publicKeySubstitutions = {
136
- // TODO(dmaretskyi): Rename to dxos.crypto.PublicKey.
137
- 'dxos.halo.keys.PubKey': {
138
- encode: (value) => ({ data: value.asUint8Array() }),
139
- decode: (value) => PublicKey.from(new Uint8Array(value.data))
140
- },
141
- // TODO(dmaretskyi): Shouldn't be substitutted to PublicKey.
142
- 'dxos.halo.keys.PrivKey': {
143
- encode: (value) => ({ data: new Uint8Array(value) }),
144
- decode: (value) => PublicKey.from(new Uint8Array(value.data)).asBuffer()
145
- }
146
- };
147
- //# sourceMappingURL=public-key.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"public-key.js","sourceRoot":"","sources":["../../src/public-key.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,wEAAsC;AACtC,+BAA+B;AAE/B,6CAA2C;AAE3C,MAAa,SAAS;IA0DpB,YACmB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAEnC,IAAI,CAAC,CAAC,MAAM,YAAY,UAAU,CAAC,EAAE;YACnC,MAAM,IAAI,SAAS,CAAC,6BAA6B,MAAM,EAAE,CAAC,CAAC;SAC5D;IACH,CAAC;IA/DD;;OAEG;IACH,MAAM,CAAC,IAAI,CAAE,MAAqB;QAChC,IAAI,MAAM,YAAY,SAAS,EAAE;YAC/B,OAAO,MAAM,CAAC;SACf;aAAM,IAAI,MAAM,YAAY,MAAM,EAAE;YACnC,OAAO,IAAI,SAAS,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;SAC9C;aAAM,IAAI,MAAM,YAAY,UAAU,EAAE;YACvC,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC;SAC9B;aAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YACrC,OAAO,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;SAClC;aAAM,IAAU,MAAO,CAAC,YAAY,EAAE;YACrC,OAAO,IAAI,SAAS,CAAO,MAAO,CAAC,YAAY,EAAE,CAAC,CAAC;SACpD;aAAM;YACL,MAAM,IAAI,SAAS,CAAC,mCAAmC,MAAM,EAAE,CAAC,CAAC;SAClE;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CAAE,GAAW;QACzB,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YACxB,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACpB;QAED,OAAO,IAAI,SAAS,CAAC,I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K,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE;KAC9E;CACF,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=public-key.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"public-key.test.d.ts","sourceRoot":"","sources":["../../src/public-key.test.ts"],"names":[],"mappings":""}
@@ -1,41 +0,0 @@
1
- "use strict";
2
- //
3
- // Copyright 2020 DXOS.org
4
- //
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const keys_1 = require("./keys");
7
- const public_key_1 = require("./public-key");
8
- const KEY_HEX = '2c28f0d08ccc5340aee02655675be5796227a28d27b9704df34b7d8b2d9fddc7';
9
- it('formatting', () => {
10
- const key = public_key_1.PublicKey.fromHex(KEY_HEX);
11
- expect(public_key_1.PublicKey.isPublicKey(key)).toEqual(true);
12
- public_key_1.PublicKey.assertValidPublicKey(key);
13
- expect(key.humanize()).toEqual('lemon-nitrogen-sixteen-undress');
14
- expect(key.toHex()).toEqual(KEY_HEX);
15
- });
16
- it('asBuffer', () => {
17
- const key = public_key_1.PublicKey.fromHex(KEY_HEX);
18
- const buffer = key.asBuffer();
19
- expect(buffer).toBeInstanceOf(Buffer);
20
- expect(Buffer.from(KEY_HEX, 'hex').equals(buffer)).toEqual(true);
21
- });
22
- it('asUint8Array', () => {
23
- const key = public_key_1.PublicKey.fromHex(KEY_HEX);
24
- const array = key.asUint8Array();
25
- expect(array).toBeInstanceOf(Uint8Array);
26
- expect(Buffer.from(KEY_HEX, 'hex').equals(Buffer.from(array))).toEqual(true);
27
- expect(public_key_1.PublicKey.from(Buffer.from(KEY_HEX, 'hex')).asUint8Array()).toBeInstanceOf(Uint8Array);
28
- });
29
- it('from', () => {
30
- expect(public_key_1.PublicKey.from(KEY_HEX).toHex())
31
- .toEqual(KEY_HEX);
32
- expect(public_key_1.PublicKey.from(Buffer.from(KEY_HEX, 'hex')).toHex())
33
- .toEqual(KEY_HEX);
34
- expect(public_key_1.PublicKey.from(new Uint8Array(32)).toHex())
35
- .toEqual('0000000000000000000000000000000000000000000000000000000000000000');
36
- });
37
- it('equals', () => {
38
- expect(public_key_1.PublicKey.equals(public_key_1.PublicKey.from(KEY_HEX), public_key_1.PublicKey.from(KEY_HEX))).toEqual(true);
39
- expect(public_key_1.PublicKey.equals(public_key_1.PublicKey.from((0, keys_1.randomBytes)()), public_key_1.PublicKey.from((0, keys_1.randomBytes)()))).toEqual(false);
40
- });
41
- //# sourceMappingURL=public-key.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"public-key.test.js","sourceRoot":"","sources":["../../src/public-key.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;AAEF,iCAAqC;AACrC,6CAAyC;AAEzC,MAAM,OAAO,GAAG,kEAAkE,CAAC;AAEnF,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE;IACpB,MAAM,GAAG,GAAG,sBAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEvC,MAAM,CAAC,sBAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,sBAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;IAEpC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,gCAAgC,CAAC,CAAC;IACjE,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE;IAClB,MAAM,GAAG,GAAG,sBAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IAE9B,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAEtC,MAAM,CAAC,MAAM,CAAC,I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G,EAAE;IAChB,MAAM,CAAC,sBAAS,CAAC,MAAM,CACrB,sBAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EACvB,sBAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CACxB,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,MAAM,CAAC,sBAAS,CAAC,MAAM,CACrB,sBAAS,CAAC,IAAI,CAAC,IAAA,kBAAW,GAAE,CAAC,EAC7B,sBAAS,CAAC,IAAI,CAAC,IAAA,kBAAW,GAAE,CAAC,CAC9B,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
@@ -1,9 +0,0 @@
1
- /**
2
- * Generate bip39 seed phrase (aka mnemonic).
3
- */
4
- export declare const generateSeedPhrase: () => string;
5
- /**
6
- * Generate key pair from seed phrase.
7
- */
8
- export declare const keyPairFromSeedPhrase: (seedPhrase: string) => import("./keys").KeyPair;
9
- //# sourceMappingURL=seedphrase.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"seedphrase.d.ts","sourceRoot":"","sources":["../../src/seedphrase.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,eAAO,MAAM,kBAAkB,QAAO,MAA4B,CAAC;AAEnE;;GAEG;AACH,eAAO,MAAM,qBAAqB,eAAgB,MAAM,6BAIvD,CAAC"}
@@ -1,28 +0,0 @@
1
- "use strict";
2
- //
3
- // Copyright 2020 DXOS.org
4
- //
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.keyPairFromSeedPhrase = exports.generateSeedPhrase = void 0;
10
- const assert_1 = __importDefault(require("assert"));
11
- const bip39_1 = require("bip39");
12
- const keys_1 = require("./keys");
13
- // Util functions for Identity: export, import, create.
14
- /**
15
- * Generate bip39 seed phrase (aka mnemonic).
16
- */
17
- const generateSeedPhrase = () => (0, bip39_1.generateMnemonic)();
18
- exports.generateSeedPhrase = generateSeedPhrase;
19
- /**
20
- * Generate key pair from seed phrase.
21
- */
22
- const keyPairFromSeedPhrase = (seedPhrase) => {
23
- (0, assert_1.default)(seedPhrase);
24
- const seed = (0, bip39_1.mnemonicToSeedSync)(seedPhrase);
25
- return (0, keys_1.createKeyPair)(seed);
26
- };
27
- exports.keyPairFromSeedPhrase = keyPairFromSeedPhrase;
28
- //# sourceMappingURL=seedphrase.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"seedphrase.js","sourceRoot":"","sources":["../../src/seedphrase.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,oDAA4B;AAC5B,iCAA6D;AAE7D,iCAAuC;AAEvC,uDAAuD;AAEvD;;GAEG;AACI,MAAM,kBAAkB,GAAG,GAAW,EAAE,CAAC,IAAA,wBAAgB,GAAE,CAAC;AAAtD,QAAA,kBAAkB,sBAAoC;AAEnE;;GAEG;AACI,MAAM,qBAAqB,GAAG,CAAC,UAAkB,EAAE,EAAE;IAC1D,IAAA,gBAAM,EAAC,UAAU,CAAC,CAAC;IACnB,MAAM,IAAI,GAAG,IAAA,0BAAkB,EAAC,UAAU,CAAC,CAAC;IAC5C,OAAO,IAAA,oBAAa,EAAC,IAAI,CAAC,CAAC;AAC7B,CAAC,CAAC;AAJW,QAAA,qBAAqB,yBAIhC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=seedphrase.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"seedphrase.test.d.ts","sourceRoot":"","sources":["../../src/seedphrase.test.ts"],"names":[],"mappings":""}
@@ -1,21 +0,0 @@
1
- "use strict";
2
- //
3
- // Copyright 2020 DXOS.org
4
- //
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const bip39_1 = require("bip39");
7
- const keys_1 = require("./keys");
8
- const seedphrase_1 = require("./seedphrase");
9
- it('Basic bip39 operations work', async () => {
10
- const seedPhrase = (0, bip39_1.generateMnemonic)();
11
- const seed = (0, bip39_1.mnemonicToSeedSync)(seedPhrase);
12
- await (0, keys_1.createKeyPair)(seed.slice(0, 32));
13
- });
14
- it('Create keypair from seedphrase', async () => {
15
- const seedPhrase = (0, seedphrase_1.generateSeedPhrase)();
16
- expect(typeof seedPhrase).toBe('string');
17
- expect(seedPhrase.split(/\s+/g).length).toEqual(12);
18
- const recoveredKeyPair = (0, seedphrase_1.keyPairFromSeedPhrase)(seedPhrase);
19
- expect(recoveredKeyPair).toBeDefined();
20
- });
21
- //# sourceMappingURL=seedphrase.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"seedphrase.test.js","sourceRoot":"","sources":["../../src/seedphrase.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;AAEF,iCAA6D;AAE7D,iCAAuC;AACvC,6CAAyE;AAEzE,EAAE,CAAC,6BAA6B,EAAE,KAAK,IAAI,EAAE;IAC3C,MAAM,UAAU,GAAG,IAAA,wBAAgB,GAAE,CAAC;IACtC,MAAM,IAAI,GAAG,IAAA,0BAAkB,EAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,IAAA,oBAAa,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AACzC,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,gCAAgC,EAAE,KAAK,IAAI,EAAE;IAC9C,MAAM,UAAU,GAAG,IAAA,+BAAkB,GAAE,CAAC;IACxC,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAEpD,MAAM,gBAAgB,GAAG,IAAA,kCAAqB,EAAC,UAAU,CAAC,CAAC;IAC3D,MAAM,CAAC,gBAAgB,CAAC,CAAC,WAAW,EAAE,CAAC;AACzC,CAAC,CAAC,CAAC"}
@@ -1,60 +0,0 @@
1
- //
2
- // Copyright 2020 DXOS.org
3
- //
4
-
5
- import { randomBytes } from './keys';
6
- import { PublicKey } from './public-key';
7
-
8
- const KEY_HEX = '2c28f0d08ccc5340aee02655675be5796227a28d27b9704df34b7d8b2d9fddc7';
9
-
10
- it('formatting', () => {
11
- const key = PublicKey.fromHex(KEY_HEX);
12
-
13
- expect(PublicKey.isPublicKey(key)).toEqual(true);
14
- PublicKey.assertValidPublicKey(key);
15
-
16
- expect(key.humanize()).toEqual('lemon-nitrogen-sixteen-undress');
17
- expect(key.toHex()).toEqual(KEY_HEX);
18
- });
19
-
20
- it('asBuffer', () => {
21
- const key = PublicKey.fromHex(KEY_HEX);
22
- const buffer = key.asBuffer();
23
-
24
- expect(buffer).toBeInstanceOf(Buffer);
25
-
26
- expect(Buffer.from(KEY_HEX, 'hex').equals(buffer)).toEqual(true);
27
- });
28
-
29
- it('asUint8Array', () => {
30
- const key = PublicKey.fromHex(KEY_HEX);
31
-
32
- const array = key.asUint8Array();
33
- expect(array).toBeInstanceOf(Uint8Array);
34
- expect(Buffer.from(KEY_HEX, 'hex').equals(Buffer.from(array))).toEqual(true);
35
-
36
- expect(PublicKey.from(Buffer.from(KEY_HEX, 'hex')).asUint8Array()).toBeInstanceOf(Uint8Array);
37
- });
38
-
39
- it('from', () => {
40
- expect(PublicKey.from(KEY_HEX).toHex())
41
- .toEqual(KEY_HEX);
42
-
43
- expect(PublicKey.from(Buffer.from(KEY_HEX, 'hex')).toHex())
44
- .toEqual(KEY_HEX);
45
-
46
- expect(PublicKey.from(new Uint8Array(32)).toHex())
47
- .toEqual('0000000000000000000000000000000000000000000000000000000000000000');
48
- });
49
-
50
- it('equals', () => {
51
- expect(PublicKey.equals(
52
- PublicKey.from(KEY_HEX),
53
- PublicKey.from(KEY_HEX)
54
- )).toEqual(true);
55
-
56
- expect(PublicKey.equals(
57
- PublicKey.from(randomBytes()),
58
- PublicKey.from(randomBytes())
59
- )).toEqual(false);
60
- });
package/src/public-key.ts DELETED
@@ -1,165 +0,0 @@
1
- //
2
- // Copyright 2020 DXOS.org
3
- //
4
-
5
- import crypto from 'hypercore-crypto';
6
- import { inspect } from 'util';
7
-
8
- import { HumanHasher } from './human-hash';
9
-
10
- export class PublicKey {
11
- /**
12
- * Creates new instance of PublicKey automatically determining the input format.
13
- */
14
- static from (source: PublicKeyLike): PublicKey {
15
- if (source instanceof PublicKey) {
16
- return source;
17
- } else if (source instanceof Buffer) {
18
- return new PublicKey(new Uint8Array(source));
19
- } else if (source instanceof Uint8Array) {
20
- return new PublicKey(source);
21
- } else if (typeof source === 'string') {
22
- return PublicKey.fromHex(source);
23
- } else if ((<any>source).asUint8Array) {
24
- return new PublicKey((<any>source).asUint8Array());
25
- } else {
26
- throw new TypeError(`Unable to create PublicKey from ${source}`);
27
- }
28
- }
29
-
30
- /**
31
- * Creates new instance of PublicKey from hex string.
32
- */
33
- static fromHex (hex: string) {
34
- if (hex.startsWith('0x')) {
35
- hex = hex.slice(2);
36
- }
37
-
38
- return new PublicKey(new Uint8Array(Buffer.from(hex, 'hex')));
39
- }
40
-
41
- static random (): PublicKey {
42
- return PublicKey.from(crypto.randomBytes(32));
43
- }
44
-
45
- /**
46
- * Tests if provided values is an instance of PublicKey.
47
- */
48
- static isPublicKey (value: any): value is PublicKey {
49
- return value instanceof PublicKey;
50
- }
51
-
52
- /**
53
- * Asserts that provided values is an instance of PublicKey.
54
- */
55
- static assertValidPublicKey (value: any): asserts value is PublicKey {
56
- if (!this.isPublicKey(value)) {
57
- throw new TypeError('Invalid PublicKey');
58
- }
59
- }
60
-
61
- /**
62
- * Tests two keys for equality.
63
- */
64
- static equals (left: PublicKeyLike, right: PublicKeyLike) {
65
- return PublicKey.from(left).equals(right);
66
- }
67
-
68
- constructor (
69
- private readonly _value: Uint8Array
70
- ) {
71
- if (!(_value instanceof Uint8Array)) {
72
- throw new TypeError(`Expected Uint8Array, got: ${_value}`);
73
- }
74
- }
75
-
76
- /**
77
- * Return underlying Uint8Array representation.
78
- */
79
- asUint8Array (): Uint8Array {
80
- return this._value;
81
- }
82
-
83
- /**
84
- * Covert this key to buffer.
85
- */
86
- asBuffer (): Buffer {
87
- return Buffer.from(this._value);
88
- }
89
-
90
- /**
91
- * Convert this key to hex-encoded string.
92
- */
93
- toHex (): string {
94
- return this.asBuffer().toString('hex');
95
- }
96
-
97
- /**
98
- * Convert this key to human-readable representation.
99
- */
100
- humanize (): string {
101
- return hasher.humanize(this.toHex());
102
- }
103
-
104
- /**
105
- * Same as `PublicKey.humanize()`.
106
- */
107
- toString (): string {
108
- return this.toHex();
109
- }
110
-
111
- /**
112
- * Same as `PublicKey.humanize()`.
113
- */
114
- toJSON () {
115
- return this.toHex();
116
- }
117
-
118
- /**
119
- * Used by NodeJS to get textual representation of this object when it's printed with a `console.log` statement.
120
- */
121
- [inspect.custom] () {
122
- return `<PublicKey ${this.humanize()}>`;
123
- }
124
-
125
- /**
126
- * Test this key for equality with some other key.
127
- */
128
- equals (other: PublicKeyLike) {
129
- const otherConverted = PublicKey.from(other);
130
- if (this._value.length !== otherConverted._value.length) {
131
- return false;
132
- }
133
- let equal = true;
134
- this._value;
135
- for (let i = 0; i < this._value.length; i++) {
136
- equal &&= this._value[i] === otherConverted._value[i];
137
- }
138
- return equal;
139
- }
140
- }
141
-
142
- /**
143
- * All representations that can be converted to a PublicKey.
144
- */
145
- // TODO(burdon): Remove this.
146
- export type PublicKeyLike =
147
- | PublicKey
148
- | Buffer
149
- | Uint8Array
150
- | string
151
-
152
- const hasher = new HumanHasher();
153
-
154
- export const publicKeySubstitutions = {
155
- // TODO(dmaretskyi): Rename to dxos.crypto.PublicKey.
156
- 'dxos.halo.keys.PubKey': {
157
- encode: (value: PublicKey) => ({ data: value.asUint8Array() }),
158
- decode: (value: any) => PublicKey.from(new Uint8Array(value.data))
159
- },
160
- // TODO(dmaretskyi): Shouldn't be substitutted to PublicKey.
161
- 'dxos.halo.keys.PrivKey': {
162
- encode: (value: Buffer) => ({ data: new Uint8Array(value) }),
163
- decode: (value: any) => PublicKey.from(new Uint8Array(value.data)).asBuffer()
164
- }
165
- };
@@ -1,23 +0,0 @@
1
- //
2
- // Copyright 2020 DXOS.org
3
- //
4
-
5
- import { generateMnemonic, mnemonicToSeedSync } from 'bip39';
6
-
7
- import { createKeyPair } from './keys';
8
- import { generateSeedPhrase, keyPairFromSeedPhrase } from './seedphrase';
9
-
10
- it('Basic bip39 operations work', async () => {
11
- const seedPhrase = generateMnemonic();
12
- const seed = mnemonicToSeedSync(seedPhrase);
13
- await createKeyPair(seed.slice(0, 32));
14
- });
15
-
16
- it('Create keypair from seedphrase', async () => {
17
- const seedPhrase = generateSeedPhrase();
18
- expect(typeof seedPhrase).toBe('string');
19
- expect(seedPhrase.split(/\s+/g).length).toEqual(12);
20
-
21
- const recoveredKeyPair = keyPairFromSeedPhrase(seedPhrase);
22
- expect(recoveredKeyPair).toBeDefined();
23
- });
package/src/seedphrase.ts DELETED
@@ -1,24 +0,0 @@
1
- //
2
- // Copyright 2020 DXOS.org
3
- //
4
-
5
- import assert from 'assert';
6
- import { generateMnemonic, mnemonicToSeedSync } from 'bip39';
7
-
8
- import { createKeyPair } from './keys';
9
-
10
- // Util functions for Identity: export, import, create.
11
-
12
- /**
13
- * Generate bip39 seed phrase (aka mnemonic).
14
- */
15
- export const generateSeedPhrase = (): string => generateMnemonic();
16
-
17
- /**
18
- * Generate key pair from seed phrase.
19
- */
20
- export const keyPairFromSeedPhrase = (seedPhrase: string) => {
21
- assert(seedPhrase);
22
- const seed = mnemonicToSeedSync(seedPhrase);
23
- return createKeyPair(seed);
24
- };