@did-btcr2/api 0.4.0 → 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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.js +22152 -34966
- package/dist/browser.mjs +22152 -34966
- package/dist/cjs/index.js +168 -41
- package/dist/esm/api.js +11 -11
- package/dist/esm/api.js.map +1 -1
- package/dist/esm/cas.js +61 -4
- package/dist/esm/cas.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/{kms.js → key-manager.js} +21 -12
- package/dist/esm/key-manager.js.map +1 -0
- package/dist/esm/method.js +81 -20
- package/dist/esm/method.js.map +1 -1
- package/dist/types/api.d.ts +10 -5
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/cas.d.ts +34 -1
- package/dist/types/cas.d.ts.map +1 -1
- package/dist/types/crypto.d.ts +2 -2
- package/dist/types/crypto.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/{kms.d.ts → key-manager.d.ts} +19 -11
- package/dist/types/key-manager.d.ts.map +1 -0
- package/dist/types/method.d.ts +28 -12
- package/dist/types/method.d.ts.map +1 -1
- package/dist/types/types.d.ts +1 -8
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +9 -12
- package/src/api.ts +14 -13
- package/src/cas.ts +84 -5
- package/src/crypto.ts +2 -2
- package/src/index.ts +1 -1
- package/src/{kms.ts → key-manager.ts} +25 -16
- package/src/method.ts +98 -22
- package/src/types.ts +1 -8
- package/dist/esm/kms.js.map +0 -1
- package/dist/types/kms.d.ts.map +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -34,12 +34,15 @@ __export(index_exports, {
|
|
|
34
34
|
CasApi: () => CasApi,
|
|
35
35
|
CryptoApi: () => CryptoApi,
|
|
36
36
|
CryptosuiteApi: () => CryptosuiteApi,
|
|
37
|
+
DEFAULT_CAS_GATEWAY: () => DEFAULT_CAS_GATEWAY,
|
|
38
|
+
DEFAULT_CAS_TIMEOUT_MS: () => DEFAULT_CAS_TIMEOUT_MS,
|
|
37
39
|
DataIntegrityProofApi: () => DataIntegrityProofApi,
|
|
38
40
|
DidApi: () => DidApi,
|
|
39
41
|
DidBtcr2Api: () => DidBtcr2Api,
|
|
40
42
|
DidDocument: () => import_method4.DidDocument,
|
|
41
43
|
DidDocumentBuilder: () => import_method4.DidDocumentBuilder,
|
|
42
44
|
DidMethodApi: () => DidMethodApi,
|
|
45
|
+
HttpGatewayCasExecutor: () => HttpGatewayCasExecutor,
|
|
43
46
|
Identifier: () => import_method4.Identifier,
|
|
44
47
|
IdentifierTypes: () => import_common4.IdentifierTypes,
|
|
45
48
|
IpfsCasExecutor: () => IpfsCasExecutor,
|
|
@@ -1129,6 +1132,7 @@ var sha512 = from2({
|
|
|
1129
1132
|
});
|
|
1130
1133
|
|
|
1131
1134
|
// src/cas.ts
|
|
1135
|
+
var DEFAULT_CAS_GATEWAY = "https://ipfs.io";
|
|
1132
1136
|
var IpfsCasExecutor = class {
|
|
1133
1137
|
#helia;
|
|
1134
1138
|
constructor(helia) {
|
|
@@ -1150,18 +1154,47 @@ var IpfsCasExecutor = class {
|
|
|
1150
1154
|
return btoa(String.fromCharCode(...digest.bytes.slice(2))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
1151
1155
|
}
|
|
1152
1156
|
};
|
|
1157
|
+
var HttpGatewayCasExecutor = class {
|
|
1158
|
+
#gatewayUrl;
|
|
1159
|
+
constructor(gatewayUrl) {
|
|
1160
|
+
this.#gatewayUrl = gatewayUrl.replace(/\/+$/, "");
|
|
1161
|
+
}
|
|
1162
|
+
async retrieve(hash) {
|
|
1163
|
+
const hashBytes = (0, import_common.decode)(hash, "base64urlnopad");
|
|
1164
|
+
const cid = CID.create(1, code, create(sha256.code, hashBytes));
|
|
1165
|
+
try {
|
|
1166
|
+
const res = await fetch(`${this.#gatewayUrl}/ipfs/${cid.toString()}?format=raw`, {
|
|
1167
|
+
headers: { Accept: "application/vnd.ipld.raw" }
|
|
1168
|
+
});
|
|
1169
|
+
if (!res.ok) return null;
|
|
1170
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
1171
|
+
} catch {
|
|
1172
|
+
return null;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
async publish() {
|
|
1176
|
+
throw new Error(
|
|
1177
|
+
"HttpGatewayCasExecutor is read-only. Publishing requires a full IPFS node (use IpfsCasExecutor with Helia)."
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
var DEFAULT_CAS_TIMEOUT_MS = 3e4;
|
|
1153
1182
|
var CasApi = class {
|
|
1154
1183
|
#executor;
|
|
1184
|
+
#timeoutMs;
|
|
1155
1185
|
constructor(config) {
|
|
1156
1186
|
if (config.executor) {
|
|
1157
1187
|
this.#executor = config.executor;
|
|
1158
1188
|
} else if (config.helia) {
|
|
1159
1189
|
this.#executor = new IpfsCasExecutor(config.helia);
|
|
1190
|
+
} else if (config.gateway) {
|
|
1191
|
+
this.#executor = new HttpGatewayCasExecutor(config.gateway);
|
|
1160
1192
|
} else {
|
|
1161
1193
|
throw new Error(
|
|
1162
|
-
"CAS configuration requires
|
|
1194
|
+
"CAS configuration requires an executor, Helia instance, or gateway URL. Example: createApi({ cas: { gateway: 'https://ipfs.io' } })"
|
|
1163
1195
|
);
|
|
1164
1196
|
}
|
|
1197
|
+
this.#timeoutMs = config.timeoutMs ?? DEFAULT_CAS_TIMEOUT_MS;
|
|
1165
1198
|
}
|
|
1166
1199
|
/**
|
|
1167
1200
|
* Retrieve a JSON object from the CAS by its SHA-256 hash bytes.
|
|
@@ -1170,7 +1203,7 @@ var CasApi = class {
|
|
|
1170
1203
|
*/
|
|
1171
1204
|
async retrieve(hashBytes) {
|
|
1172
1205
|
const hash = (0, import_common.encode)(hashBytes, "base64urlnopad");
|
|
1173
|
-
const bytes = await this.#executor.retrieve(hash);
|
|
1206
|
+
const bytes = await this.#withTimeout(this.#executor.retrieve(hash));
|
|
1174
1207
|
if (!bytes) return null;
|
|
1175
1208
|
return JSON.parse(new TextDecoder().decode(bytes));
|
|
1176
1209
|
}
|
|
@@ -1183,18 +1216,40 @@ var CasApi = class {
|
|
|
1183
1216
|
*/
|
|
1184
1217
|
async publish(object) {
|
|
1185
1218
|
const bytes = new TextEncoder().encode((0, import_common.canonicalize)(object));
|
|
1186
|
-
return await this.#executor.publish(bytes);
|
|
1219
|
+
return await this.#withTimeout(this.#executor.publish(bytes));
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Wraps a promise with a timeout. If `#timeoutMs` is 0, no timeout is applied.
|
|
1223
|
+
*/
|
|
1224
|
+
#withTimeout(promise) {
|
|
1225
|
+
if (!this.#timeoutMs) return promise;
|
|
1226
|
+
return new Promise((resolve, reject) => {
|
|
1227
|
+
const timer = setTimeout(
|
|
1228
|
+
() => reject(new Error(`CAS operation timed out after ${this.#timeoutMs}ms`)),
|
|
1229
|
+
this.#timeoutMs
|
|
1230
|
+
);
|
|
1231
|
+
promise.then(
|
|
1232
|
+
(val) => {
|
|
1233
|
+
clearTimeout(timer);
|
|
1234
|
+
resolve(val);
|
|
1235
|
+
},
|
|
1236
|
+
(err) => {
|
|
1237
|
+
clearTimeout(timer);
|
|
1238
|
+
reject(err);
|
|
1239
|
+
}
|
|
1240
|
+
);
|
|
1241
|
+
});
|
|
1187
1242
|
}
|
|
1188
1243
|
};
|
|
1189
1244
|
|
|
1190
|
-
// src/
|
|
1191
|
-
var
|
|
1245
|
+
// src/key-manager.ts
|
|
1246
|
+
var import_key_manager = require("@did-btcr2/key-manager");
|
|
1192
1247
|
var KeyManagerApi = class {
|
|
1193
1248
|
/** The backing KeyManager instance. */
|
|
1194
1249
|
kms;
|
|
1195
1250
|
/** Create a new KeyManagerApi, optionally backed by a custom KeyManager. */
|
|
1196
1251
|
constructor(kms) {
|
|
1197
|
-
this.kms = kms ?? new
|
|
1252
|
+
this.kms = kms ?? new import_key_manager.LocalKeyManager();
|
|
1198
1253
|
}
|
|
1199
1254
|
/** Generate a new key directly in the KMS. */
|
|
1200
1255
|
generateKey(options) {
|
|
@@ -1214,13 +1269,17 @@ var KeyManagerApi = class {
|
|
|
1214
1269
|
}
|
|
1215
1270
|
/**
|
|
1216
1271
|
* Export a Schnorr keypair from the KMS.
|
|
1217
|
-
*
|
|
1218
|
-
*
|
|
1272
|
+
* Routes through the KeyManager's declared capability (`canExport`) rather
|
|
1273
|
+
* than an `instanceof LocalKeyManager` check, so third-party adapters can
|
|
1274
|
+
* opt in to export support without coupling to a specific implementation.
|
|
1275
|
+
* External adapters (AWS, Vault, HSM) typically advertise `canExport: false`.
|
|
1276
|
+
* @throws {Error} If the backing KeyManager does not advertise canExport=true,
|
|
1277
|
+
* or omits the optional `exportKey` method.
|
|
1219
1278
|
*/
|
|
1220
1279
|
export(id) {
|
|
1221
|
-
if (!
|
|
1280
|
+
if (!this.kms.canExport || !this.kms.exportKey) {
|
|
1222
1281
|
throw new Error(
|
|
1223
|
-
"Key export is not supported by the current KeyManager implementation.
|
|
1282
|
+
"Key export is not supported by the current KeyManager implementation. The adapter must advertise `canExport: true` and provide an `exportKey` method."
|
|
1224
1283
|
);
|
|
1225
1284
|
}
|
|
1226
1285
|
return this.kms.exportKey(id);
|
|
@@ -1237,13 +1296,13 @@ var KeyManagerApi = class {
|
|
|
1237
1296
|
* Sign data via the KMS.
|
|
1238
1297
|
* @param data The data to sign (must be non-empty).
|
|
1239
1298
|
* @param id Optional key identifier; uses the active key if omitted.
|
|
1240
|
-
* @param options Signing options
|
|
1299
|
+
* @param options Signing options. Defaults: `scheme: 'bip340'`.
|
|
1241
1300
|
*/
|
|
1242
1301
|
sign(data, id, options) {
|
|
1243
1302
|
assertBytes(data, "data");
|
|
1244
1303
|
return this.kms.sign(data, id, options);
|
|
1245
1304
|
}
|
|
1246
|
-
/** Verify a signature via the KMS. */
|
|
1305
|
+
/** Verify a signature via the KMS. Defaults: `scheme: 'bip340'`. */
|
|
1247
1306
|
verify(signature, data, id, options) {
|
|
1248
1307
|
return this.kms.verify(signature, data, id, options);
|
|
1249
1308
|
}
|
|
@@ -1837,8 +1896,16 @@ var DidMethodApi = class {
|
|
|
1837
1896
|
}
|
|
1838
1897
|
}
|
|
1839
1898
|
/**
|
|
1840
|
-
* Update an existing DID document
|
|
1841
|
-
*
|
|
1899
|
+
* Update an existing DID document by driving the sans-I/O {@link Updater} state
|
|
1900
|
+
* machine (from @did-btcr2/method). This method handles the I/O side:
|
|
1901
|
+
* - Signing: supplies the {@link Signer} to `NeedSigningKey`.
|
|
1902
|
+
* - Broadcast: establishes a beacon via {@link BeaconFactory} and calls
|
|
1903
|
+
* `broadcastSignal()` with the bitcoin connection configured on the API.
|
|
1904
|
+
*
|
|
1905
|
+
* For multi-party aggregation of SMT/CAS beacons, the caller should drive the
|
|
1906
|
+
* Updater directly and delegate `NeedBroadcast` to the aggregation runner
|
|
1907
|
+
* rather than using this high-level method.
|
|
1908
|
+
*
|
|
1842
1909
|
* @param params The update parameters.
|
|
1843
1910
|
* @returns The signed update.
|
|
1844
1911
|
*/
|
|
@@ -1848,19 +1915,64 @@ var DidMethodApi = class {
|
|
|
1848
1915
|
sourceVersionId,
|
|
1849
1916
|
verificationMethodId,
|
|
1850
1917
|
beaconId,
|
|
1851
|
-
|
|
1918
|
+
signer,
|
|
1852
1919
|
bitcoin
|
|
1853
1920
|
}) {
|
|
1854
|
-
const btcConnection = bitcoin ?? this.#btc?.connection
|
|
1855
|
-
|
|
1921
|
+
const btcConnection = bitcoin ?? this.#btc?.connection;
|
|
1922
|
+
if (!btcConnection) {
|
|
1923
|
+
throw new import_common3.UpdateError(
|
|
1924
|
+
"Bitcoin connection required for update. Pass a configured `bitcoin` parameter or configure a BitcoinApi on the DidBtcr2Api instance.",
|
|
1925
|
+
import_common3.INVALID_DID_UPDATE,
|
|
1926
|
+
{ beaconId }
|
|
1927
|
+
);
|
|
1928
|
+
}
|
|
1929
|
+
this.#log.debug("Updating DID", sourceDocument.id, { beaconId, verificationMethodId });
|
|
1930
|
+
const updater = import_method2.DidBtcr2.update({
|
|
1856
1931
|
sourceDocument,
|
|
1857
1932
|
patches,
|
|
1858
1933
|
sourceVersionId,
|
|
1859
1934
|
verificationMethodId,
|
|
1860
|
-
beaconId
|
|
1861
|
-
signingMaterial,
|
|
1862
|
-
bitcoin: btcConnection
|
|
1935
|
+
beaconId
|
|
1863
1936
|
});
|
|
1937
|
+
let state = updater.advance();
|
|
1938
|
+
while (state.status === "action-required") {
|
|
1939
|
+
for (const need of state.needs) {
|
|
1940
|
+
switch (need.kind) {
|
|
1941
|
+
case "NeedSigningKey": {
|
|
1942
|
+
this.#log.debug("Providing signer for", need.verificationMethodId);
|
|
1943
|
+
updater.provide(need, signer);
|
|
1944
|
+
break;
|
|
1945
|
+
}
|
|
1946
|
+
case "NeedFunding": {
|
|
1947
|
+
this.#log.debug("Checking funding for beacon address %s", need.beaconAddress);
|
|
1948
|
+
const utxos = await btcConnection.rest.address.getUtxos(need.beaconAddress);
|
|
1949
|
+
if (!utxos.length) {
|
|
1950
|
+
throw new import_common3.UpdateError(
|
|
1951
|
+
`Beacon address ${need.beaconAddress} is unfunded. Send BTC to this address before broadcasting the update.`,
|
|
1952
|
+
import_common3.INVALID_DID_UPDATE,
|
|
1953
|
+
{ beaconAddress: need.beaconAddress }
|
|
1954
|
+
);
|
|
1955
|
+
}
|
|
1956
|
+
this.#log.debug("Beacon address funded (%d UTXOs)", utxos.length);
|
|
1957
|
+
updater.provide(need);
|
|
1958
|
+
break;
|
|
1959
|
+
}
|
|
1960
|
+
case "NeedBroadcast": {
|
|
1961
|
+
this.#log.debug(
|
|
1962
|
+
"Broadcasting signed update via %s beacon",
|
|
1963
|
+
need.beaconService.type
|
|
1964
|
+
);
|
|
1965
|
+
const beacon = import_method2.BeaconFactory.establish(need.beaconService);
|
|
1966
|
+
await beacon.broadcastSignal(need.signedUpdate, signer, btcConnection);
|
|
1967
|
+
updater.provide(need);
|
|
1968
|
+
break;
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
state = updater.advance();
|
|
1973
|
+
}
|
|
1974
|
+
this.#log.debug("DID update complete", sourceDocument.id);
|
|
1975
|
+
return state.result.signedUpdate;
|
|
1864
1976
|
}
|
|
1865
1977
|
/**
|
|
1866
1978
|
* Get the signing method from a DID document by method ID.
|
|
@@ -1882,8 +1994,9 @@ var DidMethodApi = class {
|
|
|
1882
1994
|
* .buildUpdate(currentDoc)
|
|
1883
1995
|
* .patch({ op: 'add', path: '/service/1', value: newService })
|
|
1884
1996
|
* .version(2)
|
|
1885
|
-
* .
|
|
1997
|
+
* .verificationMethodId('#initialKey')
|
|
1886
1998
|
* .beacon('#beacon-0')
|
|
1999
|
+
* .signer(new LocalSigner(secretKey))
|
|
1887
2000
|
* .execute();
|
|
1888
2001
|
* ```
|
|
1889
2002
|
*/
|
|
@@ -1908,7 +2021,7 @@ var UpdateBuilder = class {
|
|
|
1908
2021
|
#sourceVersionId;
|
|
1909
2022
|
#verificationMethodId;
|
|
1910
2023
|
#beaconId;
|
|
1911
|
-
#
|
|
2024
|
+
#signer;
|
|
1912
2025
|
#bitcoin;
|
|
1913
2026
|
/** @internal */
|
|
1914
2027
|
constructor(methodApi, sourceDocument) {
|
|
@@ -1930,8 +2043,8 @@ var UpdateBuilder = class {
|
|
|
1930
2043
|
this.#sourceVersionId = id;
|
|
1931
2044
|
return this;
|
|
1932
2045
|
}
|
|
1933
|
-
/** Set the verification method ID used for signing. */
|
|
1934
|
-
|
|
2046
|
+
/** Set the verification method ID used for signing the update. */
|
|
2047
|
+
verificationMethodId(methodId) {
|
|
1935
2048
|
this.#verificationMethodId = methodId;
|
|
1936
2049
|
return this;
|
|
1937
2050
|
}
|
|
@@ -1940,37 +2053,48 @@ var UpdateBuilder = class {
|
|
|
1940
2053
|
this.#beaconId = beaconId;
|
|
1941
2054
|
return this;
|
|
1942
2055
|
}
|
|
1943
|
-
/**
|
|
1944
|
-
|
|
1945
|
-
|
|
2056
|
+
/**
|
|
2057
|
+
* Set the {@link Signer} that produces the update's BIP-340 Schnorr proof
|
|
2058
|
+
* and the beacon transaction's ECDSA input signature. Use `LocalSigner`
|
|
2059
|
+
* for in-process secret keys, `KeyManagerSigner` for KMS-managed keys
|
|
2060
|
+
* (AWS, Vault, HSM, etc.), or any custom adapter implementing the `Signer`
|
|
2061
|
+
* interface.
|
|
2062
|
+
*/
|
|
2063
|
+
signer(s) {
|
|
2064
|
+
this.#signer = s;
|
|
1946
2065
|
return this;
|
|
1947
2066
|
}
|
|
1948
2067
|
/** Override the Bitcoin connection for this update. */
|
|
1949
|
-
|
|
2068
|
+
bitcoin(connection) {
|
|
1950
2069
|
this.#bitcoin = connection;
|
|
1951
2070
|
return this;
|
|
1952
2071
|
}
|
|
1953
2072
|
/**
|
|
1954
2073
|
* Execute the update.
|
|
1955
|
-
* @throws {Error} If required fields (version,
|
|
2074
|
+
* @throws {Error} If required fields (version, verificationMethodId, beacon, signer) are missing.
|
|
1956
2075
|
*/
|
|
1957
2076
|
async execute() {
|
|
1958
2077
|
if (this.#sourceVersionId === void 0) {
|
|
1959
2078
|
throw new Error("UpdateBuilder: sourceVersionId is required. Call .version(id) before .execute().");
|
|
1960
2079
|
}
|
|
1961
2080
|
if (!this.#verificationMethodId) {
|
|
1962
|
-
throw new Error(
|
|
2081
|
+
throw new Error(
|
|
2082
|
+
"UpdateBuilder: verificationMethodId is required. Call .verificationMethodId(id) before .execute()."
|
|
2083
|
+
);
|
|
1963
2084
|
}
|
|
1964
2085
|
if (!this.#beaconId) {
|
|
1965
2086
|
throw new Error("UpdateBuilder: beaconId is required. Call .beacon(id) before .execute().");
|
|
1966
2087
|
}
|
|
2088
|
+
if (!this.#signer) {
|
|
2089
|
+
throw new Error("UpdateBuilder: signer is required. Call .signer(s) before .execute().");
|
|
2090
|
+
}
|
|
1967
2091
|
return this.#methodApi.update({
|
|
1968
2092
|
sourceDocument: this.#sourceDocument,
|
|
1969
2093
|
patches: this.#patches,
|
|
1970
2094
|
sourceVersionId: this.#sourceVersionId,
|
|
1971
2095
|
verificationMethodId: this.#verificationMethodId,
|
|
1972
2096
|
beaconId: this.#beaconId,
|
|
1973
|
-
|
|
2097
|
+
signer: this.#signer,
|
|
1974
2098
|
bitcoin: this.#bitcoin
|
|
1975
2099
|
});
|
|
1976
2100
|
}
|
|
@@ -2019,18 +2143,16 @@ var DidBtcr2Api = class {
|
|
|
2019
2143
|
}
|
|
2020
2144
|
/**
|
|
2021
2145
|
* CAS API sub-facade (lazily initialized).
|
|
2022
|
-
*
|
|
2023
|
-
*
|
|
2146
|
+
*
|
|
2147
|
+
* When no `cas` config was provided to the constructor, defaults to a
|
|
2148
|
+
* read-only {@link HttpGatewayCasExecutor} backed by the public IPFS
|
|
2149
|
+
* gateway (`https://ipfs.io`). Override via `createApi({ cas: { ... } })`.
|
|
2150
|
+
* @throws {Error} If the instance has been disposed.
|
|
2024
2151
|
*/
|
|
2025
2152
|
get cas() {
|
|
2026
2153
|
this.#assertNotDisposed();
|
|
2027
2154
|
if (!this.#cas) {
|
|
2028
|
-
|
|
2029
|
-
throw new Error(
|
|
2030
|
-
"CAS not configured. Pass a cas config to createApi(), e.g.: createApi({ cas: { helia: await createHelia() } })"
|
|
2031
|
-
);
|
|
2032
|
-
}
|
|
2033
|
-
this.#cas = new CasApi(this.#casConfig);
|
|
2155
|
+
this.#cas = new CasApi(this.#casConfig ?? { gateway: DEFAULT_CAS_GATEWAY });
|
|
2034
2156
|
}
|
|
2035
2157
|
return this.#cas;
|
|
2036
2158
|
}
|
|
@@ -2043,7 +2165,7 @@ var DidBtcr2Api = class {
|
|
|
2043
2165
|
if (!this.#btcr2) {
|
|
2044
2166
|
this.#btcr2 = new DidMethodApi(
|
|
2045
2167
|
this.#btcConfig ? this.btc : void 0,
|
|
2046
|
-
this
|
|
2168
|
+
this.cas,
|
|
2047
2169
|
this.#log
|
|
2048
2170
|
);
|
|
2049
2171
|
}
|
|
@@ -2145,6 +2267,7 @@ var DidBtcr2Api = class {
|
|
|
2145
2267
|
patches,
|
|
2146
2268
|
verificationMethodId,
|
|
2147
2269
|
beaconId,
|
|
2270
|
+
signer,
|
|
2148
2271
|
sourceDocument,
|
|
2149
2272
|
sourceVersionId
|
|
2150
2273
|
}) {
|
|
@@ -2185,7 +2308,8 @@ var DidBtcr2Api = class {
|
|
|
2185
2308
|
patches,
|
|
2186
2309
|
sourceVersionId: versionId,
|
|
2187
2310
|
verificationMethodId,
|
|
2188
|
-
beaconId
|
|
2311
|
+
beaconId,
|
|
2312
|
+
signer
|
|
2189
2313
|
});
|
|
2190
2314
|
}
|
|
2191
2315
|
/**
|
|
@@ -2218,12 +2342,15 @@ function createApi(config) {
|
|
|
2218
2342
|
CasApi,
|
|
2219
2343
|
CryptoApi,
|
|
2220
2344
|
CryptosuiteApi,
|
|
2345
|
+
DEFAULT_CAS_GATEWAY,
|
|
2346
|
+
DEFAULT_CAS_TIMEOUT_MS,
|
|
2221
2347
|
DataIntegrityProofApi,
|
|
2222
2348
|
DidApi,
|
|
2223
2349
|
DidBtcr2Api,
|
|
2224
2350
|
DidDocument,
|
|
2225
2351
|
DidDocumentBuilder,
|
|
2226
2352
|
DidMethodApi,
|
|
2353
|
+
HttpGatewayCasExecutor,
|
|
2227
2354
|
Identifier,
|
|
2228
2355
|
IdentifierTypes,
|
|
2229
2356
|
IpfsCasExecutor,
|
package/dist/esm/api.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
2
2
|
import { BitcoinApi } from './bitcoin.js';
|
|
3
|
-
import { CasApi } from './cas.js';
|
|
3
|
+
import { CasApi, DEFAULT_CAS_GATEWAY } from './cas.js';
|
|
4
4
|
import { CryptoApi } from './crypto.js';
|
|
5
5
|
import { DidApi } from './did.js';
|
|
6
6
|
import { assertString, NOOP_LOGGER } from './helpers.js';
|
|
7
|
-
import { KeyManagerApi } from './
|
|
7
|
+
import { KeyManagerApi } from './key-manager.js';
|
|
8
8
|
import { DidMethodApi } from './method.js';
|
|
9
9
|
/**
|
|
10
10
|
* Main DidBtcr2Api facade — the primary entry point for the SDK.
|
|
@@ -53,17 +53,16 @@ export class DidBtcr2Api {
|
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* CAS API sub-facade (lazily initialized).
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
*
|
|
57
|
+
* When no `cas` config was provided to the constructor, defaults to a
|
|
58
|
+
* read-only {@link HttpGatewayCasExecutor} backed by the public IPFS
|
|
59
|
+
* gateway (`https://ipfs.io`). Override via `createApi({ cas: { ... } })`.
|
|
60
|
+
* @throws {Error} If the instance has been disposed.
|
|
58
61
|
*/
|
|
59
62
|
get cas() {
|
|
60
63
|
this.#assertNotDisposed();
|
|
61
64
|
if (!this.#cas) {
|
|
62
|
-
|
|
63
|
-
throw new Error('CAS not configured. Pass a cas config to createApi(), e.g.: '
|
|
64
|
-
+ 'createApi({ cas: { helia: await createHelia() } })');
|
|
65
|
-
}
|
|
66
|
-
this.#cas = new CasApi(this.#casConfig);
|
|
65
|
+
this.#cas = new CasApi(this.#casConfig ?? { gateway: DEFAULT_CAS_GATEWAY });
|
|
67
66
|
}
|
|
68
67
|
return this.#cas;
|
|
69
68
|
}
|
|
@@ -74,7 +73,7 @@ export class DidBtcr2Api {
|
|
|
74
73
|
get btcr2() {
|
|
75
74
|
this.#assertNotDisposed();
|
|
76
75
|
if (!this.#btcr2) {
|
|
77
|
-
this.#btcr2 = new DidMethodApi(this.#btcConfig ? this.btc : undefined, this
|
|
76
|
+
this.#btcr2 = new DidMethodApi(this.#btcConfig ? this.btc : undefined, this.cas, this.#log);
|
|
78
77
|
}
|
|
79
78
|
return this.#btcr2;
|
|
80
79
|
}
|
|
@@ -172,7 +171,7 @@ export class DidBtcr2Api {
|
|
|
172
171
|
* @param params The update parameters.
|
|
173
172
|
* @returns The signed update.
|
|
174
173
|
*/
|
|
175
|
-
async updateDid({ did, patches, verificationMethodId, beaconId, sourceDocument, sourceVersionId, }) {
|
|
174
|
+
async updateDid({ did, patches, verificationMethodId, beaconId, signer, sourceDocument, sourceVersionId, }) {
|
|
176
175
|
this.#assertNotDisposed();
|
|
177
176
|
assertString(did, 'did');
|
|
178
177
|
let doc = sourceDocument;
|
|
@@ -205,6 +204,7 @@ export class DidBtcr2Api {
|
|
|
205
204
|
sourceVersionId: versionId,
|
|
206
205
|
verificationMethodId,
|
|
207
206
|
beaconId,
|
|
207
|
+
signer,
|
|
208
208
|
});
|
|
209
209
|
}
|
|
210
210
|
/**
|
package/dist/esm/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAkB,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C;;;;;;GAMG;AACH,MAAM,OAAO,WAAW;IACtB,wEAAwE;IAC/D,MAAM,CAAY;IAC3B,mEAAmE;IAC1D,GAAG,CAAS;IACrB,iCAAiC;IACxB,GAAG,CAAgB;IAE5B,UAAU,CAAoB;IAC9B,IAAI,CAAc;IAClB,UAAU,CAAa;IACvB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;oBAC7B,MAAM,IAAI,KAAK,CACb,qBAAqB,GAAG,sCAAsC,MAAM,CAAC,YAAY,CAAC,GAAG,CACtF,CAAC;gBACJ,CAAC;gBACD,SAAS,GAAG,MAAM,CAAC;YACrB,CAAC;QACH,CAAC;QAED,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YAC7B,cAAc,EAAM,GAAG;YACvB,OAAO;YACP,eAAe,EAAK,SAAS;YAC7B,oBAAoB;YACpB,QAAQ;YACR,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,OAAO;QACL,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAED,kBAAkB;QAChB,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;QAC5F,CAAC;IACH,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,MAAkB;IAC1C,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC"}
|
package/dist/esm/cas.js
CHANGED
|
@@ -3,6 +3,8 @@ import { CID } from 'multiformats/cid';
|
|
|
3
3
|
import * as raw from 'multiformats/codecs/raw';
|
|
4
4
|
import { create as createDigest } from 'multiformats/hashes/digest';
|
|
5
5
|
import { sha256 } from 'multiformats/hashes/sha2';
|
|
6
|
+
/** Default IPFS HTTP gateway used for CAS reads when no CAS config is provided. */
|
|
7
|
+
export const DEFAULT_CAS_GATEWAY = 'https://ipfs.io';
|
|
6
8
|
/**
|
|
7
9
|
* Default {@link CasExecutor} backed by IPFS via Helia.
|
|
8
10
|
*
|
|
@@ -35,6 +37,45 @@ export class IpfsCasExecutor {
|
|
|
35
37
|
.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
36
38
|
}
|
|
37
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Read-only {@link CasExecutor} backed by an IPFS HTTP gateway.
|
|
42
|
+
*
|
|
43
|
+
* Converts the base64url SHA-256 hash to a CIDv1 (raw codec) and fetches
|
|
44
|
+
* the raw block via the
|
|
45
|
+
* {@link https://specs.ipfs.tech/http-gateways/trustless-gateway/ | Trustless Gateway}
|
|
46
|
+
* protocol.
|
|
47
|
+
*
|
|
48
|
+
* Publishing is not supported — use {@link IpfsCasExecutor} with a Helia
|
|
49
|
+
* instance for writes.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export class HttpGatewayCasExecutor {
|
|
53
|
+
#gatewayUrl;
|
|
54
|
+
constructor(gatewayUrl) {
|
|
55
|
+
this.#gatewayUrl = gatewayUrl.replace(/\/+$/, '');
|
|
56
|
+
}
|
|
57
|
+
async retrieve(hash) {
|
|
58
|
+
const hashBytes = decodeHash(hash, 'base64urlnopad');
|
|
59
|
+
const cid = CID.create(1, raw.code, createDigest(sha256.code, hashBytes));
|
|
60
|
+
try {
|
|
61
|
+
const res = await fetch(`${this.#gatewayUrl}/ipfs/${cid.toString()}?format=raw`, {
|
|
62
|
+
headers: { Accept: 'application/vnd.ipld.raw' },
|
|
63
|
+
});
|
|
64
|
+
if (!res.ok)
|
|
65
|
+
return null;
|
|
66
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async publish() {
|
|
73
|
+
throw new Error('HttpGatewayCasExecutor is read-only. '
|
|
74
|
+
+ 'Publishing requires a full IPFS node (use IpfsCasExecutor with Helia).');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** Default timeout (ms) for CAS operations. */
|
|
78
|
+
export const DEFAULT_CAS_TIMEOUT_MS = 30_000;
|
|
38
79
|
/**
|
|
39
80
|
* Content-Addressed Storage API sub-facade.
|
|
40
81
|
*
|
|
@@ -50,6 +91,7 @@ export class IpfsCasExecutor {
|
|
|
50
91
|
*/
|
|
51
92
|
export class CasApi {
|
|
52
93
|
#executor;
|
|
94
|
+
#timeoutMs;
|
|
53
95
|
constructor(config) {
|
|
54
96
|
if (config.executor) {
|
|
55
97
|
this.#executor = config.executor;
|
|
@@ -57,10 +99,14 @@ export class CasApi {
|
|
|
57
99
|
else if (config.helia) {
|
|
58
100
|
this.#executor = new IpfsCasExecutor(config.helia);
|
|
59
101
|
}
|
|
102
|
+
else if (config.gateway) {
|
|
103
|
+
this.#executor = new HttpGatewayCasExecutor(config.gateway);
|
|
104
|
+
}
|
|
60
105
|
else {
|
|
61
|
-
throw new Error('CAS configuration requires
|
|
62
|
-
+ 'Example: createApi({ cas: {
|
|
106
|
+
throw new Error('CAS configuration requires an executor, Helia instance, or gateway URL. '
|
|
107
|
+
+ 'Example: createApi({ cas: { gateway: \'https://ipfs.io\' } })');
|
|
63
108
|
}
|
|
109
|
+
this.#timeoutMs = config.timeoutMs ?? DEFAULT_CAS_TIMEOUT_MS;
|
|
64
110
|
}
|
|
65
111
|
/**
|
|
66
112
|
* Retrieve a JSON object from the CAS by its SHA-256 hash bytes.
|
|
@@ -69,7 +115,7 @@ export class CasApi {
|
|
|
69
115
|
*/
|
|
70
116
|
async retrieve(hashBytes) {
|
|
71
117
|
const hash = encodeHash(hashBytes, 'base64urlnopad');
|
|
72
|
-
const bytes = await this.#executor.retrieve(hash);
|
|
118
|
+
const bytes = await this.#withTimeout(this.#executor.retrieve(hash));
|
|
73
119
|
if (!bytes)
|
|
74
120
|
return null;
|
|
75
121
|
return JSON.parse(new TextDecoder().decode(bytes));
|
|
@@ -83,7 +129,18 @@ export class CasApi {
|
|
|
83
129
|
*/
|
|
84
130
|
async publish(object) {
|
|
85
131
|
const bytes = new TextEncoder().encode(canonicalize(object));
|
|
86
|
-
return await this.#executor.publish(bytes);
|
|
132
|
+
return await this.#withTimeout(this.#executor.publish(bytes));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Wraps a promise with a timeout. If `#timeoutMs` is 0, no timeout is applied.
|
|
136
|
+
*/
|
|
137
|
+
#withTimeout(promise) {
|
|
138
|
+
if (!this.#timeoutMs)
|
|
139
|
+
return promise;
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
const timer = setTimeout(() => reject(new Error(`CAS operation timed out after ${this.#timeoutMs}ms`)), this.#timeoutMs);
|
|
142
|
+
promise.then((val) => { clearTimeout(timer); resolve(val); }, (err) => { clearTimeout(timer); reject(err); });
|
|
143
|
+
});
|
|
87
144
|
}
|
|
88
145
|
}
|
|
89
146
|
//# sourceMappingURL=cas.js.map
|
package/dist/esm/cas.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cas.js","sourceRoot":"","sources":["../../src/cas.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE7F,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"cas.js","sourceRoot":"","sources":["../../src/cas.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE7F,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,GAAG,MA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jC,IAAI,CAAC,IAAI,CAAC,UAAU;YAAE,OAAO,OAAO,CAAC;QACrC,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxC,MAAM,KAAK,GAAG,UAAU,CACtB,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,iCAAiC,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,EAC7E,IAAI,CAAC,UAAU,CAChB,CAAC;YACF,OAAO,CAAC,IAAI,CACV,CAAC,GAAG,EAAE,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAC/C,CAAC,GAAG,EAAE,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAC/C,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/esm/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export * from './types.js';
|
|
|
6
6
|
export * from './helpers.js';
|
|
7
7
|
export * from './bitcoin.js';
|
|
8
8
|
export * from './cas.js';
|
|
9
|
-
export * from './
|
|
9
|
+
export * from './key-manager.js';
|
|
10
10
|
export * from './crypto.js';
|
|
11
11
|
export * from './did.js';
|
|
12
12
|
export * from './method.js';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAyBpD,gBAAgB;AAChB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAyBpD,gBAAgB;AAChB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
|