@did-btcr2/keypair 0.5.1 → 0.7.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.
@@ -1,69 +1,84 @@
1
1
  import { Hex, KeyBytes, Maybe, MultibaseObject, PublicKeyObject } from '@did-btcr2/common';
2
- import { SecretKey } from './secret.js';
2
+ import { Secp256k1SecretKey } from './secret.js';
3
3
  export interface Point {
4
4
  x: KeyBytes;
5
5
  y: KeyBytes;
6
6
  }
7
7
  /**
8
- * Interface for the PublicKey class.
9
- * @interface IPublicKey
10
- * @type {IPublicKey}
8
+ * General PublicKey Interface used by CompressedSecp256k1PublicKey.
9
+ * @interface PublicKey
10
+ * @type {PublicKey}
11
11
  */
12
- export interface IPublicKey {
12
+ export interface PublicKey {
13
+ /**
14
+ * Compressed public key getter.
15
+ * @readonly @type {KeyBytes} The 33 byte compressed public key [parity, x-coord].
16
+ */
17
+ compressed: KeyBytes;
13
18
  /**
14
19
  * Uncompressed public key getter.
15
20
  * @readonly @type {KeyBytes} The 65 byte uncompressed public key [0x04, x-coord, y-coord].
16
21
  */
17
22
  uncompressed: KeyBytes;
18
23
  /**
19
- * Compressed public key getter.
20
- * @readonly @type {KeyBytes} The 33 byte compressed public key [parity, x-coord].
24
+ * X-only public key getter.
25
+ * @readonly @type {KeyBytes} The 32 byte x-only public key [x-coord].
21
26
  */
22
- compressed: KeyBytes;
27
+ xOnly: KeyBytes;
23
28
  /**
24
- * PublicKey parity getter.
29
+ * CompressedSecp256k1PublicKey parity getter.
25
30
  * @readonly @type {number} The 1 byte parity (0x02 if even, 0x03 if odd).
26
31
  */
27
32
  parity: number;
28
33
  /**
29
- * PublicKey x-coordinate getter.
34
+ * CompressedSecp256k1PublicKey isEven getter.
35
+ * @readonly @type {boolean} True if the public key is even, false if odd.
36
+ */
37
+ isEven: boolean;
38
+ /**
39
+ * CompressedSecp256k1PublicKey x-coordinate getter.
30
40
  * @readonly @type {KeyBytes} The 32 byte x-coordinate of the public key.
31
41
  */
32
42
  x: KeyBytes;
33
43
  /**
34
- * PublicKey y-coordinate getter.
44
+ * CompressedSecp256k1PublicKey y-coordinate getter.
35
45
  * @readonly @type {KeyBytes} The 32 byte y-coordinate of the public key.
36
46
  */
37
47
  y: KeyBytes;
38
48
  /**
39
- * PublicKey multibase getter.
49
+ * CompressedSecp256k1PublicKey multibase getter.
40
50
  * @readonly @returns {MultibaseObject} The public key as MultibaseObject as a address string, key and prefix bytes.
41
51
  */
42
52
  multibase: MultibaseObject;
43
53
  /**
44
- * PublicKey hex string getter.
54
+ * CompressedSecp256k1PublicKey hex string getter.
45
55
  * @readonly @type {Hex} The public key as a hex string.
46
56
  */
47
57
  hex: Hex;
58
+ /**
59
+ * CompressedSecp256k1PublicKey point getter.
60
+ * @readonly @type {Point} The public key as a point (x, y).
61
+ */
62
+ point: Point;
48
63
  /**
49
64
  * Decode the base58btc multibase string to the compressed public key prefixed with 0x02.
50
65
  * @returns {KeyBytes} The public key as a 33-byte compressed public key with header.
51
66
  */
52
67
  decode(): KeyBytes;
53
68
  /**
54
- * Encode the PublicKey as an x-only base58btc multibase public key.
69
+ * Encode the CompressedSecp256k1PublicKey as an x-only base58btc multibase public key.
55
70
  * @returns {string} The public key formatted a base58btc multibase string.
56
71
  */
57
72
  encode(): string;
58
73
  /**
59
- * PublicKey key equality check. Checks if `this` public key is equal to `other` public key.
60
- * @param {PublicKey} other The public key to compare.
74
+ * CompressedSecp256k1PublicKey key equality check. Checks if `this` public key is equal to `other` public key.
75
+ * @param {CompressedSecp256k1PublicKey} other The public key to compare.
61
76
  * @returns {boolean} True if the public keys are equal.
62
77
  */
63
- equals(other: PublicKey): boolean;
78
+ equals(other: CompressedSecp256k1PublicKey): boolean;
64
79
  /**
65
- * JSON representation of a PublicKey object.
66
- * @returns {PublicKeyObject} The PublicKey as a JSON object.
80
+ * JSON representation of a CompressedSecp256k1PublicKey object.
81
+ * @returns {PublicKeyObject} The CompressedSecp256k1PublicKey as a JSON object.
67
82
  */
68
83
  json(): PublicKeyObject;
69
84
  }
@@ -71,16 +86,16 @@ export interface IPublicKey {
71
86
  * Encapsulates a secp256k1 public key compliant to BIP-340 BIP schnorr signature scheme.
72
87
  * Provides get methods for different formats (compressed, x-only, multibase).
73
88
  * Provides helpers methods for comparison and serialization.
74
- * @class PublicKey
75
- * @type {PublicKey}
89
+ * @class CompressedSecp256k1PublicKey
90
+ * @type {CompressedSecp256k1PublicKey}
76
91
  */
77
- export declare class PublicKey implements PublicKey {
92
+ export declare class CompressedSecp256k1PublicKey implements PublicKey {
78
93
  /** @type {KeyBytes} The public key bytes */
79
94
  private readonly _bytes;
80
95
  /** @type {MultibaseObject} The public key as a MultibaseObject */
81
96
  private _multibase;
82
97
  /**
83
- * Creates a PublicKey instance.
98
+ * Creates a CompressedSecp256k1PublicKey instance.
84
99
  * @param {KeyBytes} bytes The public key byte array.
85
100
  * @throws {PublicKeyError} if the byte length is not 32 (x-only) or 33 (compressed)
86
101
  */
@@ -96,10 +111,20 @@ export declare class PublicKey implements PublicKey {
96
111
  */
97
112
  get uncompressed(): KeyBytes;
98
113
  /**
99
- * Get the parity byte of the public key.
100
- * @returns {number} The parity byte of the public key.
114
+ * X-only (32-byte) view of the public key per BIP-340.
115
+ */
116
+ get xOnly(): KeyBytes;
117
+ /**
118
+ * Parity of the SEC compressed public key.
119
+ * @returns {0x02 | 0x03} The parity byte (0x02 if even, 0x03 if odd).
120
+ * @throws {PublicKeyError} If the parity byte is not 0x02 or 0x03.
121
+ */
122
+ get parity(): 0x02 | 0x03;
123
+ /**
124
+ * Whether the SEC compressed public key has even Y.
125
+ * @returns {boolean} True if the public key has even Y.
101
126
  */
102
- get parity(): number;
127
+ get isEven(): boolean;
103
128
  /**
104
129
  * Get the x-coordinate of the public key.
105
130
  * @returns {Uint8Array} The 32-byte x-coordinate of the public key.
@@ -125,6 +150,11 @@ export declare class PublicKey implements PublicKey {
125
150
  * @returns {Point} The public key point.
126
151
  */
127
152
  get point(): Point;
153
+ /**
154
+ * Returns the BIP-340 (x-only) representation of this key.
155
+ * @returns {KeyBytes} The BIP-340 (x-only) representation of the public key.
156
+ */
157
+ bip340(): KeyBytes;
128
158
  /**
129
159
  * Returns the point of the public key.
130
160
  * @param {Hex} pk The public key in hex (Uint8Array or string) format.
@@ -144,27 +174,27 @@ export declare class PublicKey implements PublicKey {
144
174
  encode(): string;
145
175
  /**
146
176
  * Compares this public key to another public key.
147
- * @param {PublicKey} other The other public key to compare
177
+ * @param {CompressedSecp256k1PublicKey} other The other public key to compare
148
178
  * @returns {boolean} True if the public keys are equal, false otherwise.
149
179
  */
150
- equals(other: PublicKey): boolean;
180
+ equals(other: CompressedSecp256k1PublicKey): boolean;
151
181
  /**
152
- * JSON representation of a PublicKey object.
153
- * @returns {PublicKeyObject} The PublicKey as a JSON object.
182
+ * JSON representation of a CompressedSecp256k1PublicKey object.
183
+ * @returns {PublicKeyObject} The CompressedSecp256k1PublicKey as a JSON object.
154
184
  */
155
185
  json(): PublicKeyObject;
156
186
  /**
157
- * Creates a PublicKey object from a JSON representation.
158
- * @param {PublicKeyObject} json The JSON object to initialize the PublicKey.
159
- * @returns {PublicKey} The initialized PublicKey object.
187
+ * Creates a CompressedSecp256k1PublicKey object from a JSON representation.
188
+ * @param {PublicKeyObject} json The JSON object to initialize the CompressedSecp256k1PublicKey.
189
+ * @returns {CompressedSecp256k1PublicKey} The initialized CompressedSecp256k1PublicKey object.
160
190
  */
161
- static fromJSON(json: Maybe<PublicKeyObject>): PublicKey;
191
+ static fromJSON(json: Maybe<PublicKeyObject>): CompressedSecp256k1PublicKey;
162
192
  /**
163
- * Computes the deterministic public key for a given private key.
164
- * @param {PrivateKey | KeyBytes} sk The PrivateKey object or the private key bytes
165
- * @returns {PublicKey} A new PublicKey object
193
+ * Computes the deterministic public key for a given secret key.
194
+ * @param {Secp256k1SecretKey | KeyBytes} sk The Secp256k1SecretKey object or the secret key bytes
195
+ * @returns {CompressedSecp256k1PublicKey} A new CompressedSecp256k1PublicKey object
166
196
  */
167
- static fromSecretKey(sk: SecretKey | KeyBytes): PublicKey;
197
+ static fromSecretKey(sk: Secp256k1SecretKey | KeyBytes): CompressedSecp256k1PublicKey;
168
198
  /**
169
199
  * Computes modular exponentiation: (base^exp) % mod.
170
200
  * Used for computing modular square roots.
@@ -188,10 +218,4 @@ export declare class PublicKey implements PublicKey {
188
218
  * @returns {Uint8Array} 65-byte uncompressed public key (starts with `0x04`)
189
219
  */
190
220
  liftX(): Uint8Array;
191
- /**
192
- * Static version of liftX method.
193
- * @param {KeyBytes} x The 32-byte x-coordinate to lift.
194
- * @returns {Uint8Array} The 65-byte uncompressed public key (0x04, x, y).
195
- */
196
- static xOnly(x: KeyBytes): Uint8Array;
197
221
  }
@@ -1 +1 @@
1
- {"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,GAAG,EACH,QAAQ,EACR,KAAK,EACL,eAAe,EAEf,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,QAAQ,CAAC;IACZ,CAAC,EAAE,QAAQ,CAAC;CACb;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,YAAY,EAAE,QAAQ,CAAC;IAEvB;;;OAGG;IACH,UAAU,EAAE,QAAQ,CAAC;IAErB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,CAAC,EAAE,QAAQ,CAAC;IAEZ;;;OAGG;IACH,CAAC,EAAE,QAAQ,CAAC;IAEZ;;;OAGG;IACH,SAAS,EAAE,eAAe,CAAC;IAE3B;;;OAGG;IACH,GAAG,EAAE,GAAG,CAAC;IAET;;;OAGG;IACH,MAAM,IAAI,QAAQ,CAAC;IAEnB;;;OAGG;IACH,MAAM,IAAI,MAAM,CAAC;IAEjB;;;;OAIG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EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAU7D;;;;;;OAMG;IACI,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM;IAI5C;;;;OAIG;IACI,KAAK,IAAI,UAAU;CAwB3B"}
@@ -1,12 +1,12 @@
1
1
  import { Bytes, Entropy, Hex, KeyBytes, SecretKeyObject } from '@did-btcr2/common';
2
2
  import { SchnorrKeyPair } from './pair.js';
3
- import { PublicKey } from './public.js';
3
+ import { CompressedSecp256k1PublicKey } from './public.js';
4
4
  /**
5
- * Interface for the SecretKey class.
6
- * @interface ISecretKey
7
- * @type {ISecretKey}
5
+ * General SecretKey interface for the Secp256k1SecretKey class.
6
+ * @interface SecretKey
7
+ * @type {SecretKey}
8
8
  */
9
- export interface ISecretKey {
9
+ export interface SecretKey {
10
10
  /**
11
11
  * Get the secret key bytes.
12
12
  * @readonly @type {KeyBytes} The secret key bytes.
@@ -25,23 +25,23 @@ export interface ISecretKey {
25
25
  hex: Hex;
26
26
  /**
27
27
  * Checks if this secret key is equal to another secret key.
28
- *
28
+ * @param {Secp256k1SecretKey} other The other secret key to compare.
29
29
  * @returns {boolean} True if the private keys are equal.
30
30
  */
31
- equals(other: SecretKey): boolean;
31
+ equals(other: Secp256k1SecretKey): boolean;
32
32
  /**
33
33
  * Uses the secret key to compute the corresponding public key.
34
- * @returns {KeyBytes} A new PublicKey object.
34
+ * @returns {CompressedSecp256k1PublicKey} The computed public key bytes.
35
35
  */
36
- computePublicKey(): KeyBytes;
36
+ computePublicKey(): CompressedSecp256k1PublicKey;
37
37
  /**
38
38
  * Checks if the secret key is valid.
39
39
  * @returns {boolean} Whether the secret key is valid.
40
40
  */
41
41
  isValid(): boolean;
42
42
  /**
43
- * JSON representation of a SecretKey object.
44
- * @returns {SecretKeyObject} The SecretKey as a JSON object.
43
+ * JSON representation of a Secp256k1SecretKey object.
44
+ * @returns {SecretKeyObject} The Secp256k1SecretKey as a JSON object.
45
45
  */
46
46
  json(): SecretKeyObject;
47
47
  }
@@ -49,11 +49,11 @@ export interface ISecretKey {
49
49
  * Encapsulates a secp256k1 secret key
50
50
  * Provides get methods for different formats (raw, secret, point).
51
51
  * Provides helpers methods for comparison, serialization and publicKey generation.
52
- * @class SecretKey
53
- * @type {SecretKey}
54
- *
52
+ * @class Secp256k1SecretKey
53
+ * @type {Secp256k1SecretKey}
54
+ * @implements {SecretKey}
55
55
  */
56
- export declare class SecretKey implements ISecretKey {
56
+ export declare class Secp256k1SecretKey implements SecretKey {
57
57
  /** @type {KeyBytes} The entropy for the secret key as a byte array */
58
58
  private _bytes?;
59
59
  /** @type {bigint} The entropy for the secret key as a bigint */
@@ -61,7 +61,7 @@ export declare class SecretKey implements ISecretKey {
61
61
  /** @type {string} The secret key as a secretKeyMultibase */
62
62
  private _multibase;
63
63
  /**
64
- * Instantiates an instance of SecretKey.
64
+ * Instantiates an instance of Secp256k1SecretKey.
65
65
  * @param {Entropy} entropy bytes (Uint8Array) or secret (bigint)
66
66
  * @throws {SecretKeyError} If entropy is not provided, not a valid 32-byte secret key or not a valid bigint seed
67
67
  */
@@ -93,15 +93,15 @@ export declare class SecretKey implements ISecretKey {
93
93
  encode(): string;
94
94
  /**
95
95
  * Checks if this secret key is equal to another.
96
- * @param {SecretKey} other The other secret key
96
+ * @param {Secp256k1SecretKey} other The other secret key
97
97
  * @returns {boolean} True if the private keys are equal, false otherwise
98
98
  */
99
- equals(other: SecretKey): boolean;
99
+ equals(other: Secp256k1SecretKey): boolean;
100
100
  /**
101
101
  * Computes the public key from the secret key bytes.
102
- * @returns {KeyBytes} The computed public key
102
+ * @returns {CompressedSecp256k1PublicKey} The computed public key
103
103
  */
104
- computePublicKey(): KeyBytes;
104
+ computePublicKey(): CompressedSecp256k1PublicKey;
105
105
  /**
106
106
  * Converts the secret key to a JSON object.
107
107
  * @returns {SecretKeyObject} The secret key as a JSON object
@@ -114,10 +114,9 @@ export declare class SecretKey implements ISecretKey {
114
114
  isValid(): boolean;
115
115
  /**
116
116
  * Checks if the public key is a valid secp256k1 point.
117
- * @param {PublicKey} pk The public key to validate
118
117
  * @returns {boolean} True if the public key is valid, false otherwise
119
118
  */
120
- isValidPair(pk: PublicKey): boolean;
119
+ hasValidPublicKey(): boolean;
121
120
  /**
122
121
  * Decodes the multibase string to the 34-byte secret key (2 byte prefix + 32 byte key).
123
122
  * @param {string} multibase The multibase string to decode
@@ -125,14 +124,14 @@ export declare class SecretKey implements ISecretKey {
125
124
  */
126
125
  static decode(multibase: string): Bytes;
127
126
  /**
128
- * Creates a SecretKey object from a JSON object.
127
+ * Creates a Secp256k1SecretKey object from a JSON object.
129
128
  * @param {SecretKeyObject} json The JSON object containing the secret key bytes
130
- * @returns {SecretKey} A new SecretKey object
129
+ * @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
131
130
  */
132
- static fromJSON(json: SecretKeyObject): SecretKey;
131
+ static fromJSON(json: SecretKeyObject): Secp256k1SecretKey;
133
132
  /**
134
- * Converts a SecretKey or KeyBytes to a Pair.
135
- * @param {KeyBytes} bytes
133
+ * Converts a Secp256k1SecretKey or KeyBytes to a SchnorrKeyPair.
134
+ * @param {KeyBytes} bytes The secret key bytes
136
135
  * @returns {SchnorrKeyPair} The SchnorrKeyPair object containing the public and private keys
137
136
  * @throws {SecretKeyError} If the secret key is not valid
138
137
  */
@@ -150,25 +149,25 @@ export declare class SecretKey implements ISecretKey {
150
149
  */
151
150
  static toBytes(secret: bigint): KeyBytes;
152
151
  /**
153
- * Creates a new SecretKey object from a bigint secret.
154
- * @param {bigint} secret The secret bigint
155
- * @returns {SecretKey} A new SecretKey object
152
+ * Creates a new Secp256k1SecretKey object from a bigint secret.
153
+ * @param {bigint} entropy The secret bigint
154
+ * @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
156
155
  */
157
- static fromSecret(secret: bigint): SecretKey;
156
+ static fromEntropy(entropy: bigint): Secp256k1SecretKey;
158
157
  /**
159
158
  * Generates random secret key bytes.
160
159
  * @returns {KeyBytes} Uint8Array of 32 random bytes.
161
160
  */
162
161
  static random(): KeyBytes;
163
162
  /**
164
- * Creates a new SecretKey from random secret key bytes.
165
- * @returns {SecretKey} A new SecretKey object
163
+ * Creates a new Secp256k1SecretKey from random secret key bytes.
164
+ * @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
166
165
  */
167
- static generate(): SecretKey;
166
+ static generate(): Secp256k1SecretKey;
168
167
  /**
169
168
  * Generates a public key from the given secret key bytes.
170
169
  * @param {KeyBytes} bytes The secret key bytes
171
- * @returns {KeyBytes} The computed public key bytes
170
+ * @returns {CompressedSecp256k1PublicKey} The computed public key bytes
172
171
  */
173
- static getPublicKey(bytes: KeyBytes): KeyBytes;
172
+ static getPublicKey(bytes: KeyBytes): CompressedSecp256k1PublicKey;
174
173
  }
@@ -1 +1 @@
1
- {"version":3,"file":"secret.d.ts","sourceRoot":"","sources":["../../src/secret.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,EAEL,OAAO,EACP,GAAG,EACH,QAAQ,EAER,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,KAAK,EAAE,QAAQ,CAAC;IAEhB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,GAAG,EAAE,GAAG,CAAC;IAET;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC;IAElC;;;OAGG;IACH,gBAAgB,IAAI,QAAQ,CAAC;IAE7B;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC;IAGnB;;;OAGG;IACH,IAAI,IAAI,eAAe,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,qBAAa,SAAU,YAAW,UAAU;IAC1C,sEAAsE;IACtE,OAAO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AAI,eAAe;IAQ9B;;;OAGG;IACI,OAAO,IAAI,OAAO;IAIzB;;;OAGG;IACI,iBAAiB,IAAI,OAAO;IAanC;;;;OAIG;WACW,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK;IA8B9C;;;;OAIG;WACW,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,kBAAkB;IAIjE;;;;;OAKG;WACW,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,cAAc;IAWxD;;;;OAIG;WACW,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM;IAI/C;;;;OAIG;WACW,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ;IAiB/C;;;;OAIG;WACW,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB;IAS9D;;;OAGG;WACW,MAAM,IAAI,QAAQ;IAShC;;;OAGG;WACW,QAAQ,IAAI,kBAAkB;IAQ5C;;;;OAIG;WACW,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,4BAA4B;CAI1E"}
@@ -0,0 +1,16 @@
1
+ import { KeyBytes } from '@did-btcr2/common';
2
+ import { CompressedSecp256k1PublicKey } from './public.js';
3
+ import { Secp256k1SecretKey } from './secret.js';
4
+ export type RawSchnorrKeyPair = {
5
+ public: KeyBytes;
6
+ secret?: KeyBytes;
7
+ };
8
+ /** Params for the {@link SchnorrKeyPair} constructor */
9
+ export interface SchnorrKeyPairParams {
10
+ secretKey?: Secp256k1SecretKey | KeyBytes;
11
+ publicKey?: CompressedSecp256k1PublicKey | KeyBytes;
12
+ }
13
+ export interface MultibaseKeys {
14
+ publicKeyMultibase: string;
15
+ secretKeyMultibase: string;
16
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,QAAQ,CAAC;IACjB,MAAM,CAAC,EAAE,QAAQ,CAAA;CAClB,CAAA;AAED,wDAAwD;AACxD,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,kBAAkB,GAAG,QAAQ,CAAC;IAC1C,SAAS,CAAC,EAAE,4BAA4B,GAAG,QAAQ,CAAC;CACrD;AAED,MAAM,WAAW,aAAa;IAC5B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAA;CAC3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@did-btcr2/keypair",
3
- "version": "0.5.1",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "description": "JavaScript/TypeScript implementation of secp256k1 public/private key pairs with BIP340 schnorr signatures. Used by various parts of the did-btcr2-js monorepo.",
6
6
  "main": "./dist/cjs/index.js",
@@ -62,7 +62,7 @@
62
62
  "@noble/hashes": "^1.7.1",
63
63
  "multiformats": "^13.3.2",
64
64
  "tiny-secp256k1": "^2.2.3",
65
- "@did-btcr2/common": "2.0.0"
65
+ "@did-btcr2/common": "2.2.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@eslint/js": "^9.20.0",
@@ -104,8 +104,7 @@
104
104
  "build:esm": "rimraf dist/esm dist/types && pnpm tsc -p tsconfig.json",
105
105
  "build:cjs": "rimraf dist/cjs && tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json",
106
106
  "build:tests": "pnpm tsc -p tests/tsconfig.json",
107
- "build:docs": "typedoc --options typedoc.json",
108
- "build:all": "pnpm build && pnpm build:tests && pnpm build:docs",
107
+ "build:all": "pnpm build && pnpm build:tests",
109
108
  "release": "pnpm build && pnpm pack && mv *.tgz ../../release/key-pair",
110
109
  "lint": "eslint . --max-warnings 0",
111
110
  "lint:fix": "eslint . --fix",
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './pair.js';
2
2
  export * from './secret.js';
3
- export * from './public.js';
3
+ export * from './public.js';
4
+ export * from './types.js';