@astrox/identity 0.0.17 → 0.0.27
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/lib/cjs/buffer.js.map +1 -1
- package/lib/cjs/identity/delegation.js +1 -1
- package/lib/cjs/identity/delegation.js.map +1 -1
- package/lib/cjs/identity/der.d.ts +9 -0
- package/lib/cjs/identity/der.js +45 -12
- package/lib/cjs/identity/der.js.map +1 -1
- package/lib/cjs/identity/ed25519.js +1 -1
- package/lib/cjs/identity/secp256k1.d.ts +73 -0
- package/lib/cjs/identity/secp256k1.js +156 -0
- package/lib/cjs/identity/secp256k1.js.map +1 -0
- package/lib/cjs/identity/webauthn.js +1 -1
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/tsconfig-cjs.tsbuildinfo +1735 -1028
- package/lib/tsconfig.tsbuildinfo +590 -657
- package/package.json +20 -2
package/lib/cjs/buffer.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../../src/buffer.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,SAAgB,aAAa,CAAC,SAAiB;;IAC7C,OAAO,IAAI,UAAU,CAAC,
|
1
|
+
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../../src/buffer.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,SAAgB,aAAa,CAAC,SAAiB;;IAC7C,OAAO,IAAI,UAAU,CAAC,CAAC,MAAA,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,mCAAI,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AACnG,CAAC;AAFD,sCAEC;AAED;;;GAGG;AACH,SAAgB,WAAW,CAAC,KAAkB;IAC5C,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;AACnG,CAAC;AAFD,kCAEC"}
|
@@ -14,7 +14,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
14
14
|
var __importStar = (this && this.__importStar) || function (mod) {
|
15
15
|
if (mod && mod.__esModule) return mod;
|
16
16
|
var result = {};
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18
18
|
__setModuleDefault(result, mod);
|
19
19
|
return result;
|
20
20
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"delegation.js","sourceRoot":"","sources":["../../../src/identity/delegation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAOuB;AACvB,iDAA8C;AAC9C,kDAAoC;AACpC,sCAAuD;AAEvD,MAAM,eAAe,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,gCAAgC,CAAC,CAAC;AACnF,MAAM,sBAAsB,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAE1E,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,EAAE;QAClD,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;KACxC;IAED,OAAO,sBAAa,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAa,UAAU;IACrB,YACkB,MAAmB,EACnB,UAAkB,EAClB,OAAqB;QAFrB,WAAM,G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MAAM,CAAC,cAAc,CAC1B,GAA+B,EAC/B,UAA2B;QAE3B,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACnC,CAAC;IASM,aAAa;QAClB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAEM,YAAY;QACjB,OAAO;YACL,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS;SACxC,CAAC;IACJ,CAAC;IACM,IAAI,CAAC,IAAiB;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,OAAyB;QACrD,MAAM,EAAE,IAAI,KAAgB,OAAO,EAAlB,MAAM,UAAK,OAAO,EAA7B,QAAmB,CAAU,CAAC;QACpC,MAAM,SAAS,GAAG,MAAM,mBAAW,CAAC,IAAI,CAAC,CAAC;QAC1C,uCACK,MAAM,KACT,IAAI,EAAE;gBACJ,OAAO,EAAE,IAAI;gBACb,UAAU,EAAE,MAAM,IAAI,CAAC,IAAI,CACzB,IAAI,UAAU,CAAC,CAAC,GAAG,sBAAsB,EAAE,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAC1E;gBACD,iBAAiB,EAAE,IAAI,CAAC,WAAW,CAAC,WAAW;gBAC/C,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS;aAC1C,IACD;IACJ,CAAC;CACF;AAjDD,gDAiDC"}
|
@@ -1,3 +1,8 @@
|
|
1
|
+
export declare const bufEquals: (b1: ArrayBuffer, b2: ArrayBuffer) => boolean;
|
2
|
+
export declare const encodeLenBytes: (len: number) => number;
|
3
|
+
export declare const encodeLen: (buf: Uint8Array, offset: number, len: number) => number;
|
4
|
+
export declare const decodeLenBytes: (buf: Uint8Array, offset: number) => number;
|
5
|
+
export declare const decodeLen: (buf: Uint8Array, offset: number) => number;
|
1
6
|
/**
|
2
7
|
* A DER encoded `SEQUENCE(OID)` for DER-encoded-COSE
|
3
8
|
*/
|
@@ -6,6 +11,10 @@ export declare const DER_COSE_OID: Uint8Array;
|
|
6
11
|
* A DER encoded `SEQUENCE(OID)` for the Ed25519 algorithm
|
7
12
|
*/
|
8
13
|
export declare const ED25519_OID: Uint8Array;
|
14
|
+
/**
|
15
|
+
* A DER encoded `SEQUENCE(OID)` for secp256k1 with the ECDSA algorithm
|
16
|
+
*/
|
17
|
+
export declare const SECP256K1_OID: Uint8Array;
|
9
18
|
/**
|
10
19
|
* Wraps the given `payload` in a DER encoding tagged with the given encoded `oid` like so:
|
11
20
|
* `SEQUENCE(oid, BITSTRING(payload))`
|
package/lib/cjs/identity/der.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.unwrapDER = exports.wrapDER = exports.ED25519_OID = exports.DER_COSE_OID = void 0;
|
3
|
+
exports.unwrapDER = exports.wrapDER = exports.SECP256K1_OID = exports.ED25519_OID = exports.DER_COSE_OID = exports.decodeLen = exports.decodeLenBytes = exports.encodeLen = exports.encodeLenBytes = exports.bufEquals = void 0;
|
4
4
|
const bufEquals = (b1, b2) => {
|
5
5
|
if (b1.byteLength !== b2.byteLength)
|
6
6
|
return false;
|
@@ -12,6 +12,7 @@ const bufEquals = (b1, b2) => {
|
|
12
12
|
}
|
13
13
|
return true;
|
14
14
|
};
|
15
|
+
exports.bufEquals = bufEquals;
|
15
16
|
const encodeLenBytes = (len) => {
|
16
17
|
if (len <= 0x7f) {
|
17
18
|
return 1;
|
@@ -29,6 +30,7 @@ const encodeLenBytes = (len) => {
|
|
29
30
|
throw new Error('Length too long (> 4 bytes)');
|
30
31
|
}
|
31
32
|
};
|
33
|
+
exports.encodeLenBytes = encodeLenBytes;
|
32
34
|
const encodeLen = (buf, offset, len) => {
|
33
35
|
if (len <= 0x7f) {
|
34
36
|
buf[offset] = len;
|
@@ -56,6 +58,7 @@ const encodeLen = (buf, offset, len) => {
|
|
56
58
|
throw new Error('Length too long (> 4 bytes)');
|
57
59
|
}
|
58
60
|
};
|
61
|
+
exports.encodeLen = encodeLen;
|
59
62
|
const decodeLenBytes = (buf, offset) => {
|
60
63
|
if (buf[offset] < 0x80)
|
61
64
|
return 1;
|
@@ -69,13 +72,27 @@ const decodeLenBytes = (buf, offset) => {
|
|
69
72
|
return 4;
|
70
73
|
throw new Error('Length too long (> 4 bytes)');
|
71
74
|
};
|
75
|
+
exports.decodeLenBytes = decodeLenBytes;
|
76
|
+
const decodeLen = (buf, offset) => {
|
77
|
+
const lenBytes = exports.decodeLenBytes(buf, offset);
|
78
|
+
if (lenBytes === 1)
|
79
|
+
return buf[offset];
|
80
|
+
else if (lenBytes === 2)
|
81
|
+
return buf[offset + 1];
|
82
|
+
else if (lenBytes === 3)
|
83
|
+
return (buf[offset + 1] << 8) + buf[offset + 2];
|
84
|
+
else if (lenBytes === 4)
|
85
|
+
return (buf[offset + 1] << 16) + (buf[offset + 2] << 8) + buf[offset + 3];
|
86
|
+
throw new Error('Length too long (> 4 bytes)');
|
87
|
+
};
|
88
|
+
exports.decodeLen = decodeLen;
|
72
89
|
/**
|
73
90
|
* A DER encoded `SEQUENCE(OID)` for DER-encoded-COSE
|
74
91
|
*/
|
75
92
|
exports.DER_COSE_OID = Uint8Array.from([
|
76
93
|
...[0x30, 0x0c],
|
77
94
|
...[0x06, 0x0a],
|
78
|
-
...[0x2b, 0x06, 0x01, 0x04, 0x01, 0x83, 0xb8, 0x43, 0x01, 0x01],
|
95
|
+
...[0x2b, 0x06, 0x01, 0x04, 0x01, 0x83, 0xb8, 0x43, 0x01, 0x01], // DER encoded COSE
|
79
96
|
]);
|
80
97
|
/**
|
81
98
|
* A DER encoded `SEQUENCE(OID)` for the Ed25519 algorithm
|
@@ -83,7 +100,17 @@ exports.DER_COSE_OID = Uint8Array.from([
|
|
83
100
|
exports.ED25519_OID = Uint8Array.from([
|
84
101
|
...[0x30, 0x05],
|
85
102
|
...[0x06, 0x03],
|
86
|
-
...[0x2b, 0x65, 0x70],
|
103
|
+
...[0x2b, 0x65, 0x70], // id-Ed25519 OID
|
104
|
+
]);
|
105
|
+
/**
|
106
|
+
* A DER encoded `SEQUENCE(OID)` for secp256k1 with the ECDSA algorithm
|
107
|
+
*/
|
108
|
+
exports.SECP256K1_OID = Uint8Array.from([
|
109
|
+
...[0x30, 0x10],
|
110
|
+
...[0x06, 0x07],
|
111
|
+
...[0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01],
|
112
|
+
...[0x06, 0x05],
|
113
|
+
...[0x2b, 0x81, 0x04, 0x00, 0x0a], // OID secp256k1
|
87
114
|
]);
|
88
115
|
/**
|
89
116
|
* Wraps the given `payload` in a DER encoding tagged with the given encoded `oid` like so:
|
@@ -94,20 +121,20 @@ exports.ED25519_OID = Uint8Array.from([
|
|
94
121
|
*/
|
95
122
|
function wrapDER(payload, oid) {
|
96
123
|
// The Bit String header needs to include the unused bit count byte in its length
|
97
|
-
const bitStringHeaderLength = 2 + encodeLenBytes(payload.byteLength + 1);
|
124
|
+
const bitStringHeaderLength = 2 + exports.encodeLenBytes(payload.byteLength + 1);
|
98
125
|
const len = oid.byteLength + bitStringHeaderLength + payload.byteLength;
|
99
126
|
let offset = 0;
|
100
|
-
const buf = new Uint8Array(1 + encodeLenBytes(len) + len);
|
127
|
+
const buf = new Uint8Array(1 + exports.encodeLenBytes(len) + len);
|
101
128
|
// Sequence
|
102
129
|
buf[offset++] = 0x30;
|
103
130
|
// Sequence Length
|
104
|
-
offset += encodeLen(buf, offset, len);
|
131
|
+
offset += exports.encodeLen(buf, offset, len);
|
105
132
|
// OID
|
106
133
|
buf.set(oid, offset);
|
107
134
|
offset += oid.byteLength;
|
108
135
|
// Bit String Header
|
109
136
|
buf[offset++] = 0x03;
|
110
|
-
offset += encodeLen(buf, offset, payload.byteLength + 1);
|
137
|
+
offset += exports.encodeLen(buf, offset, payload.byteLength + 1);
|
111
138
|
// 0 padding
|
112
139
|
buf[offset++] = 0x00;
|
113
140
|
buf.set(new Uint8Array(payload), offset);
|
@@ -123,7 +150,7 @@ exports.wrapDER = wrapDER;
|
|
123
150
|
* @param oid The DER encoded (and SEQUENCE wrapped!) expected OID
|
124
151
|
* @returns The unwrapped payload
|
125
152
|
*/
|
126
|
-
|
153
|
+
const unwrapDER = (derEncoded, oid) => {
|
127
154
|
let offset = 0;
|
128
155
|
const expect = (n, msg) => {
|
129
156
|
if (buf[offset++] !== n) {
|
@@ -132,14 +159,20 @@ exports.unwrapDER = (derEncoded, oid) => {
|
|
132
159
|
};
|
133
160
|
const buf = new Uint8Array(derEncoded);
|
134
161
|
expect(0x30, 'sequence');
|
135
|
-
offset += decodeLenBytes(buf, offset);
|
136
|
-
if (!bufEquals(buf.slice(offset, offset + oid.byteLength), oid)) {
|
162
|
+
offset += exports.decodeLenBytes(buf, offset);
|
163
|
+
if (!exports.bufEquals(buf.slice(offset, offset + oid.byteLength), oid)) {
|
137
164
|
throw new Error('Not the expected OID.');
|
138
165
|
}
|
139
166
|
offset += oid.byteLength;
|
140
167
|
expect(0x03, 'bit string');
|
141
|
-
|
168
|
+
const payloadLen = exports.decodeLen(buf, offset) - 1; // Subtracting 1 to account for the 0 padding
|
169
|
+
offset += exports.decodeLenBytes(buf, offset);
|
142
170
|
expect(0x00, '0 padding');
|
143
|
-
|
171
|
+
const result = buf.slice(offset);
|
172
|
+
if (payloadLen !== result.length) {
|
173
|
+
throw new Error(`DER payload mismatch: Expected length ${payloadLen} actual length ${result.length}`);
|
174
|
+
}
|
175
|
+
return result;
|
144
176
|
};
|
177
|
+
exports.unwrapDER = unwrapDER;
|
145
178
|
//# sourceMappingURL=der.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"der.js","sourceRoot":"","sources":["../../../src/identity/der.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"der.js","sourceRoot":"","sources":["../../../src/identity/der.ts"],"names":[],"mappings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C;IACtC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAC1B,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,UAAU,KAAK,MAAM,CAAC,MAAM,EAAE;QAChC,MAAM,IAAI,KAAK,CACb,yCAAyC,UAAU,kBAAkB,MAAM,CAAC,MAAM,EAAE,CACrF,CAAC;KACH;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA5BW,QAAA,SAAS,aA4BpB"}
|
@@ -14,7 +14,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
14
14
|
var __importStar = (this && this.__importStar) || function (mod) {
|
15
15
|
if (mod && mod.__esModule) return mod;
|
16
16
|
var result = {};
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18
18
|
__setModuleDefault(result, mod);
|
19
19
|
return result;
|
20
20
|
};
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import { DerEncodedPublicKey, KeyPair, Signature } from '@astrox/agent';
|
2
|
+
import { PublicKey, SignIdentity } from '@astrox/agent';
|
3
|
+
declare type PublicKeyHex = string;
|
4
|
+
declare type SecretKeyHex = string;
|
5
|
+
export declare type JsonableSecp256k1Identity = [PublicKeyHex, SecretKeyHex];
|
6
|
+
export declare class Secp256k1PublicKey implements PublicKey {
|
7
|
+
/**
|
8
|
+
* Construct Secp256k1PublicKey from an existing PublicKey
|
9
|
+
* @param {PublicKey} key
|
10
|
+
* @returns {Secp256k1PublicKey} Instance of Secp256k1PublicKey
|
11
|
+
*/
|
12
|
+
static from(key: PublicKey): Secp256k1PublicKey;
|
13
|
+
static fromRaw(rawKey: ArrayBuffer): Secp256k1PublicKey;
|
14
|
+
static fromDer(derKey: DerEncodedPublicKey): Secp256k1PublicKey;
|
15
|
+
private static derEncode;
|
16
|
+
private static derDecode;
|
17
|
+
private readonly rawKey;
|
18
|
+
private readonly derKey;
|
19
|
+
private constructor();
|
20
|
+
toDer(): DerEncodedPublicKey;
|
21
|
+
toRaw(): ArrayBuffer;
|
22
|
+
}
|
23
|
+
export declare class Secp256k1KeyIdentity extends SignIdentity {
|
24
|
+
protected _privateKey: ArrayBuffer;
|
25
|
+
/**
|
26
|
+
* Generates an identity. If a seed is provided, the keys are generated from the
|
27
|
+
* seed according to BIP 0032. Otherwise, the key pair is randomly generated.
|
28
|
+
* This method throws an error in case the seed is not 32 bytes long or invalid
|
29
|
+
* for use as a private key.
|
30
|
+
* @param {Uint8Array} seed the optional seed
|
31
|
+
* @returns {Secp256k1KeyIdentity}
|
32
|
+
*/
|
33
|
+
static generate(seed?: Uint8Array): Secp256k1KeyIdentity;
|
34
|
+
static fromParsedJson(obj: JsonableSecp256k1Identity): Secp256k1KeyIdentity;
|
35
|
+
static fromJSON(json: string): Secp256k1KeyIdentity;
|
36
|
+
/**
|
37
|
+
* generates an identity from a public and private key. Please ensure that you are generating these keys securely and protect the user's private key
|
38
|
+
* @param {ArrayBuffer} publicKey
|
39
|
+
* @param {ArrayBuffer} privateKey
|
40
|
+
* @returns {Secp256k1KeyIdentity}
|
41
|
+
*/
|
42
|
+
static fromKeyPair(publicKey: ArrayBuffer, privateKey: ArrayBuffer): Secp256k1KeyIdentity;
|
43
|
+
/**
|
44
|
+
* generates an identity from an existing secret key, and is the correct method to generate an identity from a seed phrase. Please ensure you protect the user's private key.
|
45
|
+
* @param {ArrayBuffer} secretKey
|
46
|
+
* @returns {Secp256k1KeyIdentity}
|
47
|
+
*/
|
48
|
+
static fromSecretKey(secretKey: ArrayBuffer): Secp256k1KeyIdentity;
|
49
|
+
protected _publicKey: Secp256k1PublicKey;
|
50
|
+
protected constructor(publicKey: Secp256k1PublicKey, _privateKey: ArrayBuffer);
|
51
|
+
/**
|
52
|
+
* Serialize this key to JSON-serializable object.
|
53
|
+
* @returns {JsonableSecp256k1Identity}
|
54
|
+
*/
|
55
|
+
toJSON(): JsonableSecp256k1Identity;
|
56
|
+
/**
|
57
|
+
* Return a copy of the key pair.
|
58
|
+
* @returns {KeyPair}
|
59
|
+
*/
|
60
|
+
getKeyPair(): KeyPair;
|
61
|
+
/**
|
62
|
+
* Return the public key.
|
63
|
+
* @returns {Secp256k1PublicKey}
|
64
|
+
*/
|
65
|
+
getPublicKey(): Secp256k1PublicKey;
|
66
|
+
/**
|
67
|
+
* Signs a blob of data, with this identity's private key.
|
68
|
+
* @param {ArrayBuffer} challenge - challenge to sign with this identity's secretKey, producing a signature
|
69
|
+
* @returns {Promise<Signature>} signature
|
70
|
+
*/
|
71
|
+
sign(challenge: ArrayBuffer): Promise<Signature>;
|
72
|
+
}
|
73
|
+
export default Secp256k1KeyIdentity;
|
@@ -0,0 +1,156 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.Secp256k1KeyIdentity = exports.Secp256k1PublicKey = void 0;
|
7
|
+
const agent_1 = require("@astrox/agent");
|
8
|
+
const js_sha256_1 = require("js-sha256");
|
9
|
+
const secp256k1_1 = __importDefault(require("secp256k1"));
|
10
|
+
const tweetnacl_1 = require("tweetnacl");
|
11
|
+
const buffer_1 = require("../buffer");
|
12
|
+
const der_1 = require("./der");
|
13
|
+
class Secp256k1PublicKey {
|
14
|
+
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
|
15
|
+
constructor(key) {
|
16
|
+
key.byteLength;
|
17
|
+
this.rawKey = key;
|
18
|
+
this.derKey = Secp256k1PublicKey.derEncode(key);
|
19
|
+
}
|
20
|
+
/**
|
21
|
+
* Construct Secp256k1PublicKey from an existing PublicKey
|
22
|
+
* @param {PublicKey} key
|
23
|
+
* @returns {Secp256k1PublicKey} Instance of Secp256k1PublicKey
|
24
|
+
*/
|
25
|
+
static from(key) {
|
26
|
+
return this.fromDer(key.toDer());
|
27
|
+
}
|
28
|
+
static fromRaw(rawKey) {
|
29
|
+
return new Secp256k1PublicKey(rawKey);
|
30
|
+
}
|
31
|
+
static fromDer(derKey) {
|
32
|
+
return new Secp256k1PublicKey(this.derDecode(derKey));
|
33
|
+
}
|
34
|
+
static derEncode(publicKey) {
|
35
|
+
return der_1.wrapDER(publicKey, der_1.SECP256K1_OID).buffer;
|
36
|
+
}
|
37
|
+
static derDecode(key) {
|
38
|
+
return der_1.unwrapDER(key, der_1.SECP256K1_OID);
|
39
|
+
}
|
40
|
+
toDer() {
|
41
|
+
return this.derKey;
|
42
|
+
}
|
43
|
+
toRaw() {
|
44
|
+
return this.rawKey;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
exports.Secp256k1PublicKey = Secp256k1PublicKey;
|
48
|
+
class Secp256k1KeyIdentity extends agent_1.SignIdentity {
|
49
|
+
constructor(publicKey, _privateKey) {
|
50
|
+
super();
|
51
|
+
this._privateKey = _privateKey;
|
52
|
+
this._publicKey = publicKey;
|
53
|
+
}
|
54
|
+
/**
|
55
|
+
* Generates an identity. If a seed is provided, the keys are generated from the
|
56
|
+
* seed according to BIP 0032. Otherwise, the key pair is randomly generated.
|
57
|
+
* This method throws an error in case the seed is not 32 bytes long or invalid
|
58
|
+
* for use as a private key.
|
59
|
+
* @param {Uint8Array} seed the optional seed
|
60
|
+
* @returns {Secp256k1KeyIdentity}
|
61
|
+
*/
|
62
|
+
static generate(seed) {
|
63
|
+
if (seed && seed.byteLength !== 32) {
|
64
|
+
throw new Error('Secp256k1 Seed needs to be 32 bytes long.');
|
65
|
+
}
|
66
|
+
let privateKey;
|
67
|
+
if (seed) {
|
68
|
+
// private key from seed according to https://en.bitcoin.it/wiki/BIP_0032
|
69
|
+
// master key generation:
|
70
|
+
privateKey = seed;
|
71
|
+
if (!secp256k1_1.default.privateKeyVerify(privateKey)) {
|
72
|
+
throw new Error('The seed is invalid.');
|
73
|
+
}
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
privateKey = new Uint8Array(tweetnacl_1.randomBytes(32));
|
77
|
+
while (!secp256k1_1.default.privateKeyVerify(privateKey)) {
|
78
|
+
privateKey = new Uint8Array(tweetnacl_1.randomBytes(32));
|
79
|
+
}
|
80
|
+
}
|
81
|
+
const publicKeyRaw = secp256k1_1.default.publicKeyCreate(privateKey, false);
|
82
|
+
const publicKey = Secp256k1PublicKey.fromRaw(publicKeyRaw);
|
83
|
+
return new this(publicKey, privateKey);
|
84
|
+
}
|
85
|
+
static fromParsedJson(obj) {
|
86
|
+
const [publicKeyRaw, privateKeyRaw] = obj;
|
87
|
+
return new Secp256k1KeyIdentity(Secp256k1PublicKey.fromRaw(buffer_1.fromHexString(publicKeyRaw)), buffer_1.fromHexString(privateKeyRaw));
|
88
|
+
}
|
89
|
+
static fromJSON(json) {
|
90
|
+
const parsed = JSON.parse(json);
|
91
|
+
if (Array.isArray(parsed)) {
|
92
|
+
if (typeof parsed[0] === 'string' && typeof parsed[1] === 'string') {
|
93
|
+
return this.fromParsedJson([parsed[0], parsed[1]]);
|
94
|
+
}
|
95
|
+
throw new Error('Deserialization error: JSON must have at least 2 items.');
|
96
|
+
}
|
97
|
+
throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(json)}`);
|
98
|
+
}
|
99
|
+
/**
|
100
|
+
* generates an identity from a public and private key. Please ensure that you are generating these keys securely and protect the user's private key
|
101
|
+
* @param {ArrayBuffer} publicKey
|
102
|
+
* @param {ArrayBuffer} privateKey
|
103
|
+
* @returns {Secp256k1KeyIdentity}
|
104
|
+
*/
|
105
|
+
static fromKeyPair(publicKey, privateKey) {
|
106
|
+
return new Secp256k1KeyIdentity(Secp256k1PublicKey.fromRaw(publicKey), privateKey);
|
107
|
+
}
|
108
|
+
/**
|
109
|
+
* generates an identity from an existing secret key, and is the correct method to generate an identity from a seed phrase. Please ensure you protect the user's private key.
|
110
|
+
* @param {ArrayBuffer} secretKey
|
111
|
+
* @returns {Secp256k1KeyIdentity}
|
112
|
+
*/
|
113
|
+
static fromSecretKey(secretKey) {
|
114
|
+
const publicKey = secp256k1_1.default.publicKeyCreate(new Uint8Array(secretKey), false);
|
115
|
+
const identity = Secp256k1KeyIdentity.fromKeyPair(publicKey, new Uint8Array(secretKey));
|
116
|
+
return identity;
|
117
|
+
}
|
118
|
+
/**
|
119
|
+
* Serialize this key to JSON-serializable object.
|
120
|
+
* @returns {JsonableSecp256k1Identity}
|
121
|
+
*/
|
122
|
+
toJSON() {
|
123
|
+
return [buffer_1.toHexString(this._publicKey.toRaw()), buffer_1.toHexString(this._privateKey)];
|
124
|
+
}
|
125
|
+
/**
|
126
|
+
* Return a copy of the key pair.
|
127
|
+
* @returns {KeyPair}
|
128
|
+
*/
|
129
|
+
getKeyPair() {
|
130
|
+
return {
|
131
|
+
secretKey: this._privateKey,
|
132
|
+
publicKey: this._publicKey,
|
133
|
+
};
|
134
|
+
}
|
135
|
+
/**
|
136
|
+
* Return the public key.
|
137
|
+
* @returns {Secp256k1PublicKey}
|
138
|
+
*/
|
139
|
+
getPublicKey() {
|
140
|
+
return this._publicKey;
|
141
|
+
}
|
142
|
+
/**
|
143
|
+
* Signs a blob of data, with this identity's private key.
|
144
|
+
* @param {ArrayBuffer} challenge - challenge to sign with this identity's secretKey, producing a signature
|
145
|
+
* @returns {Promise<Signature>} signature
|
146
|
+
*/
|
147
|
+
async sign(challenge) {
|
148
|
+
const hash = js_sha256_1.sha256.create();
|
149
|
+
hash.update(challenge);
|
150
|
+
const signature = secp256k1_1.default.ecdsaSign(new Uint8Array(hash.digest()), new Uint8Array(this._privateKey)).signature.buffer;
|
151
|
+
return signature;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
exports.Secp256k1KeyIdentity = Secp256k1KeyIdentity;
|
155
|
+
exports.default = Secp256k1KeyIdentity;
|
156
|
+
//# sourceMappingURL=secp256k1.js.map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SAAS,EAAE,IAAI,CAAC,UAAU;SAC3B,CAAC;IACJ,CAAC;IAED;;;OAGG;IACI,YAAY;QACjB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,IAAI,CAAC,SAAsB;QACtC,MAAM,IAAI,GAAG,kBAAM,CAAC,MAAM,EAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACvB,MAAM,SAAS,GAAG,mBAAS,CAAC,SAAS,CACnC,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAC7B,IAAI,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CACjC,CAAC,SAAS,CAAC,MAAM,CAAC;QACnB,OAAO,SAAsB,CAAC;IAChC,CAAC;CACF;AA3HD,oDA2HC;AAED,kBAAe,oBAAoB,CAAC"}
|
@@ -14,7 +14,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
14
14
|
var __importStar = (this && this.__importStar) || function (mod) {
|
15
15
|
if (mod && mod.__esModule) return mod;
|
16
16
|
var result = {};
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18
18
|
__setModuleDefault(result, mod);
|
19
19
|
return result;
|
20
20
|
};
|
package/lib/cjs/index.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ED25519_OID = exports.DER_COSE_OID = exports.unwrapDER = exports.wrapDER = exports.WebAuthnIdentity = exports.DelegationChain = exports.DelegationIdentity = exports.Delegation = exports.Ed25519PublicKey = exports.Ed25519KeyIdentity = void 0;
|
3
4
|
var ed25519_1 = require("./identity/ed25519");
|
4
5
|
Object.defineProperty(exports, "Ed25519KeyIdentity", { enumerable: true, get: function () { return ed25519_1.Ed25519KeyIdentity; } });
|
5
6
|
Object.defineProperty(exports, "Ed25519PublicKey", { enumerable: true, get: function () { return ed25519_1.Ed25519PublicKey; } });
|
package/lib/cjs/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,8CAA0E;AAAjE,6GAAA,kBAAkB,OAAA;AAAE,2GAAA,gBAAgB,OAAA;AAC7C,oDAK+B;AAJ7B,wGAAA,UAAU,OAAA;AACV,gHAAA,kBAAkB,OAAA;AAClB,6GAAA,eAAe,OAAA;AAGjB,gDAAuD;AAA9C,4GAAA,gBAAgB,OAAA;AACzB,sCAA+E;AAAtE,8FAAA,OAAO,OAAA;AAAE,gGAAA,SAAS,OAAA;AAAE,mGAAA,YAAY,OAAA;AAAE,kGAAA,WAAW,OAAA"}
|