@did-btcr2/method 0.15.0 → 0.16.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/dist/browser.js +228 -206
- package/dist/browser.mjs +228 -206
- package/dist/cjs/core/beacon/aggregation/protocol/nostr.js +4 -4
- package/dist/cjs/core/beacon/aggregation/protocol/nostr.js.map +1 -1
- package/dist/cjs/core/beacon/cid-aggregate.js +2 -2
- package/dist/cjs/core/beacon/singleton.js +2 -2
- package/dist/cjs/core/beacon/singleton.js.map +1 -1
- package/dist/cjs/core/crud/create.js +4 -4
- package/dist/cjs/core/crud/create.js.map +1 -1
- package/dist/cjs/core/crud/deactivate.js +4 -4
- package/dist/cjs/core/crud/deactivate.js.map +1 -1
- package/dist/cjs/core/crud/read.js +20 -20
- package/dist/cjs/core/crud/read.js.map +1 -1
- package/dist/cjs/core/crud/update.js +2 -2
- package/dist/cjs/core/crud/update.js.map +1 -1
- package/dist/cjs/core/key-manager/index.js +5 -5
- package/dist/cjs/core/key-manager/index.js.map +1 -1
- package/dist/cjs/did-btcr2.js +1 -1
- package/dist/cjs/utils/appendix.js +4 -4
- package/dist/cjs/utils/appendix.js.map +1 -1
- package/dist/cjs/utils/did-document-builder.js +1 -1
- package/dist/cjs/utils/did-document-builder.js.map +1 -1
- package/dist/cjs/utils/did-document.js +2 -2
- package/dist/cjs/utils/did-document.js.map +1 -1
- package/dist/cjs/utils/identifier.js +5 -5
- package/dist/cjs/utils/identifier.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/protocol/nostr.js +4 -4
- package/dist/esm/core/beacon/aggregation/protocol/nostr.js.map +1 -1
- package/dist/esm/core/beacon/cid-aggregate.js +2 -2
- package/dist/esm/core/beacon/singleton.js +2 -2
- package/dist/esm/core/beacon/singleton.js.map +1 -1
- package/dist/esm/core/crud/create.js +4 -4
- package/dist/esm/core/crud/create.js.map +1 -1
- package/dist/esm/core/crud/deactivate.js +4 -4
- package/dist/esm/core/crud/deactivate.js.map +1 -1
- package/dist/esm/core/crud/read.js +20 -20
- package/dist/esm/core/crud/read.js.map +1 -1
- package/dist/esm/core/crud/update.js +2 -2
- package/dist/esm/core/crud/update.js.map +1 -1
- package/dist/esm/core/key-manager/index.js +5 -5
- package/dist/esm/core/key-manager/index.js.map +1 -1
- package/dist/esm/did-btcr2.js +1 -1
- package/dist/esm/utils/appendix.js +4 -4
- package/dist/esm/utils/appendix.js.map +1 -1
- package/dist/esm/utils/did-document-builder.js +1 -1
- package/dist/esm/utils/did-document-builder.js.map +1 -1
- package/dist/esm/utils/did-document.js +2 -2
- package/dist/esm/utils/did-document.js.map +1 -1
- package/dist/esm/utils/identifier.js +5 -5
- package/dist/esm/utils/identifier.js.map +1 -1
- package/dist/types/core/beacon/aggregation/protocol/nostr.d.ts +1 -1
- package/dist/types/core/beacon/cid-aggregate.d.ts +2 -2
- package/dist/types/core/crud/deactivate.d.ts +4 -4
- package/dist/types/core/crud/deactivate.d.ts.map +1 -1
- package/dist/types/core/crud/read.d.ts +4 -4
- package/dist/types/core/crud/read.d.ts.map +1 -1
- package/dist/types/core/key-manager/index.d.ts +6 -6
- package/dist/types/core/key-manager/index.d.ts.map +1 -1
- package/dist/types/core/key-manager/interface.d.ts +3 -3
- package/dist/types/core/key-manager/interface.d.ts.map +1 -1
- package/dist/types/did-btcr2.d.ts +1 -1
- package/dist/types/interfaces/crud.d.ts +1 -4
- package/dist/types/interfaces/crud.d.ts.map +1 -1
- package/dist/types/types/crud.d.ts +5 -5
- package/dist/types/types/crud.d.ts.map +1 -1
- package/dist/types/utils/appendix.d.ts +7 -7
- package/dist/types/utils/appendix.d.ts.map +1 -1
- package/dist/types/utils/did-document-builder.d.ts +1 -1
- package/dist/types/utils/did-document-builder.d.ts.map +1 -1
- package/dist/types/utils/did-document.d.ts +1 -1
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/dist/types/utils/identifier.d.ts +2 -2
- package/dist/types/utils/identifier.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/core/beacon/aggregation/protocol/nostr.ts +4 -4
- package/src/core/beacon/cid-aggregate.ts +2 -2
- package/src/core/beacon/singleton.ts +2 -2
- package/src/core/crud/create.ts +4 -4
- package/src/core/crud/deactivate.ts +4 -4
- package/src/core/crud/read.ts +21 -21
- package/src/core/crud/update.ts +2 -2
- package/src/core/key-manager/index.ts +7 -7
- package/src/core/key-manager/interface.ts +3 -3
- package/src/did-btcr2.ts +1 -1
- package/src/interfaces/crud.ts +1 -4
- package/src/types/crud.ts +5 -5
- package/src/utils/appendix.ts +9 -9
- package/src/utils/did-document-builder.ts +1 -1
- package/src/utils/did-document.ts +2 -2
- package/src/utils/identifier.ts +5 -5
package/dist/browser.mjs
CHANGED
|
@@ -7359,7 +7359,7 @@ var require_dist2 = __commonJS({
|
|
|
7359
7359
|
return false;
|
|
7360
7360
|
}
|
|
7361
7361
|
}
|
|
7362
|
-
function
|
|
7362
|
+
function isPoint4(p3) {
|
|
7363
7363
|
return _isPoint(p3, false);
|
|
7364
7364
|
}
|
|
7365
7365
|
function isPointCompressed(p3) {
|
|
@@ -7386,7 +7386,7 @@ var require_dist2 = __commonJS({
|
|
|
7386
7386
|
});
|
|
7387
7387
|
}
|
|
7388
7388
|
function xOnlyPointFromPoint(p3) {
|
|
7389
|
-
if (!
|
|
7389
|
+
if (!isPoint4(p3)) {
|
|
7390
7390
|
throw new Error(THROW_BAD_POINT);
|
|
7391
7391
|
}
|
|
7392
7392
|
return p3.slice(1, 33);
|
|
@@ -7406,13 +7406,13 @@ var require_dist2 = __commonJS({
|
|
|
7406
7406
|
return xOnlyPointFromPoint(pointFromScalar2(d2));
|
|
7407
7407
|
}
|
|
7408
7408
|
function pointCompress(p3, compressed) {
|
|
7409
|
-
if (!
|
|
7409
|
+
if (!isPoint4(p3)) {
|
|
7410
7410
|
throw new Error(THROW_BAD_POINT);
|
|
7411
7411
|
}
|
|
7412
7412
|
return fromHex2(p3).toRawBytes(assumeCompression(compressed, p3));
|
|
7413
7413
|
}
|
|
7414
7414
|
function pointMultiply(a3, tweak, compressed) {
|
|
7415
|
-
if (!
|
|
7415
|
+
if (!isPoint4(a3)) {
|
|
7416
7416
|
throw new Error(THROW_BAD_POINT);
|
|
7417
7417
|
}
|
|
7418
7418
|
if (!isTweak(tweak)) {
|
|
@@ -7423,7 +7423,7 @@ var require_dist2 = __commonJS({
|
|
|
7423
7423
|
);
|
|
7424
7424
|
}
|
|
7425
7425
|
function pointAdd2(a3, b2, compressed) {
|
|
7426
|
-
if (!
|
|
7426
|
+
if (!isPoint4(a3) || !isPoint4(b2)) {
|
|
7427
7427
|
throw new Error(THROW_BAD_POINT);
|
|
7428
7428
|
}
|
|
7429
7429
|
return throwToNull(() => {
|
|
@@ -7437,7 +7437,7 @@ var require_dist2 = __commonJS({
|
|
|
7437
7437
|
});
|
|
7438
7438
|
}
|
|
7439
7439
|
function pointAddScalar(p3, tweak, compressed) {
|
|
7440
|
-
if (!
|
|
7440
|
+
if (!isPoint4(p3)) {
|
|
7441
7441
|
throw new Error(THROW_BAD_POINT);
|
|
7442
7442
|
}
|
|
7443
7443
|
if (!isTweak(tweak)) {
|
|
@@ -7531,7 +7531,7 @@ var require_dist2 = __commonJS({
|
|
|
7531
7531
|
return Q.toRawBytes(assumeCompression(compressed));
|
|
7532
7532
|
}
|
|
7533
7533
|
function verify(h2, Q, signature2, strict) {
|
|
7534
|
-
if (!
|
|
7534
|
+
if (!isPoint4(Q)) {
|
|
7535
7535
|
throw new Error(THROW_BAD_POINT);
|
|
7536
7536
|
}
|
|
7537
7537
|
if (!isSignature(signature2)) {
|
|
@@ -7554,7 +7554,7 @@ var require_dist2 = __commonJS({
|
|
|
7554
7554
|
}
|
|
7555
7555
|
return secp256k13.schnorr.verify(signature2, h2, Q);
|
|
7556
7556
|
}
|
|
7557
|
-
exports.isPoint =
|
|
7557
|
+
exports.isPoint = isPoint4;
|
|
7558
7558
|
exports.isPointCompressed = isPointCompressed;
|
|
7559
7559
|
exports.isPrivate = isPrivate3;
|
|
7560
7560
|
exports.isXOnlyPoint = isXOnlyPoint;
|
|
@@ -30635,7 +30635,7 @@ var require_eddsa = __commonJS({
|
|
|
30635
30635
|
EDDSA.prototype.decodeInt = function decodeInt(bytes3) {
|
|
30636
30636
|
return utils3.intFromLE(bytes3);
|
|
30637
30637
|
};
|
|
30638
|
-
EDDSA.prototype.isPoint = function
|
|
30638
|
+
EDDSA.prototype.isPoint = function isPoint4(val) {
|
|
30639
30639
|
return val instanceof this.pointClass;
|
|
30640
30640
|
};
|
|
30641
30641
|
}
|
|
@@ -32247,13 +32247,13 @@ var require_asn12 = __commonJS({
|
|
|
32247
32247
|
).optional()
|
|
32248
32248
|
);
|
|
32249
32249
|
});
|
|
32250
|
-
var
|
|
32250
|
+
var PublicKey3 = asn1.define("SubjectPublicKeyInfo", function() {
|
|
32251
32251
|
this.seq().obj(
|
|
32252
32252
|
this.key("algorithm").use(AlgorithmIdentifier2),
|
|
32253
32253
|
this.key("subjectPublicKey").bitstr()
|
|
32254
32254
|
);
|
|
32255
32255
|
});
|
|
32256
|
-
exports.PublicKey =
|
|
32256
|
+
exports.PublicKey = PublicKey3;
|
|
32257
32257
|
var PrivateKeyInfo2 = asn1.define("PrivateKeyInfo", function() {
|
|
32258
32258
|
this.seq().obj(
|
|
32259
32259
|
this.key("version")["int"](),
|
|
@@ -48429,8 +48429,8 @@ var CIDAggregateBeacon = class _CIDAggregateBeacon extends Beacon {
|
|
|
48429
48429
|
*
|
|
48430
48430
|
* The Broadcast CIDAggregate Beacon Signal algorithm involving two roles: a set of cohort participants and a Beacon
|
|
48431
48431
|
* coordinator. The Beacon coordinator collects individual DID Update Payload Content Identifiers (CIDs) for specific
|
|
48432
|
-
* did:
|
|
48433
|
-
* (CAS). The CID for the DID Update Bundle is included in a Partially Signed Bitcoin Transaction (PSBT) transaction
|
|
48432
|
+
* did:btcr2 idntifiers and aggregates them into a DID Update Bundle, which is then published to a Content Addressable
|
|
48433
|
+
* Storage (CAS). The CID for the DID Update Bundle is included in a Partially Signed Bitcoin Transaction (PSBT) transaction
|
|
48434
48434
|
* output spent from the Beacon’s n-of-n address. Each of the n cohort participants in the Beacon MUST sign the
|
|
48435
48435
|
* transaction before it can be broadcast to the network. It is RECOMMENDED that cohort participants keep a copy of
|
|
48436
48436
|
* the DID Update Bundle and separately pin it to the CAS.
|
|
@@ -57621,7 +57621,7 @@ function getNetwork(network) {
|
|
|
57621
57621
|
// ../bitcoin/dist/esm/bitcoin.js
|
|
57622
57622
|
var BitcoinNetworkConnection = class {
|
|
57623
57623
|
network;
|
|
57624
|
-
|
|
57624
|
+
bitcoin;
|
|
57625
57625
|
testnet3;
|
|
57626
57626
|
testnet4;
|
|
57627
57627
|
signet;
|
|
@@ -57642,7 +57642,7 @@ var BitcoinNetworkConnection = class {
|
|
|
57642
57642
|
throw new MethodError("Parsing failed: malformed BITCOIN_NETWORK_CONFIG", "MISSING_MALFORMED_BITCOIN_NETWORK_CONFIG", { BITCOIN_NETWORK_CONFIG });
|
|
57643
57643
|
}
|
|
57644
57644
|
const networkConfigs = JSON.parse(BITCOIN_NETWORK_CONFIG);
|
|
57645
|
-
const networks2 = ["
|
|
57645
|
+
const networks2 = ["bitcoin", "testnet3", "testnet4", "signet", "mutinynet", "regtest"];
|
|
57646
57646
|
for (const network of networks2) {
|
|
57647
57647
|
const networkConfig = configs?.[network] ?? networkConfigs[network];
|
|
57648
57648
|
if (networkConfig) {
|
|
@@ -57666,7 +57666,7 @@ var BitcoinNetworkConnection = class {
|
|
|
57666
57666
|
}
|
|
57667
57667
|
/**
|
|
57668
57668
|
* Get the Bitcoin network configuration for a specific network.
|
|
57669
|
-
* @param {keyof AvailableNetworks} network - The Bitcoin network (e.g., '
|
|
57669
|
+
* @param {keyof AvailableNetworks} network - The Bitcoin network (e.g., 'bitcoin', 'testnet3', 'signet', 'regtest').
|
|
57670
57670
|
* @returns {Bitcoin} The Bitcoin object.
|
|
57671
57671
|
*/
|
|
57672
57672
|
getNetworkConnection(network) {
|
|
@@ -57678,7 +57678,7 @@ var BitcoinNetworkConnection = class {
|
|
|
57678
57678
|
}
|
|
57679
57679
|
/**
|
|
57680
57680
|
* Sets the active Bitcoin network.
|
|
57681
|
-
* @param {keyof AvailableNetworks} active - The Bitcoin network to set as active (e.g., '
|
|
57681
|
+
* @param {keyof AvailableNetworks} active - The Bitcoin network to set as active (e.g., 'bitcoin', 'testnet3', 'signet', 'regtest').
|
|
57682
57682
|
* @throws {MethodError} If no configuration is found for the specified network.
|
|
57683
57683
|
*/
|
|
57684
57684
|
setActiveNetwork(active) {
|
|
@@ -57712,7 +57712,7 @@ init_shim();
|
|
|
57712
57712
|
|
|
57713
57713
|
// ../bitcoin/dist/esm/taproot.js
|
|
57714
57714
|
init_shim();
|
|
57715
|
-
var
|
|
57715
|
+
var tinysecp3 = __toESM(require_dist2(), 1);
|
|
57716
57716
|
|
|
57717
57717
|
// ../keypair/dist/esm/index.js
|
|
57718
57718
|
init_shim();
|
|
@@ -57722,12 +57722,13 @@ init_shim();
|
|
|
57722
57722
|
|
|
57723
57723
|
// ../keypair/dist/esm/public.js
|
|
57724
57724
|
init_shim();
|
|
57725
|
+
var tinysecp2 = __toESM(require_dist2(), 1);
|
|
57725
57726
|
|
|
57726
57727
|
// ../keypair/dist/esm/secret.js
|
|
57727
57728
|
init_shim();
|
|
57728
57729
|
var import_crypto3 = __toESM(require_crypto_browserify(), 1);
|
|
57729
57730
|
var tinysecp = __toESM(require_dist2(), 1);
|
|
57730
|
-
var
|
|
57731
|
+
var Secp256k1SecretKey = class _Secp256k1SecretKey {
|
|
57731
57732
|
/** @type {KeyBytes} The entropy for the secret key as a byte array */
|
|
57732
57733
|
_bytes;
|
|
57733
57734
|
/** @type {bigint} The entropy for the secret key as a bigint */
|
|
@@ -57735,7 +57736,7 @@ var SecretKey = class _SecretKey {
|
|
|
57735
57736
|
/** @type {string} The secret key as a secretKeyMultibase */
|
|
57736
57737
|
_multibase;
|
|
57737
57738
|
/**
|
|
57738
|
-
* Instantiates an instance of
|
|
57739
|
+
* Instantiates an instance of Secp256k1SecretKey.
|
|
57739
57740
|
* @param {Entropy} entropy bytes (Uint8Array) or secret (bigint)
|
|
57740
57741
|
* @throws {SecretKeyError} If entropy is not provided, not a valid 32-byte secret key or not a valid bigint seed
|
|
57741
57742
|
*/
|
|
@@ -57747,10 +57748,10 @@ var SecretKey = class _SecretKey {
|
|
|
57747
57748
|
}
|
|
57748
57749
|
if (isBytes9 && entropy.length === 32) {
|
|
57749
57750
|
this._bytes = entropy;
|
|
57750
|
-
this._seed =
|
|
57751
|
+
this._seed = _Secp256k1SecretKey.toSecret(entropy);
|
|
57751
57752
|
}
|
|
57752
57753
|
if (isSecret && !(entropy < 1n || entropy >= CURVE.n)) {
|
|
57753
|
-
this._bytes =
|
|
57754
|
+
this._bytes = _Secp256k1SecretKey.toBytes(entropy);
|
|
57754
57755
|
this._seed = entropy;
|
|
57755
57756
|
}
|
|
57756
57757
|
if (!this._bytes || this._bytes.length !== 32) {
|
|
@@ -57807,7 +57808,7 @@ var SecretKey = class _SecretKey {
|
|
|
57807
57808
|
}
|
|
57808
57809
|
/**
|
|
57809
57810
|
* Checks if this secret key is equal to another.
|
|
57810
|
-
* @param {
|
|
57811
|
+
* @param {Secp256k1SecretKey} other The other secret key
|
|
57811
57812
|
* @returns {boolean} True if the private keys are equal, false otherwise
|
|
57812
57813
|
*/
|
|
57813
57814
|
equals(other) {
|
|
@@ -57847,14 +57848,15 @@ var SecretKey = class _SecretKey {
|
|
|
57847
57848
|
}
|
|
57848
57849
|
/**
|
|
57849
57850
|
* Checks if the public key is a valid secp256k1 point.
|
|
57850
|
-
* @param {
|
|
57851
|
+
* @param {CompressedSecp256k1PublicKey} pk The public key to validate
|
|
57851
57852
|
* @returns {boolean} True if the public key is valid, false otherwise
|
|
57852
57853
|
*/
|
|
57853
|
-
|
|
57854
|
+
hasValidPublicKey(pk) {
|
|
57854
57855
|
if (!tinysecp.isPoint(pk.compressed)) {
|
|
57855
57856
|
return false;
|
|
57856
57857
|
}
|
|
57857
|
-
|
|
57858
|
+
const computed = new CompressedSecp256k1PublicKey(this.computePublicKey());
|
|
57859
|
+
return computed.equals(pk);
|
|
57858
57860
|
}
|
|
57859
57861
|
/**
|
|
57860
57862
|
* Decodes the multibase string to the 34-byte secret key (2 byte prefix + 32 byte key).
|
|
@@ -57874,21 +57876,21 @@ var SecretKey = class _SecretKey {
|
|
|
57874
57876
|
return decoded;
|
|
57875
57877
|
}
|
|
57876
57878
|
/**
|
|
57877
|
-
* Creates a
|
|
57879
|
+
* Creates a Secp256k1SecretKey object from a JSON object.
|
|
57878
57880
|
* @param {SecretKeyObject} json The JSON object containing the secret key bytes
|
|
57879
|
-
* @returns {
|
|
57881
|
+
* @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
|
|
57880
57882
|
*/
|
|
57881
57883
|
static fromJSON(json) {
|
|
57882
|
-
return new
|
|
57884
|
+
return new _Secp256k1SecretKey(new Uint8Array(json.bytes));
|
|
57883
57885
|
}
|
|
57884
57886
|
/**
|
|
57885
|
-
* Converts a
|
|
57886
|
-
* @param {KeyBytes} bytes
|
|
57887
|
+
* Converts a Secp256k1SecretKey or KeyBytes to a SchnorrKeyPair.
|
|
57888
|
+
* @param {KeyBytes} bytes The secret key bytes
|
|
57887
57889
|
* @returns {SchnorrKeyPair} The SchnorrKeyPair object containing the public and private keys
|
|
57888
57890
|
* @throws {SecretKeyError} If the secret key is not valid
|
|
57889
57891
|
*/
|
|
57890
57892
|
static toKeyPair(bytes3) {
|
|
57891
|
-
const secretKey = new
|
|
57893
|
+
const secretKey = new _Secp256k1SecretKey(bytes3);
|
|
57892
57894
|
const publicKey2 = secretKey.computePublicKey();
|
|
57893
57895
|
return new SchnorrKeyPair({ publicKey: publicKey2, secretKey });
|
|
57894
57896
|
}
|
|
@@ -57913,14 +57915,14 @@ var SecretKey = class _SecretKey {
|
|
|
57913
57915
|
return new Uint8Array(bytes3);
|
|
57914
57916
|
}
|
|
57915
57917
|
/**
|
|
57916
|
-
* Creates a new
|
|
57917
|
-
* @param {bigint}
|
|
57918
|
-
* @returns {
|
|
57918
|
+
* Creates a new Secp256k1SecretKey object from a bigint secret.
|
|
57919
|
+
* @param {bigint} entropy The secret bigint
|
|
57920
|
+
* @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
|
|
57919
57921
|
*/
|
|
57920
|
-
static
|
|
57921
|
-
const hexsecret =
|
|
57922
|
+
static fromEntropy(entropy) {
|
|
57923
|
+
const hexsecret = entropy.toString(16).padStart(64, "0");
|
|
57922
57924
|
const privateKeyBytes = new Uint8Array(hexsecret.match(/.{2}/g).map((byte) => parseInt(byte, 16)));
|
|
57923
|
-
return new
|
|
57925
|
+
return new _Secp256k1SecretKey(privateKeyBytes);
|
|
57924
57926
|
}
|
|
57925
57927
|
/**
|
|
57926
57928
|
* Generates random secret key bytes.
|
|
@@ -57931,12 +57933,12 @@ var SecretKey = class _SecretKey {
|
|
|
57931
57933
|
return (0, import_crypto3.getRandomValues)(byteArray);
|
|
57932
57934
|
}
|
|
57933
57935
|
/**
|
|
57934
|
-
* Creates a new
|
|
57935
|
-
* @returns {
|
|
57936
|
+
* Creates a new Secp256k1SecretKey from random secret key bytes.
|
|
57937
|
+
* @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
|
|
57936
57938
|
*/
|
|
57937
57939
|
static generate() {
|
|
57938
57940
|
const randomBytes7 = this.random();
|
|
57939
|
-
return new
|
|
57941
|
+
return new _Secp256k1SecretKey(randomBytes7);
|
|
57940
57942
|
}
|
|
57941
57943
|
/**
|
|
57942
57944
|
* Generates a public key from the given secret key bytes.
|
|
@@ -57944,22 +57946,22 @@ var SecretKey = class _SecretKey {
|
|
|
57944
57946
|
* @returns {KeyBytes} The computed public key bytes
|
|
57945
57947
|
*/
|
|
57946
57948
|
static getPublicKey(bytes3) {
|
|
57947
|
-
return new
|
|
57949
|
+
return new _Secp256k1SecretKey(bytes3).computePublicKey();
|
|
57948
57950
|
}
|
|
57949
57951
|
};
|
|
57950
57952
|
|
|
57951
57953
|
// ../keypair/dist/esm/public.js
|
|
57952
|
-
var
|
|
57954
|
+
var CompressedSecp256k1PublicKey = class _CompressedSecp256k1PublicKey {
|
|
57953
57955
|
/** @type {KeyBytes} The public key bytes */
|
|
57954
57956
|
_bytes;
|
|
57955
57957
|
/** @type {MultibaseObject} The public key as a MultibaseObject */
|
|
57956
57958
|
_multibase = {
|
|
57957
57959
|
prefix: BIP340_PUBLIC_KEY_MULTIBASE_PREFIX,
|
|
57958
57960
|
key: [],
|
|
57959
|
-
|
|
57961
|
+
encoded: ""
|
|
57960
57962
|
};
|
|
57961
57963
|
/**
|
|
57962
|
-
* Creates a
|
|
57964
|
+
* Creates a CompressedSecp256k1PublicKey instance.
|
|
57963
57965
|
* @param {KeyBytes} bytes The public key byte array.
|
|
57964
57966
|
* @throws {PublicKeyError} if the byte length is not 32 (x-only) or 33 (compressed)
|
|
57965
57967
|
*/
|
|
@@ -57967,8 +57969,11 @@ var PublicKey = class _PublicKey {
|
|
|
57967
57969
|
if (bytes3.length !== 33) {
|
|
57968
57970
|
throw new PublicKeyError("Invalid argument: byte length must be 33 (compressed)", "CONSTRUCTOR_ERROR", { bytes: bytes3 });
|
|
57969
57971
|
}
|
|
57972
|
+
if (!tinysecp2.isPoint(bytes3)) {
|
|
57973
|
+
throw new PublicKeyError("Invalid argument: bytes are not a valid secp256k1 compressed point", "CONSTRUCTOR_ERROR", { bytes: bytes3 });
|
|
57974
|
+
}
|
|
57970
57975
|
this._bytes = bytes3;
|
|
57971
|
-
this._multibase.
|
|
57976
|
+
this._multibase.encoded = this.encode();
|
|
57972
57977
|
this._multibase.key = [...this._multibase.prefix, ...this.compressed];
|
|
57973
57978
|
}
|
|
57974
57979
|
/**
|
|
@@ -57988,12 +57993,24 @@ var PublicKey = class _PublicKey {
|
|
|
57988
57993
|
return uncompressed;
|
|
57989
57994
|
}
|
|
57990
57995
|
/**
|
|
57991
|
-
*
|
|
57992
|
-
|
|
57996
|
+
* X-only (32-byte) view of the public key per BIP-340.
|
|
57997
|
+
*/
|
|
57998
|
+
get xOnly() {
|
|
57999
|
+
return this._bytes.slice(1);
|
|
58000
|
+
}
|
|
58001
|
+
/**
|
|
58002
|
+
* Parity of the SEC compressed public key.
|
|
58003
|
+
* @returns {0 | 1} The parity of the public key. 0 = even (0x02), 1 = odd (0x03).
|
|
57993
58004
|
*/
|
|
57994
58005
|
get parity() {
|
|
57995
|
-
|
|
57996
|
-
|
|
58006
|
+
return this._bytes[0] & 1;
|
|
58007
|
+
}
|
|
58008
|
+
/**
|
|
58009
|
+
* Whether the SEC compressed public key has even Y.
|
|
58010
|
+
* @returns {boolean} True if the public key has even Y.
|
|
58011
|
+
*/
|
|
58012
|
+
get isEven() {
|
|
58013
|
+
return this._bytes[0] === 2;
|
|
57997
58014
|
}
|
|
57998
58015
|
/**
|
|
57999
58016
|
* Get the x-coordinate of the public key.
|
|
@@ -58037,6 +58054,13 @@ var PublicKey = class _PublicKey {
|
|
|
58037
58054
|
y: this.y
|
|
58038
58055
|
};
|
|
58039
58056
|
}
|
|
58057
|
+
/**
|
|
58058
|
+
* Returns the BIP-340 (x-only) representation of this key.
|
|
58059
|
+
* @returns {KeyBytes} The BIP-340 (x-only) representation of the public key.
|
|
58060
|
+
*/
|
|
58061
|
+
bip340() {
|
|
58062
|
+
return this.xOnly;
|
|
58063
|
+
}
|
|
58040
58064
|
/**
|
|
58041
58065
|
* Returns the point of the public key.
|
|
58042
58066
|
* @param {Hex} pk The public key in hex (Uint8Array or string) format.
|
|
@@ -58045,11 +58069,11 @@ var PublicKey = class _PublicKey {
|
|
|
58045
58069
|
*/
|
|
58046
58070
|
static point(pk) {
|
|
58047
58071
|
if (typeof pk === "string" && /^[0-9a-fA-F]+$/.test(pk)) {
|
|
58048
|
-
const publicKey2 = new
|
|
58072
|
+
const publicKey2 = new _CompressedSecp256k1PublicKey(import_buffer.Buffer.fromHex(pk));
|
|
58049
58073
|
return publicKey2.point;
|
|
58050
58074
|
}
|
|
58051
58075
|
if (pk instanceof Uint8Array || ArrayBuffer.isView(pk)) {
|
|
58052
|
-
const publicKey2 = new
|
|
58076
|
+
const publicKey2 = new _CompressedSecp256k1PublicKey(pk);
|
|
58053
58077
|
return publicKey2.point;
|
|
58054
58078
|
}
|
|
58055
58079
|
throw new PublicKeyError("Invalid publicKey: must be a hex string or byte array", "POINT_ERROR", { publicKey: pk });
|
|
@@ -58059,7 +58083,7 @@ var PublicKey = class _PublicKey {
|
|
|
58059
58083
|
* @returns {KeyBytes} The decoded public key: prefix and public key bytes
|
|
58060
58084
|
*/
|
|
58061
58085
|
decode() {
|
|
58062
|
-
const decoded = base58btc.decode(this.multibase.
|
|
58086
|
+
const decoded = base58btc.decode(this.multibase.encoded);
|
|
58063
58087
|
if (decoded.length !== 35) {
|
|
58064
58088
|
throw new PublicKeyError("Invalid argument: must be 35 byte publicKeyMultibase", "DECODE_MULTIBASE_ERROR");
|
|
58065
58089
|
}
|
|
@@ -58085,15 +58109,15 @@ var PublicKey = class _PublicKey {
|
|
|
58085
58109
|
}
|
|
58086
58110
|
/**
|
|
58087
58111
|
* Compares this public key to another public key.
|
|
58088
|
-
* @param {
|
|
58112
|
+
* @param {CompressedSecp256k1PublicKey} other The other public key to compare
|
|
58089
58113
|
* @returns {boolean} True if the public keys are equal, false otherwise.
|
|
58090
58114
|
*/
|
|
58091
58115
|
equals(other) {
|
|
58092
58116
|
return this.hex === other.hex;
|
|
58093
58117
|
}
|
|
58094
58118
|
/**
|
|
58095
|
-
* JSON representation of a
|
|
58096
|
-
* @returns {PublicKeyObject} The
|
|
58119
|
+
* JSON representation of a CompressedSecp256k1PublicKey object.
|
|
58120
|
+
* @returns {PublicKeyObject} The CompressedSecp256k1PublicKey as a JSON object.
|
|
58097
58121
|
*/
|
|
58098
58122
|
json() {
|
|
58099
58123
|
return {
|
|
@@ -58107,26 +58131,26 @@ var PublicKey = class _PublicKey {
|
|
|
58107
58131
|
};
|
|
58108
58132
|
}
|
|
58109
58133
|
/**
|
|
58110
|
-
* Creates a
|
|
58111
|
-
* @param {PublicKeyObject} json The JSON object to initialize the
|
|
58112
|
-
* @returns {
|
|
58134
|
+
* Creates a CompressedSecp256k1PublicKey object from a JSON representation.
|
|
58135
|
+
* @param {PublicKeyObject} json The JSON object to initialize the CompressedSecp256k1PublicKey.
|
|
58136
|
+
* @returns {CompressedSecp256k1PublicKey} The initialized CompressedSecp256k1PublicKey object.
|
|
58113
58137
|
*/
|
|
58114
58138
|
static fromJSON(json) {
|
|
58115
58139
|
json.x.unshift(json.parity);
|
|
58116
|
-
return new
|
|
58140
|
+
return new _CompressedSecp256k1PublicKey(json.x.toUint8Array());
|
|
58117
58141
|
}
|
|
58118
58142
|
/**
|
|
58119
|
-
* Computes the deterministic public key for a given
|
|
58120
|
-
* @param {
|
|
58121
|
-
* @returns {
|
|
58143
|
+
* Computes the deterministic public key for a given secret key.
|
|
58144
|
+
* @param {Secp256k1SecretKey | KeyBytes} sk The Secp256k1SecretKey object or the secret key bytes
|
|
58145
|
+
* @returns {CompressedSecp256k1PublicKey} A new CompressedSecp256k1PublicKey object
|
|
58122
58146
|
*/
|
|
58123
58147
|
static fromSecretKey(sk) {
|
|
58124
|
-
const bytes3 = sk instanceof
|
|
58148
|
+
const bytes3 = sk instanceof Secp256k1SecretKey ? sk.bytes : sk;
|
|
58125
58149
|
if (bytes3.length !== 32) {
|
|
58126
|
-
throw new PublicKeyError("Invalid arg: must be 32 byte
|
|
58150
|
+
throw new PublicKeyError("Invalid arg: must be 32 byte secret key", "FROM_SECRET_KEY_ERROR");
|
|
58127
58151
|
}
|
|
58128
|
-
const
|
|
58129
|
-
return new
|
|
58152
|
+
const secret = sk instanceof Secp256k1SecretKey ? sk : new Secp256k1SecretKey(sk);
|
|
58153
|
+
return new _CompressedSecp256k1PublicKey(secret.computePublicKey());
|
|
58130
58154
|
}
|
|
58131
58155
|
/**
|
|
58132
58156
|
* Computes modular exponentiation: (base^exp) % mod.
|
|
@@ -58174,23 +58198,11 @@ var PublicKey = class _PublicKey {
|
|
|
58174
58198
|
const yBytes = import_buffer.Buffer.fromHex(y.toString(16).padStart(64, "0"));
|
|
58175
58199
|
return new Uint8Array(import_buffer.Buffer.concat([import_buffer.Buffer.from([4]), import_buffer.Buffer.from(this.x), yBytes]));
|
|
58176
58200
|
}
|
|
58177
|
-
/**
|
|
58178
|
-
* Static version of liftX method.
|
|
58179
|
-
* @param {KeyBytes} x The 32-byte x-coordinate to lift.
|
|
58180
|
-
* @returns {Uint8Array} The 65-byte uncompressed public key (0x04, x, y).
|
|
58181
|
-
*/
|
|
58182
|
-
static xOnly(x) {
|
|
58183
|
-
if (x.length !== 32) {
|
|
58184
|
-
throw new PublicKeyError("Invalid argument: x-coordinate length must be 32 bytes", "LIFT_X_ERROR");
|
|
58185
|
-
}
|
|
58186
|
-
const publicKey2 = new _PublicKey(x);
|
|
58187
|
-
return publicKey2.x;
|
|
58188
|
-
}
|
|
58189
58201
|
};
|
|
58190
58202
|
|
|
58191
58203
|
// ../keypair/dist/esm/pair.js
|
|
58192
58204
|
var SchnorrKeyPair = class _SchnorrKeyPair {
|
|
58193
|
-
/** @type {
|
|
58205
|
+
/** @type {Secp256k1SecretKey} The secret key object */
|
|
58194
58206
|
_secretKey;
|
|
58195
58207
|
_publicKey;
|
|
58196
58208
|
/** @type {string} The public key in multibase format */
|
|
@@ -58199,31 +58211,35 @@ var SchnorrKeyPair = class _SchnorrKeyPair {
|
|
|
58199
58211
|
_secretKeyMultibase;
|
|
58200
58212
|
/**
|
|
58201
58213
|
* Creates an instance of Keys. Must provide a at least a secret key.
|
|
58202
|
-
* Can optionally provide both a
|
|
58203
|
-
* @param {
|
|
58214
|
+
* Can optionally provide both a secret and public key, but must be a valid pair.
|
|
58215
|
+
* @param {SchnorrKeyPairParams} params The parameters to initialize the Keys object.
|
|
58216
|
+
* @param {CompressedSecp256k1PublicKey | KeyBytes} params.publicKey The public key object or bytes
|
|
58217
|
+
* @param {Secp256k1SecretKey | KeyBytes} [params.secret] The secret key object or bytes
|
|
58218
|
+
* @throws {KeyPairError} If neither a public key or secret key is provided.
|
|
58219
|
+
* @throws {KeyPairError} If the public key is not a valid pair with the secret key.
|
|
58204
58220
|
*/
|
|
58205
|
-
constructor(
|
|
58206
|
-
if (!
|
|
58221
|
+
constructor(params = {}) {
|
|
58222
|
+
if (!params.publicKey && !params.secretKey) {
|
|
58207
58223
|
throw new KeyPairError("Argument missing: must at least provide a publicKey", "CONSTRUCTOR_ERROR");
|
|
58208
58224
|
}
|
|
58209
|
-
if (secretKey instanceof Uint8Array) {
|
|
58210
|
-
this._secretKey = new
|
|
58211
|
-
} else if (secretKey instanceof
|
|
58212
|
-
this._secretKey = secretKey;
|
|
58225
|
+
if (params.secretKey instanceof Uint8Array) {
|
|
58226
|
+
this._secretKey = new Secp256k1SecretKey(params.secretKey);
|
|
58227
|
+
} else if (params.secretKey instanceof Secp256k1SecretKey) {
|
|
58228
|
+
this._secretKey = params.secretKey;
|
|
58213
58229
|
}
|
|
58214
|
-
if (
|
|
58215
|
-
this._publicKey =
|
|
58216
|
-
} else if (
|
|
58217
|
-
this._publicKey = new
|
|
58230
|
+
if (params.publicKey instanceof CompressedSecp256k1PublicKey) {
|
|
58231
|
+
this._publicKey = params.publicKey;
|
|
58232
|
+
} else if (params.publicKey instanceof Uint8Array) {
|
|
58233
|
+
this._publicKey = new CompressedSecp256k1PublicKey(params.publicKey);
|
|
58218
58234
|
} else {
|
|
58219
|
-
this._publicKey = new
|
|
58235
|
+
this._publicKey = new CompressedSecp256k1PublicKey(this._secretKey.computePublicKey());
|
|
58220
58236
|
}
|
|
58221
|
-
this._publicKeyMultibase = this._publicKey.multibase.
|
|
58237
|
+
this._publicKeyMultibase = this._publicKey.multibase.encoded;
|
|
58222
58238
|
this._secretKeyMultibase = this._secretKey ? this._secretKey.multibase : "";
|
|
58223
58239
|
}
|
|
58224
58240
|
/**
|
|
58225
|
-
* Get the
|
|
58226
|
-
* @returns {
|
|
58241
|
+
* Get the Secp256k1SecretKey.
|
|
58242
|
+
* @returns {Secp256k1SecretKey} The Secp256k1SecretKey object
|
|
58227
58243
|
* @throws {KeyPairError} If the secret key is not available
|
|
58228
58244
|
*/
|
|
58229
58245
|
get secretKey() {
|
|
@@ -58233,33 +58249,33 @@ var SchnorrKeyPair = class _SchnorrKeyPair {
|
|
|
58233
58249
|
if (!this._secretKey.isValid()) {
|
|
58234
58250
|
throw new KeyPairError("Secret key is not valid", "SECRET_KEY_ERROR");
|
|
58235
58251
|
}
|
|
58236
|
-
const
|
|
58237
|
-
return
|
|
58252
|
+
const secret = this._secretKey;
|
|
58253
|
+
return secret;
|
|
58238
58254
|
}
|
|
58239
58255
|
/**
|
|
58240
|
-
* Set the
|
|
58241
|
-
* @param {
|
|
58256
|
+
* Set the CompressedSecp256k1PublicKey.
|
|
58257
|
+
* @param {CompressedSecp256k1PublicKey} publicKey The CompressedSecp256k1PublicKey object
|
|
58242
58258
|
* @throws {KeyPairError} If the public key is not a valid pair with the secret key.
|
|
58243
58259
|
*/
|
|
58244
58260
|
set publicKey(publicKey2) {
|
|
58245
|
-
if (this.secretKey && !this.secretKey.
|
|
58261
|
+
if (this.secretKey && !this.secretKey.hasValidPublicKey(publicKey2)) {
|
|
58246
58262
|
throw new KeyPairError("Public key is not a valid pair with the secret key", "PUBLIC_KEY_ERROR");
|
|
58247
58263
|
}
|
|
58248
58264
|
this._publicKey = publicKey2;
|
|
58249
|
-
this._publicKeyMultibase = publicKey2.multibase.
|
|
58265
|
+
this._publicKeyMultibase = publicKey2.multibase.encoded;
|
|
58250
58266
|
this._secretKeyMultibase = this._secretKey ? this._secretKey.multibase : "";
|
|
58251
58267
|
}
|
|
58252
58268
|
/**
|
|
58253
|
-
* Get the
|
|
58254
|
-
* @returns {
|
|
58269
|
+
* Get the CompressedSecp256k1PublicKey.
|
|
58270
|
+
* @returns {CompressedSecp256k1PublicKey} The CompressedSecp256k1PublicKey object
|
|
58255
58271
|
*/
|
|
58256
58272
|
get publicKey() {
|
|
58257
58273
|
const publicKey2 = this._publicKey;
|
|
58258
58274
|
return publicKey2;
|
|
58259
58275
|
}
|
|
58260
58276
|
/**
|
|
58261
|
-
* Get the
|
|
58262
|
-
* @returns {
|
|
58277
|
+
* Get the raw bytes of each key in the SchnorrKeyPair.
|
|
58278
|
+
* @returns {RawSchnorrKeyPair} JSON object with the SchnorrKeyPair raw bytes.
|
|
58263
58279
|
*/
|
|
58264
58280
|
get raw() {
|
|
58265
58281
|
return {
|
|
@@ -58269,7 +58285,7 @@ var SchnorrKeyPair = class _SchnorrKeyPair {
|
|
|
58269
58285
|
}
|
|
58270
58286
|
/**
|
|
58271
58287
|
* Get the Keys in multibase format.
|
|
58272
|
-
* @returns {MultibaseKeys} The
|
|
58288
|
+
* @returns {MultibaseKeys} The Secp256k1SecretKey in multibase format
|
|
58273
58289
|
*/
|
|
58274
58290
|
get multibase() {
|
|
58275
58291
|
return {
|
|
@@ -58293,37 +58309,40 @@ var SchnorrKeyPair = class _SchnorrKeyPair {
|
|
|
58293
58309
|
* @returns {SchnorrKeyPair} The initialized Keys object.
|
|
58294
58310
|
*/
|
|
58295
58311
|
static fromJSON(keys) {
|
|
58296
|
-
|
|
58297
|
-
|
|
58298
|
-
|
|
58312
|
+
return new _SchnorrKeyPair({
|
|
58313
|
+
secretKey: Secp256k1SecretKey.fromJSON(keys.secretKey),
|
|
58314
|
+
publicKey: CompressedSecp256k1PublicKey.fromJSON(keys.publicKey)
|
|
58315
|
+
});
|
|
58299
58316
|
}
|
|
58300
58317
|
/**
|
|
58301
|
-
* Static method creates a new SchnorrKeyPair from a
|
|
58302
|
-
* @param {
|
|
58318
|
+
* Static method creates a new SchnorrKeyPair from a Secp256k1SecretKey object or secret key bytes.
|
|
58319
|
+
* @param {Secp256k1SecretKey | KeyBytes} data The secret key bytes
|
|
58303
58320
|
* @returns {SchnorrKeyPair} A new SchnorrKeyPair object
|
|
58304
58321
|
*/
|
|
58305
58322
|
static fromPrivateKey(data) {
|
|
58306
|
-
const bytes3 = data instanceof
|
|
58323
|
+
const bytes3 = data instanceof Secp256k1SecretKey ? data.bytes : data;
|
|
58307
58324
|
if (bytes3.length !== 32) {
|
|
58308
58325
|
throw new KeyPairError("Invalid arg: must be 32 byte secret key", "FROM_PRIVATE_KEY_ERROR");
|
|
58309
58326
|
}
|
|
58310
|
-
const
|
|
58311
|
-
|
|
58312
|
-
|
|
58327
|
+
const secret = data instanceof Uint8Array ? new Secp256k1SecretKey(data) : data;
|
|
58328
|
+
return new _SchnorrKeyPair({
|
|
58329
|
+
secretKey: data instanceof Uint8Array ? new Secp256k1SecretKey(data) : data,
|
|
58330
|
+
publicKey: secret.computePublicKey()
|
|
58331
|
+
});
|
|
58313
58332
|
}
|
|
58314
58333
|
/**
|
|
58315
|
-
* Static method creates a new Keys (
|
|
58316
|
-
* @param {bigint}
|
|
58317
|
-
* @returns {
|
|
58334
|
+
* Static method creates a new Keys (Secp256k1SecretKey/CompressedSecp256k1PublicKey) from bigint entropy.
|
|
58335
|
+
* @param {bigint} entropy The entropy in bigint form
|
|
58336
|
+
* @returns {SchnorrKeyPair} A new SchnorrKeyPair object
|
|
58318
58337
|
*/
|
|
58319
|
-
static
|
|
58320
|
-
const secretKey =
|
|
58338
|
+
static fromEntropy(entropy) {
|
|
58339
|
+
const secretKey = Secp256k1SecretKey.fromEntropy(entropy);
|
|
58321
58340
|
const publicKey2 = secretKey.computePublicKey();
|
|
58322
58341
|
return new _SchnorrKeyPair({ secretKey, publicKey: publicKey2 });
|
|
58323
58342
|
}
|
|
58324
58343
|
/**
|
|
58325
58344
|
* Converts key bytes to a hex string.
|
|
58326
|
-
* @param {KeyBytes} keyBytes The key bytes (
|
|
58345
|
+
* @param {KeyBytes} keyBytes The key bytes (secret or public).
|
|
58327
58346
|
* @returns {Hex} The key bytes as a hex string.
|
|
58328
58347
|
*/
|
|
58329
58348
|
static toHex(keyBytes) {
|
|
@@ -58331,18 +58350,18 @@ var SchnorrKeyPair = class _SchnorrKeyPair {
|
|
|
58331
58350
|
}
|
|
58332
58351
|
/**
|
|
58333
58352
|
* Compares two Keys objects for equality.
|
|
58334
|
-
* @param {SchnorrKeyPair}
|
|
58335
|
-
* @param {SchnorrKeyPair}
|
|
58353
|
+
* @param {SchnorrKeyPair} kp The main keys.
|
|
58354
|
+
* @param {SchnorrKeyPair} otherKp The other keys to compare.
|
|
58336
58355
|
* @returns {boolean} True if the public key and secret key are equal, false otherwise.
|
|
58337
58356
|
*/
|
|
58338
|
-
static equals(
|
|
58339
|
-
const pk =
|
|
58340
|
-
const otherPk =
|
|
58357
|
+
static equals(kp, otherKp) {
|
|
58358
|
+
const pk = kp.publicKey;
|
|
58359
|
+
const otherPk = otherKp.publicKey;
|
|
58341
58360
|
if (pk && otherPk) {
|
|
58342
58361
|
return pk.hex === otherPk.hex;
|
|
58343
58362
|
}
|
|
58344
|
-
const sk =
|
|
58345
|
-
const otherSk =
|
|
58363
|
+
const sk = kp.secretKey;
|
|
58364
|
+
const otherSk = otherKp.secretKey;
|
|
58346
58365
|
if (sk && otherSk) {
|
|
58347
58366
|
return sk.hex === otherSk.hex;
|
|
58348
58367
|
}
|
|
@@ -58350,16 +58369,19 @@ var SchnorrKeyPair = class _SchnorrKeyPair {
|
|
|
58350
58369
|
}
|
|
58351
58370
|
/**
|
|
58352
58371
|
* Static method to generate a new random SchnorrKeyPair instance.
|
|
58353
|
-
* @returns {SchnorrKeyPair} A new
|
|
58372
|
+
* @returns {SchnorrKeyPair} A new Secp256k1SecretKey object.
|
|
58354
58373
|
*/
|
|
58355
58374
|
static generate() {
|
|
58356
|
-
const
|
|
58357
|
-
const secretKey = new
|
|
58375
|
+
const sk = Secp256k1SecretKey.random();
|
|
58376
|
+
const secretKey = new Secp256k1SecretKey(sk);
|
|
58358
58377
|
const publicKey2 = secretKey.computePublicKey();
|
|
58359
58378
|
return new _SchnorrKeyPair({ secretKey, publicKey: publicKey2 });
|
|
58360
58379
|
}
|
|
58361
58380
|
};
|
|
58362
58381
|
|
|
58382
|
+
// ../keypair/dist/esm/types.js
|
|
58383
|
+
init_shim();
|
|
58384
|
+
|
|
58363
58385
|
// src/utils/appendix.ts
|
|
58364
58386
|
init_shim();
|
|
58365
58387
|
|
|
@@ -65680,7 +65702,7 @@ function twistedEdwards(curveDef) {
|
|
|
65680
65702
|
return n3 === _0n6 ? n3 : assertInRange(n3, CURVE_ORDER);
|
|
65681
65703
|
}
|
|
65682
65704
|
const pointPrecomputes2 = /* @__PURE__ */ new Map();
|
|
65683
|
-
function
|
|
65705
|
+
function isPoint4(other) {
|
|
65684
65706
|
if (!(other instanceof Point4))
|
|
65685
65707
|
throw new Error("ExtendedPoint expected");
|
|
65686
65708
|
}
|
|
@@ -65745,7 +65767,7 @@ function twistedEdwards(curveDef) {
|
|
|
65745
65767
|
}
|
|
65746
65768
|
// Compare one point to another.
|
|
65747
65769
|
equals(other) {
|
|
65748
|
-
|
|
65770
|
+
isPoint4(other);
|
|
65749
65771
|
const { ex: X1, ey: Y1, ez: Z1 } = this;
|
|
65750
65772
|
const { ex: X2, ey: Y2, ez: Z2 } = other;
|
|
65751
65773
|
const X1Z2 = modP(X1 * Z2);
|
|
@@ -65785,7 +65807,7 @@ function twistedEdwards(curveDef) {
|
|
|
65785
65807
|
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
|
|
65786
65808
|
// Cost: 9M + 1*a + 1*d + 7add.
|
|
65787
65809
|
add(other) {
|
|
65788
|
-
|
|
65810
|
+
isPoint4(other);
|
|
65789
65811
|
const { a: a3, d: d2 } = CURVE2;
|
|
65790
65812
|
const { ex: X1, ey: Y1, ez: Z1, et: T1 } = this;
|
|
65791
65813
|
const { ex: X2, ey: Y2, ez: Z2, et: T2 } = other;
|
|
@@ -86841,10 +86863,10 @@ var __KeyTypeValues;
|
|
|
86841
86863
|
return enumeration(__KeyTypeValues);
|
|
86842
86864
|
};
|
|
86843
86865
|
})(KeyType || (KeyType = {}));
|
|
86844
|
-
var
|
|
86845
|
-
(function(
|
|
86866
|
+
var PublicKey;
|
|
86867
|
+
(function(PublicKey3) {
|
|
86846
86868
|
let _codec;
|
|
86847
|
-
|
|
86869
|
+
PublicKey3.codec = () => {
|
|
86848
86870
|
if (_codec == null) {
|
|
86849
86871
|
_codec = message((obj, w, opts = {}) => {
|
|
86850
86872
|
if (opts.lengthDelimited !== false) {
|
|
@@ -86886,13 +86908,13 @@ var PublicKey2;
|
|
|
86886
86908
|
}
|
|
86887
86909
|
return _codec;
|
|
86888
86910
|
};
|
|
86889
|
-
|
|
86890
|
-
return encodeMessage(obj,
|
|
86911
|
+
PublicKey3.encode = (obj) => {
|
|
86912
|
+
return encodeMessage(obj, PublicKey3.codec());
|
|
86891
86913
|
};
|
|
86892
|
-
|
|
86893
|
-
return decodeMessage(buf2,
|
|
86914
|
+
PublicKey3.decode = (buf2, opts) => {
|
|
86915
|
+
return decodeMessage(buf2, PublicKey3.codec(), opts);
|
|
86894
86916
|
};
|
|
86895
|
-
})(
|
|
86917
|
+
})(PublicKey || (PublicKey = {}));
|
|
86896
86918
|
var PrivateKey;
|
|
86897
86919
|
(function(PrivateKey3) {
|
|
86898
86920
|
let _codec;
|
|
@@ -87143,7 +87165,7 @@ function pkixToRSAPublicKey(bytes3, digest2) {
|
|
|
87143
87165
|
function pkixMessageToRSAPublicKey(message2, bytes3, digest2) {
|
|
87144
87166
|
const jwk = pkixMessageToJwk(message2);
|
|
87145
87167
|
if (digest2 == null) {
|
|
87146
|
-
const hash2 = sha2562(
|
|
87168
|
+
const hash2 = sha2562(PublicKey.encode({
|
|
87147
87169
|
Type: KeyType.RSA,
|
|
87148
87170
|
Data: bytes3
|
|
87149
87171
|
}));
|
|
@@ -87156,7 +87178,7 @@ function jwkToRSAPrivateKey(jwk) {
|
|
|
87156
87178
|
throw new InvalidParametersError("Key size is too large");
|
|
87157
87179
|
}
|
|
87158
87180
|
const keys = jwkToJWKKeyPair(jwk);
|
|
87159
|
-
const hash2 = sha2562(
|
|
87181
|
+
const hash2 = sha2562(PublicKey.encode({
|
|
87160
87182
|
Type: KeyType.RSA,
|
|
87161
87183
|
Data: jwkToPkix(keys.publicKey)
|
|
87162
87184
|
}));
|
|
@@ -87168,7 +87190,7 @@ async function generateRSAKeyPair(bits) {
|
|
|
87168
87190
|
throw new InvalidParametersError("Key size is too large");
|
|
87169
87191
|
}
|
|
87170
87192
|
const keys = await generateRSAKey(bits);
|
|
87171
|
-
const hash2 = sha2562(
|
|
87193
|
+
const hash2 = sha2562(PublicKey.encode({
|
|
87172
87194
|
Type: KeyType.RSA,
|
|
87173
87195
|
Data: jwkToPkix(keys.publicKey)
|
|
87174
87196
|
}));
|
|
@@ -88659,7 +88681,7 @@ async function generateKeyPair(type, bits) {
|
|
|
88659
88681
|
throw new UnsupportedKeyTypeError();
|
|
88660
88682
|
}
|
|
88661
88683
|
function publicKeyFromProtobuf(buf2, digest2) {
|
|
88662
|
-
const { Type: Type2, Data } =
|
|
88684
|
+
const { Type: Type2, Data } = PublicKey.decode(buf2);
|
|
88663
88685
|
const data = Data ?? new Uint8Array();
|
|
88664
88686
|
switch (Type2) {
|
|
88665
88687
|
case KeyType.RSA:
|
|
@@ -88675,7 +88697,7 @@ function publicKeyFromProtobuf(buf2, digest2) {
|
|
|
88675
88697
|
}
|
|
88676
88698
|
}
|
|
88677
88699
|
function publicKeyFromMultihash(digest2) {
|
|
88678
|
-
const { Type: Type2, Data } =
|
|
88700
|
+
const { Type: Type2, Data } = PublicKey.decode(digest2.digest);
|
|
88679
88701
|
const data = Data ?? new Uint8Array();
|
|
88680
88702
|
switch (Type2) {
|
|
88681
88703
|
case KeyType.Ed25519:
|
|
@@ -88689,7 +88711,7 @@ function publicKeyFromMultihash(digest2) {
|
|
|
88689
88711
|
}
|
|
88690
88712
|
}
|
|
88691
88713
|
function publicKeyToProtobuf(key) {
|
|
88692
|
-
return
|
|
88714
|
+
return PublicKey.encode({
|
|
88693
88715
|
Type: KeyType[key.type],
|
|
88694
88716
|
Data: key.raw
|
|
88695
88717
|
});
|
|
@@ -142574,7 +142596,7 @@ var PemData = class _PemData extends AsnData {
|
|
|
142574
142596
|
}
|
|
142575
142597
|
}
|
|
142576
142598
|
};
|
|
142577
|
-
var
|
|
142599
|
+
var PublicKey2 = class _PublicKey extends PemData {
|
|
142578
142600
|
static async create(data, crypto6 = cryptoProvider.get()) {
|
|
142579
142601
|
if (data instanceof _PublicKey) {
|
|
142580
142602
|
return data;
|
|
@@ -142690,7 +142712,7 @@ var AuthorityKeyIdentifierExtension = class _AuthorityKeyIdentifierExtension ext
|
|
|
142690
142712
|
if ("name" in param && "serialNumber" in param) {
|
|
142691
142713
|
return new _AuthorityKeyIdentifierExtension(param, critical);
|
|
142692
142714
|
}
|
|
142693
|
-
const key = await
|
|
142715
|
+
const key = await PublicKey2.create(param, crypto6);
|
|
142694
142716
|
const id = await key.getKeyIdentifier(crypto6);
|
|
142695
142717
|
return new _AuthorityKeyIdentifierExtension(import_pvtsutils6.Convert.ToHex(id), critical);
|
|
142696
142718
|
}
|
|
@@ -142830,7 +142852,7 @@ var KeyUsagesExtension = class extends Extension2 {
|
|
|
142830
142852
|
KeyUsagesExtension.NAME = "Key Usages";
|
|
142831
142853
|
var SubjectKeyIdentifierExtension = class _SubjectKeyIdentifierExtension extends Extension2 {
|
|
142832
142854
|
static async create(publicKey2, critical = false, crypto6 = cryptoProvider.get()) {
|
|
142833
|
-
const key = await
|
|
142855
|
+
const key = await PublicKey2.create(publicKey2, crypto6);
|
|
142834
142856
|
const id = await key.getKeyIdentifier(crypto6);
|
|
142835
142857
|
return new _SubjectKeyIdentifierExtension(import_pvtsutils6.Convert.ToHex(id), critical);
|
|
142836
142858
|
}
|
|
@@ -143472,7 +143494,7 @@ var Pkcs10CertificateRequest = class extends PemData {
|
|
|
143472
143494
|
}
|
|
143473
143495
|
get publicKey() {
|
|
143474
143496
|
if (!__classPrivateFieldGet(this, _Pkcs10CertificateRequest_publicKey, "f")) {
|
|
143475
|
-
__classPrivateFieldSet(this, _Pkcs10CertificateRequest_publicKey, new
|
|
143497
|
+
__classPrivateFieldSet(this, _Pkcs10CertificateRequest_publicKey, new PublicKey2(this.asn.certificationRequestInfo.subjectPKInfo), "f");
|
|
143476
143498
|
}
|
|
143477
143499
|
return __classPrivateFieldGet(this, _Pkcs10CertificateRequest_publicKey, "f");
|
|
143478
143500
|
}
|
|
@@ -143594,7 +143616,7 @@ var _X509Certificate_publicKey;
|
|
|
143594
143616
|
var X509Certificate = class extends PemData {
|
|
143595
143617
|
get publicKey() {
|
|
143596
143618
|
if (!__classPrivateFieldGet(this, _X509Certificate_publicKey, "f")) {
|
|
143597
|
-
__classPrivateFieldSet(this, _X509Certificate_publicKey, new
|
|
143619
|
+
__classPrivateFieldSet(this, _X509Certificate_publicKey, new PublicKey2(this.asn.tbsCertificate.subjectPublicKeyInfo), "f");
|
|
143598
143620
|
}
|
|
143599
143621
|
return __classPrivateFieldGet(this, _X509Certificate_publicKey, "f");
|
|
143600
143622
|
}
|
|
@@ -143734,11 +143756,11 @@ var X509Certificate = class extends PemData {
|
|
|
143734
143756
|
} else if ("publicKey" in paramsKey) {
|
|
143735
143757
|
keyAlgorithm = { ...paramsKey.publicKey.algorithm, ...this.signatureAlgorithm };
|
|
143736
143758
|
publicKey2 = await paramsKey.publicKey.export(keyAlgorithm, ["verify"], crypto6);
|
|
143737
|
-
} else if (paramsKey instanceof
|
|
143759
|
+
} else if (paramsKey instanceof PublicKey2) {
|
|
143738
143760
|
keyAlgorithm = { ...paramsKey.algorithm, ...this.signatureAlgorithm };
|
|
143739
143761
|
publicKey2 = await paramsKey.export(keyAlgorithm, ["verify"], crypto6);
|
|
143740
143762
|
} else if (import_pvtsutils6.BufferSourceConverter.isBufferSource(paramsKey)) {
|
|
143741
|
-
const key = new
|
|
143763
|
+
const key = new PublicKey2(paramsKey);
|
|
143742
143764
|
keyAlgorithm = { ...key.algorithm, ...this.signatureAlgorithm };
|
|
143743
143765
|
publicKey2 = await key.export(keyAlgorithm, ["verify"], crypto6);
|
|
143744
143766
|
} else {
|
|
@@ -143867,7 +143889,7 @@ var X509CertificateGenerator = class {
|
|
|
143867
143889
|
static async create(params, crypto6 = cryptoProvider.get()) {
|
|
143868
143890
|
var _a3;
|
|
143869
143891
|
let spki;
|
|
143870
|
-
if (params.publicKey instanceof
|
|
143892
|
+
if (params.publicKey instanceof PublicKey2) {
|
|
143871
143893
|
spki = params.publicKey.rawData;
|
|
143872
143894
|
} else if ("publicKey" in params.publicKey) {
|
|
143873
143895
|
spki = params.publicKey.publicKey.rawData;
|
|
@@ -145174,7 +145196,7 @@ var Appendix = class _Appendix {
|
|
|
145174
145196
|
return verificationMethods;
|
|
145175
145197
|
}
|
|
145176
145198
|
/**
|
|
145177
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2/#derive-root-capability-from-
|
|
145199
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/#derive-root-capability-from-didbtcr2-identifier | 9.4.1 Derive Root Capability from did:btcr2 Identifier }.
|
|
145178
145200
|
*
|
|
145179
145201
|
* The Derive Root Capability algorithm deterministically generates a ZCAP-LD root capability from a given did:btcr2
|
|
145180
145202
|
* identifier. Each root capability is unique to the identifier. This root capability is defined and understood by the
|
|
@@ -145182,7 +145204,7 @@ var Appendix = class _Appendix {
|
|
|
145182
145204
|
* document. It takes in a did:btcr2 identifier and returns a rootCapability object. It returns the root capability.
|
|
145183
145205
|
*
|
|
145184
145206
|
* @param {string} identifier The did-btcr2 identifier to derive the root capability from
|
|
145185
|
-
* @returns {
|
|
145207
|
+
* @returns {RootCapability} The root capability object
|
|
145186
145208
|
* @example Root capability for updating the DID document for
|
|
145187
145209
|
* did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u
|
|
145188
145210
|
* ```
|
|
@@ -145210,7 +145232,7 @@ var Appendix = class _Appendix {
|
|
|
145210
145232
|
* capability object.
|
|
145211
145233
|
*
|
|
145212
145234
|
* @param {string} capabilityId The root capability identifier to dereference.
|
|
145213
|
-
* @returns {
|
|
145235
|
+
* @returns {RootCapability} The root capability object.
|
|
145214
145236
|
* @example a didUpdatePayload with an invoked ZCAP-LD capability containing a patch defining how the DID document
|
|
145215
145237
|
* for did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u SHOULD be mutated.
|
|
145216
145238
|
* ```
|
|
@@ -145236,7 +145258,7 @@ var Appendix = class _Appendix {
|
|
|
145236
145258
|
* "cryptosuite": "schnorr-secp256k1-jcs-2025",
|
|
145237
145259
|
* "verificationMethod": "did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u#initialKey",
|
|
145238
145260
|
* "invocationTarget": "did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u",
|
|
145239
|
-
* "capability": "urn:zcap:root:did%
|
|
145261
|
+
* "capability": "urn:zcap:root:did%3Abtcr2%3Ak1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u",
|
|
145240
145262
|
* "capabilityAction": "Write",
|
|
145241
145263
|
* "proofPurpose": "assertionMethod",
|
|
145242
145264
|
* "proofValue": "z381yXYmxU8NudZ4HXY56DfMN6zfD8syvWcRXzT9xD9uYoQToo8QsXD7ahM3gXTzuay5WJbqTswt2BKaGWYn2hHhVFKJLXaDz"
|
|
@@ -145567,8 +145589,8 @@ var SchnorrMultikey = class _SchnorrMultikey {
|
|
|
145567
145589
|
* @param {string} params.id The id of the multikey (required)
|
|
145568
145590
|
* @param {string} params.controller The controller of the multikey (required)
|
|
145569
145591
|
* @param {Keys} params.keys The Keys of the multikey (optional, required if no publicKey)
|
|
145570
|
-
* @param {
|
|
145571
|
-
* @param {
|
|
145592
|
+
* @param {CompressedSecp256k1PublicKey} params.keys.publicKey The public key of the multikey (optional, required if no privateKey)
|
|
145593
|
+
* @param {Secp256k1SecretKey} params.keys.privateKey The private key of the multikey (optional)
|
|
145572
145594
|
* @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
|
|
145573
145595
|
*/
|
|
145574
145596
|
constructor({ id, controller, keys }) {
|
|
@@ -145587,7 +145609,7 @@ var SchnorrMultikey = class _SchnorrMultikey {
|
|
|
145587
145609
|
const keys = this._keys;
|
|
145588
145610
|
return keys;
|
|
145589
145611
|
}
|
|
145590
|
-
/** @type {
|
|
145612
|
+
/** @type {CompressedSecp256k1PublicKey} @readonly Get the Multikey CompressedSecp256k1PublicKey. */
|
|
145591
145613
|
get publicKey() {
|
|
145592
145614
|
const publicKey2 = this._keys.publicKey;
|
|
145593
145615
|
return publicKey2;
|
|
@@ -145663,7 +145685,7 @@ var SchnorrMultikey = class _SchnorrMultikey {
|
|
|
145663
145685
|
id: this.id,
|
|
145664
145686
|
type: _SchnorrMultikey.type,
|
|
145665
145687
|
controller: this.controller,
|
|
145666
|
-
publicKeyMultibase: this.publicKey.multibase.
|
|
145688
|
+
publicKeyMultibase: this.publicKey.multibase.encoded
|
|
145667
145689
|
};
|
|
145668
145690
|
}
|
|
145669
145691
|
/**
|
|
@@ -145691,10 +145713,10 @@ var SchnorrMultikey = class _SchnorrMultikey {
|
|
|
145691
145713
|
}
|
|
145692
145714
|
const decoded = this.publicKey.decode();
|
|
145693
145715
|
const publicKey2 = decoded.slice(2, decoded.length);
|
|
145694
|
-
const keys = new SchnorrKeyPair({ publicKey: new
|
|
145716
|
+
const keys = new SchnorrKeyPair({ publicKey: new CompressedSecp256k1PublicKey(publicKey2) });
|
|
145695
145717
|
return new _SchnorrMultikey({ id, controller, keys });
|
|
145696
145718
|
}
|
|
145697
|
-
/** @type {boolean} @readonly Get signing ability of the Multikey (i.e. is there a valid
|
|
145719
|
+
/** @type {boolean} @readonly Get signing ability of the Multikey (i.e. is there a valid Secp256k1SecretKey). */
|
|
145698
145720
|
get signer() {
|
|
145699
145721
|
return !!this.keys.secretKey;
|
|
145700
145722
|
}
|
|
@@ -145735,7 +145757,7 @@ var SchnorrMultikey = class _SchnorrMultikey {
|
|
|
145735
145757
|
* @returns {SchnorrMultikey} The new multikey instance
|
|
145736
145758
|
*/
|
|
145737
145759
|
static fromPrivateKey({ id, controller, entropy }) {
|
|
145738
|
-
const secretKey = new
|
|
145760
|
+
const secretKey = new Secp256k1SecretKey(entropy);
|
|
145739
145761
|
const publicKey2 = secretKey.computePublicKey();
|
|
145740
145762
|
const keys = new SchnorrKeyPair({ publicKey: publicKey2, secretKey });
|
|
145741
145763
|
return new _SchnorrMultikey({ id, controller, keys });
|
|
@@ -145749,7 +145771,7 @@ var SchnorrMultikey = class _SchnorrMultikey {
|
|
|
145749
145771
|
* @returns {Multikey} The new multikey instance
|
|
145750
145772
|
*/
|
|
145751
145773
|
static fromPublicKey({ id, controller, publicKeyBytes }) {
|
|
145752
|
-
const keys = new SchnorrKeyPair({ publicKey: new
|
|
145774
|
+
const keys = new SchnorrKeyPair({ publicKey: new CompressedSecp256k1PublicKey(publicKeyBytes) });
|
|
145753
145775
|
return new _SchnorrMultikey({ id, controller, keys });
|
|
145754
145776
|
}
|
|
145755
145777
|
/**
|
|
@@ -145840,9 +145862,9 @@ var KeyManager = class _KeyManager {
|
|
|
145840
145862
|
throw new Error("Method not implemented." + txHex + keyUri);
|
|
145841
145863
|
}
|
|
145842
145864
|
/**
|
|
145843
|
-
* Gets the key pair from the key store and returns a
|
|
145865
|
+
* Gets the key pair from the key store and returns a CompressedSecp256k1PublicKey.
|
|
145844
145866
|
* @param {KeyIdentifier} keyUri The URI of the key to get the public key for.
|
|
145845
|
-
* @returns {Promise<
|
|
145867
|
+
* @returns {Promise<CompressedSecp256k1PublicKey>} The public key associated with the key URI.
|
|
145846
145868
|
*/
|
|
145847
145869
|
async getPublicKey(keyUri) {
|
|
145848
145870
|
const key = await this.getKey(keyUri);
|
|
@@ -145959,11 +145981,11 @@ var KeyManager = class _KeyManager {
|
|
|
145959
145981
|
}
|
|
145960
145982
|
/**
|
|
145961
145983
|
* Computes a multibase-compliant URI from a key.
|
|
145962
|
-
* @param key A SchnorrKeyPair,
|
|
145984
|
+
* @param key A SchnorrKeyPair, CompressedSecp256k1PublicKey, or multibase string
|
|
145963
145985
|
* @returns {string} A multibase URI (e.g. 'urn:mb:zQ3s...')
|
|
145964
145986
|
*/
|
|
145965
145987
|
static toMultibaseUri(data) {
|
|
145966
|
-
const multibase = data instanceof SchnorrKeyPair ? data.publicKey.multibase : data instanceof
|
|
145988
|
+
const multibase = data instanceof SchnorrKeyPair ? data.publicKey.multibase : data instanceof CompressedSecp256k1PublicKey ? data.multibase : data;
|
|
145967
145989
|
return `${MULTIBASE_URI_PREFIX}${multibase}`;
|
|
145968
145990
|
}
|
|
145969
145991
|
/**
|
|
@@ -146106,7 +146128,7 @@ var SingletonBeacon = class _SingletonBeacon extends Beacon {
|
|
|
146106
146128
|
const hashBytes = JSON.canonicalization.encode(import_buffer.Buffer.fromHex(UPDATE_PAYLOAD_HASH), "base58");
|
|
146107
146129
|
const signalsMetadataMap = new Map(Object.entries(signalsMetadata));
|
|
146108
146130
|
if (signalsMetadata) {
|
|
146109
|
-
didUpdatePayload = signalsMetadataMap.get(signal.txid)?.
|
|
146131
|
+
didUpdatePayload = signalsMetadataMap.get(signal.txid)?.didUpdate;
|
|
146110
146132
|
if (!didUpdatePayload) {
|
|
146111
146133
|
throw new SingletonBeaconError("Update Payload not found in signal metadata.", "PROCESS_SIGNAL_ERROR");
|
|
146112
146134
|
}
|
|
@@ -146185,7 +146207,7 @@ var SingletonBeacon = class _SingletonBeacon extends Beacon {
|
|
|
146185
146207
|
if (!spentTx) {
|
|
146186
146208
|
throw new SingletonBeaconError("Failed to send raw transaction.", "SEND_FAILED", { spentTx });
|
|
146187
146209
|
}
|
|
146188
|
-
return { [spentTx]: {
|
|
146210
|
+
return { [spentTx]: { didUpdate: didUpdatePayload } };
|
|
146189
146211
|
}
|
|
146190
146212
|
};
|
|
146191
146213
|
|
|
@@ -146904,7 +146926,7 @@ var bech32m3 = /* @__PURE__ */ genBech32("bech32m");
|
|
|
146904
146926
|
// src/utils/identifier.ts
|
|
146905
146927
|
var Identifier = class {
|
|
146906
146928
|
/**
|
|
146907
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2/#
|
|
146929
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/#didbtcr2-identifier-encoding | 3.2 did:btcr2 Identifier Encoding}.
|
|
146908
146930
|
*
|
|
146909
146931
|
* A did:btcr2 DID consists of a did:btcr2 prefix, followed by an id-bech32 value, which is a Bech32m encoding of:
|
|
146910
146932
|
* - the specification version;
|
|
@@ -146935,7 +146957,7 @@ var Identifier = class {
|
|
|
146935
146957
|
}
|
|
146936
146958
|
if (idType === "KEY") {
|
|
146937
146959
|
try {
|
|
146938
|
-
new
|
|
146960
|
+
new CompressedSecp256k1PublicKey(genesisBytes);
|
|
146939
146961
|
} catch {
|
|
146940
146962
|
throw new MethodError(
|
|
146941
146963
|
'Expected "genesisBytes" to be a valid compressed secp256k1 public key',
|
|
@@ -146968,7 +146990,7 @@ var Identifier = class {
|
|
|
146968
146990
|
return `did:btcr2:${bech32m3.encodeFromBytes(hrp, dataBytes)}`;
|
|
146969
146991
|
}
|
|
146970
146992
|
/**
|
|
146971
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2/#
|
|
146993
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/#didbtcr2-identifier-decoding | 3.3 did:btcr2 Identifier Decoding}.
|
|
146972
146994
|
* @param {string} identifier The BTCR2 DID to be parsed
|
|
146973
146995
|
* @returns {DidComponents} The parsed identifier components. See {@link DidComponents} for details.
|
|
146974
146996
|
* @throws {DidError} if an error occurs while parsing the identifier
|
|
@@ -147037,7 +147059,7 @@ var Identifier = class {
|
|
|
147037
147059
|
const genesisBytes = dataBytes.slice(byteIndex + 1);
|
|
147038
147060
|
if (idType === "KEY") {
|
|
147039
147061
|
try {
|
|
147040
|
-
new
|
|
147062
|
+
new CompressedSecp256k1PublicKey(genesisBytes);
|
|
147041
147063
|
} catch {
|
|
147042
147064
|
throw new MethodError(`Invalid genesisBytes: ${genesisBytes}`, INVALID_DID, { identifier });
|
|
147043
147065
|
}
|
|
@@ -147062,7 +147084,7 @@ var Identifier = class {
|
|
|
147062
147084
|
|
|
147063
147085
|
// src/utils/did-document.ts
|
|
147064
147086
|
var BECH32M_CHARS = "";
|
|
147065
|
-
var
|
|
147087
|
+
var DID_REGEX = /did:btcr2:(x1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*)/g;
|
|
147066
147088
|
var DidVerificationMethod = class {
|
|
147067
147089
|
id;
|
|
147068
147090
|
type;
|
|
@@ -147345,7 +147367,7 @@ var DidDocument2 = class _DidDocument {
|
|
|
147345
147367
|
};
|
|
147346
147368
|
var IntermediateDidDocument = class _IntermediateDidDocument extends DidDocument2 {
|
|
147347
147369
|
constructor(document2) {
|
|
147348
|
-
const intermediateDocument = JSON.cloneReplace(document2,
|
|
147370
|
+
const intermediateDocument = JSON.cloneReplace(document2, DID_REGEX, ID_PLACEHOLDER_VALUE);
|
|
147349
147371
|
super(intermediateDocument);
|
|
147350
147372
|
}
|
|
147351
147373
|
/**
|
|
@@ -147398,7 +147420,7 @@ var Create = class {
|
|
|
147398
147420
|
const { version: version3 = 1, network = "bitcoin" } = options2;
|
|
147399
147421
|
const idType = IdentifierTypes.KEY;
|
|
147400
147422
|
const identifier = Identifier.encode({ version: version3, network, idType, genesisBytes: pubKeyBytes });
|
|
147401
|
-
const { compressed: publicKey2, multibase: publicKeyMultibase } = new
|
|
147423
|
+
const { compressed: publicKey2, multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey(pubKeyBytes);
|
|
147402
147424
|
const service = BeaconUtils.generateBeaconServices({
|
|
147403
147425
|
identifier,
|
|
147404
147426
|
publicKey: publicKey2,
|
|
@@ -147412,7 +147434,7 @@ var Create = class {
|
|
|
147412
147434
|
id: `${identifier}#initialKey`,
|
|
147413
147435
|
type: "Multikey",
|
|
147414
147436
|
controller: identifier,
|
|
147415
|
-
publicKeyMultibase: publicKeyMultibase.
|
|
147437
|
+
publicKeyMultibase: publicKeyMultibase.encoded
|
|
147416
147438
|
}],
|
|
147417
147439
|
service
|
|
147418
147440
|
});
|
|
@@ -147452,7 +147474,7 @@ init_shim();
|
|
|
147452
147474
|
|
|
147453
147475
|
// src/did-btcr2.ts
|
|
147454
147476
|
init_shim();
|
|
147455
|
-
var
|
|
147477
|
+
var tinysecp4 = __toESM(require_dist2(), 1);
|
|
147456
147478
|
|
|
147457
147479
|
// src/core/crud/read.ts
|
|
147458
147480
|
init_shim();
|
|
@@ -147472,7 +147494,7 @@ var Resolve = class {
|
|
|
147472
147494
|
*/
|
|
147473
147495
|
static deterministic({ identifier, identifierComponents }) {
|
|
147474
147496
|
const { network, genesisBytes } = identifierComponents;
|
|
147475
|
-
const { compressed: publicKey2, multibase: publicKeyMultibase } = new
|
|
147497
|
+
const { compressed: publicKey2, multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey(genesisBytes);
|
|
147476
147498
|
const service = BeaconUtils.generateBeaconServices({
|
|
147477
147499
|
identifier,
|
|
147478
147500
|
publicKey: publicKey2,
|
|
@@ -147486,7 +147508,7 @@ var Resolve = class {
|
|
|
147486
147508
|
id: `${identifier}#initialKey`,
|
|
147487
147509
|
type: "Multikey",
|
|
147488
147510
|
controller: identifier,
|
|
147489
|
-
publicKeyMultibase: publicKeyMultibase.
|
|
147511
|
+
publicKeyMultibase: publicKeyMultibase.encoded
|
|
147490
147512
|
}],
|
|
147491
147513
|
service
|
|
147492
147514
|
});
|
|
@@ -147622,7 +147644,7 @@ var Resolve = class {
|
|
|
147622
147644
|
targetVersionId,
|
|
147623
147645
|
targetTime,
|
|
147624
147646
|
didDocumentHistory: new Array(),
|
|
147625
|
-
|
|
147647
|
+
updateHashHistory: new Array(),
|
|
147626
147648
|
signalsMetadata,
|
|
147627
147649
|
network
|
|
147628
147650
|
});
|
|
@@ -147654,7 +147676,7 @@ var Resolve = class {
|
|
|
147654
147676
|
* @param {UnixTimestamp} params.targetTime The timestamp used to target specific historical states of a DID document.
|
|
147655
147677
|
* Only Beacon Signals included in the Bitcoin blockchain before the targetTime are processed.
|
|
147656
147678
|
* @param {boolean} params.didDocumentHistory An array of DID documents ordered ascensing by version (1...N).
|
|
147657
|
-
* @param {boolean} params.
|
|
147679
|
+
* @param {boolean} params.updateHashHistory An array of SHA256 hashes of BTCR2 Updates ordered by version that are
|
|
147658
147680
|
* applied to the DID document in order to construct the contemporaryDIDDocument.
|
|
147659
147681
|
* @param {SignalsMetadata} params.signalsMetadata See {@link SignalsMetadata} for details.
|
|
147660
147682
|
* @param {string} params.network The bitcoin network to connect to (mainnet, signet, testnet, regtest).
|
|
@@ -147667,7 +147689,7 @@ var Resolve = class {
|
|
|
147667
147689
|
targetVersionId,
|
|
147668
147690
|
targetTime,
|
|
147669
147691
|
didDocumentHistory,
|
|
147670
|
-
|
|
147692
|
+
updateHashHistory,
|
|
147671
147693
|
signalsMetadata,
|
|
147672
147694
|
network
|
|
147673
147695
|
}) {
|
|
@@ -147690,8 +147712,8 @@ var Resolve = class {
|
|
|
147690
147712
|
for (let update of orderedUpdates) {
|
|
147691
147713
|
const updateTargetVersionId = update.targetVersionId;
|
|
147692
147714
|
if (updateTargetVersionId <= currentVersionId) {
|
|
147693
|
-
|
|
147694
|
-
await this.confirmDuplicateUpdate({ update, updateHashHistory
|
|
147715
|
+
updateHashHistory.push(contemporaryHash);
|
|
147716
|
+
await this.confirmDuplicateUpdate({ update, updateHashHistory });
|
|
147695
147717
|
} else if (updateTargetVersionId === currentVersionId + 1) {
|
|
147696
147718
|
const sourceHash = update.sourceHash.startsWith("z") ? update.sourceHash : `z${update.sourceHash}`;
|
|
147697
147719
|
if (sourceHash !== contemporaryHash) {
|
|
@@ -147707,7 +147729,7 @@ var Resolve = class {
|
|
|
147707
147729
|
const unsecuredUpdate = update;
|
|
147708
147730
|
delete unsecuredUpdate.proof;
|
|
147709
147731
|
const updateHash = await JSON.canonicalization.process(update, "base58");
|
|
147710
|
-
|
|
147732
|
+
updateHashHistory.push(updateHash);
|
|
147711
147733
|
contemporaryHash = await JSON.canonicalization.process(contemporaryDidDocument, "base58");
|
|
147712
147734
|
} else if (update.targetVersionId > currentVersionId + 1) {
|
|
147713
147735
|
throw new ResolveError(
|
|
@@ -147893,12 +147915,12 @@ var Resolve = class {
|
|
|
147893
147915
|
const sidecar = { signalsMetadata };
|
|
147894
147916
|
const service = { id, type, serviceEndpoint: `bitcoin:${address}` };
|
|
147895
147917
|
const beacon = BeaconFactory.establish(service, sidecar);
|
|
147896
|
-
const
|
|
147897
|
-
if (!
|
|
147898
|
-
throw new MethodError("No
|
|
147918
|
+
const didUpdate = await beacon.processSignal(signalTx, signalsMetadata) ?? null;
|
|
147919
|
+
if (!didUpdate) {
|
|
147920
|
+
throw new MethodError("No didUpdate for beacon", "PROCESS_BEACON_SIGNALS_ERROR", { tx, signalsMetadata });
|
|
147899
147921
|
}
|
|
147900
|
-
updates.push(
|
|
147901
|
-
return
|
|
147922
|
+
updates.push(didUpdate);
|
|
147923
|
+
return didUpdate;
|
|
147902
147924
|
}
|
|
147903
147925
|
/**
|
|
147904
147926
|
* Implements {@link https://dcdpr.github.io/did-btcr2/#confirm-duplicate-update | 7.2.2.4 Confirm Duplicate Update}.
|
|
@@ -147913,7 +147935,7 @@ var Resolve = class {
|
|
|
147913
147935
|
* @param {DidUpdatePayload} params.update The DID Update Payload to confirm.
|
|
147914
147936
|
* @param {Array<string>} params.updateHashHistory The history of hashes for previously applied updates.
|
|
147915
147937
|
* @returns {Promise<void>} A promise that resolves if the update is a duplicate, otherwise throws an error.
|
|
147916
|
-
* @throws {
|
|
147938
|
+
* @throws {ResolveError} if the update hash does not match the historical hash.
|
|
147917
147939
|
*/
|
|
147918
147940
|
static async confirmDuplicateUpdate({ update, updateHashHistory }) {
|
|
147919
147941
|
const unsecuredUpdate = update;
|
|
@@ -148061,7 +148083,7 @@ var Update = class {
|
|
|
148061
148083
|
id,
|
|
148062
148084
|
controller,
|
|
148063
148085
|
keys: new SchnorrKeyPair({
|
|
148064
|
-
secretKey:
|
|
148086
|
+
secretKey: Secp256k1SecretKey.decode(secretKeyMultibase)
|
|
148065
148087
|
})
|
|
148066
148088
|
});
|
|
148067
148089
|
if (!multikey) {
|
|
@@ -148130,7 +148152,7 @@ var Update = class {
|
|
|
148130
148152
|
};
|
|
148131
148153
|
|
|
148132
148154
|
// src/did-btcr2.ts
|
|
148133
|
-
initEccLib(
|
|
148155
|
+
initEccLib(tinysecp4);
|
|
148134
148156
|
var DidBtcr2 = class {
|
|
148135
148157
|
/** @type {string} Name of the DID method, as defined in the DID BTCR2 specification */
|
|
148136
148158
|
static methodName = "btcr2";
|
|
@@ -148235,7 +148257,7 @@ var DidBtcr2 = class {
|
|
|
148235
148257
|
* @param {string} params.identifier The btcr2 identifier to be updated.
|
|
148236
148258
|
* @param {DidDocument} params.sourceDocument The DID document being updated.
|
|
148237
148259
|
* @param {string} params.sourceVersionId The versionId of the source document.
|
|
148238
|
-
* @param {
|
|
148260
|
+
* @param {PatchOperation} params.documentPatch The JSON patch to be applied to the source document.
|
|
148239
148261
|
* @param {string} params.verificationMethodId The verificationMethod ID to sign the update
|
|
148240
148262
|
* @param {string[]} params.beaconIds The beacon IDs to announce the update
|
|
148241
148263
|
* @returns {Promise<void>} Promise resolving to void
|
|
@@ -148303,7 +148325,7 @@ var DidBtcr2 = class {
|
|
|
148303
148325
|
};
|
|
148304
148326
|
|
|
148305
148327
|
// src/core/crud/deactivate.ts
|
|
148306
|
-
var
|
|
148328
|
+
var Deactivate = class extends DidBtcr2 {
|
|
148307
148329
|
};
|
|
148308
148330
|
|
|
148309
148331
|
// src/core/key-manager/interface.ts
|
|
@@ -148320,7 +148342,7 @@ init_shim();
|
|
|
148320
148342
|
|
|
148321
148343
|
// src/utils/did-document-builder.ts
|
|
148322
148344
|
init_shim();
|
|
148323
|
-
var
|
|
148345
|
+
var DidDocumentBuilder = class {
|
|
148324
148346
|
document = {};
|
|
148325
148347
|
constructor(initialDocument) {
|
|
148326
148348
|
if (!initialDocument.id) {
|
|
@@ -150886,16 +150908,16 @@ var GeneralUtils = class {
|
|
|
150886
150908
|
export {
|
|
150887
150909
|
Appendix,
|
|
150888
150910
|
BECH32M_CHARS,
|
|
150889
|
-
BTC1_DID_REGEX,
|
|
150890
150911
|
Beacon,
|
|
150891
150912
|
BeaconFactory,
|
|
150892
150913
|
BeaconUtils,
|
|
150893
|
-
Btc1Deactivate,
|
|
150894
|
-
Btc1DidDocumentBuilder,
|
|
150895
150914
|
CIDAggregateBeacon,
|
|
150896
150915
|
Create,
|
|
150916
|
+
DID_REGEX,
|
|
150917
|
+
Deactivate,
|
|
150897
150918
|
DidBtcr2,
|
|
150898
150919
|
DidDocument2 as DidDocument,
|
|
150920
|
+
DidDocumentBuilder,
|
|
150899
150921
|
DidVerificationMethod,
|
|
150900
150922
|
GeneralUtils,
|
|
150901
150923
|
Identifier,
|