@bsv/sdk 1.3.36 → 1.4.1
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/cjs/mod.js +3 -0
- package/dist/cjs/mod.js.map +1 -1
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/auth/Peer.js +42 -14
- package/dist/cjs/src/auth/Peer.js.map +1 -1
- package/dist/cjs/src/auth/certificates/Certificate.js +50 -22
- package/dist/cjs/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/MasterCertificate.js +35 -10
- package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js +28 -4
- package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js +5 -2
- package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
- package/dist/cjs/src/auth/clients/AuthFetch.js +50 -20
- package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +40 -17
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/cjs/src/auth/utils/createNonce.js +31 -4
- package/dist/cjs/src/auth/utils/createNonce.js.map +1 -1
- package/dist/cjs/src/auth/utils/verifyNonce.js +26 -3
- package/dist/cjs/src/auth/utils/verifyNonce.js.map +1 -1
- package/dist/cjs/src/identity/IdentityClient.js +258 -0
- package/dist/cjs/src/identity/IdentityClient.js.map +1 -0
- package/dist/cjs/src/identity/index.js +19 -0
- package/dist/cjs/src/identity/index.js.map +1 -0
- package/dist/cjs/src/identity/types/index.js +30 -0
- package/dist/cjs/src/identity/types/index.js.map +1 -0
- package/dist/cjs/src/overlay-tools/LookupResolver.js +2 -2
- package/dist/cjs/src/overlay-tools/LookupResolver.js.map +1 -1
- package/dist/cjs/src/primitives/utils.js.map +1 -1
- package/dist/cjs/src/registry/RegistryClient.js +392 -0
- package/dist/cjs/src/registry/RegistryClient.js.map +1 -0
- package/dist/cjs/src/registry/index.js +19 -0
- package/dist/cjs/src/registry/index.js.map +1 -0
- package/dist/cjs/src/registry/types/index.js +3 -0
- package/dist/cjs/src/registry/types/index.js.map +1 -0
- package/dist/cjs/src/storage/StorageUploader.js +93 -0
- package/dist/cjs/src/storage/StorageUploader.js.map +1 -0
- package/dist/cjs/src/storage/StorageUtils.js +73 -0
- package/dist/cjs/src/storage/StorageUtils.js.map +1 -0
- package/dist/cjs/src/storage/__test/StorageUploader.test.js +92 -0
- package/dist/cjs/src/storage/__test/StorageUploader.test.js.map +1 -0
- package/dist/cjs/src/storage/__test/StorageUtils.test.js +97 -0
- package/dist/cjs/src/storage/__test/StorageUtils.test.js.map +1 -0
- package/dist/cjs/src/storage/index.js +30 -0
- package/dist/cjs/src/storage/index.js.map +1 -0
- package/dist/cjs/src/wallet/WalletClient.js +4 -4
- package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/HTTPWalletWire.js +26 -3
- package/dist/cjs/src/wallet/substrates/HTTPWalletWire.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js +178 -155
- package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js +171 -148
- package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/XDM.js +29 -2
- package/dist/cjs/src/wallet/substrates/XDM.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/mod.js +3 -0
- package/dist/esm/mod.js.map +1 -1
- package/dist/esm/src/auth/Peer.js +7 -5
- package/dist/esm/src/auth/Peer.js.map +1 -1
- package/dist/esm/src/auth/certificates/Certificate.js +3 -1
- package/dist/esm/src/auth/certificates/Certificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/MasterCertificate.js +3 -1
- package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js +2 -1
- package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js +1 -1
- package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
- package/dist/esm/src/auth/clients/AuthFetch.js +5 -1
- package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +1 -1
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/esm/src/auth/utils/createNonce.js +2 -1
- package/dist/esm/src/auth/utils/createNonce.js.map +1 -1
- package/dist/esm/src/auth/utils/verifyNonce.js +1 -1
- package/dist/esm/src/auth/utils/verifyNonce.js.map +1 -1
- package/dist/esm/src/identity/IdentityClient.js +255 -0
- package/dist/esm/src/identity/IdentityClient.js.map +1 -0
- package/dist/esm/src/identity/index.js +3 -0
- package/dist/esm/src/identity/index.js.map +1 -0
- package/dist/esm/src/identity/types/index.js +27 -0
- package/dist/esm/src/identity/types/index.js.map +1 -0
- package/dist/esm/src/overlay-tools/LookupResolver.js +2 -2
- package/dist/esm/src/overlay-tools/LookupResolver.js.map +1 -1
- package/dist/esm/src/primitives/utils.js.map +1 -1
- package/dist/esm/src/registry/RegistryClient.js +388 -0
- package/dist/esm/src/registry/RegistryClient.js.map +1 -0
- package/dist/esm/src/registry/index.js +3 -0
- package/dist/esm/src/registry/index.js.map +1 -0
- package/dist/esm/src/registry/types/index.js +2 -0
- package/dist/esm/src/registry/types/index.js.map +1 -0
- package/dist/esm/src/storage/StorageUploader.js +68 -0
- package/dist/esm/src/storage/StorageUploader.js.map +1 -0
- package/dist/esm/src/storage/StorageUtils.js +65 -0
- package/dist/esm/src/storage/StorageUtils.js.map +1 -0
- package/dist/esm/src/storage/__test/StorageUploader.test.js +64 -0
- package/dist/esm/src/storage/__test/StorageUploader.test.js.map +1 -0
- package/dist/esm/src/storage/__test/StorageUtils.test.js +72 -0
- package/dist/esm/src/storage/__test/StorageUtils.test.js.map +1 -0
- package/dist/esm/src/storage/index.js +3 -0
- package/dist/esm/src/storage/index.js.map +1 -0
- package/dist/esm/src/wallet/WalletClient.js +4 -4
- package/dist/esm/src/wallet/WalletClient.js.map +1 -1
- package/dist/esm/src/wallet/substrates/HTTPWalletWire.js +1 -1
- package/dist/esm/src/wallet/substrates/HTTPWalletWire.js.map +1 -1
- package/dist/esm/src/wallet/substrates/WalletWireProcessor.js +1 -1
- package/dist/esm/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
- package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js +2 -2
- package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
- package/dist/esm/src/wallet/substrates/XDM.js +2 -1
- package/dist/esm/src/wallet/substrates/XDM.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/mod.d.ts +3 -0
- package/dist/types/mod.d.ts.map +1 -1
- package/dist/types/src/auth/Peer.d.ts +1 -1
- package/dist/types/src/auth/Peer.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/Certificate.d.ts +2 -1
- package/dist/types/src/auth/certificates/Certificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts +2 -1
- package/dist/types/src/auth/certificates/MasterCertificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts +2 -1
- package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts.map +1 -1
- package/dist/types/src/auth/certificates/__tests/CompletedProtoWallet.d.ts +1 -1
- package/dist/types/src/auth/certificates/__tests/CompletedProtoWallet.d.ts.map +1 -1
- package/dist/types/src/auth/clients/AuthFetch.d.ts +1 -1
- package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
- package/dist/types/src/auth/utils/createNonce.d.ts +1 -1
- package/dist/types/src/auth/utils/createNonce.d.ts.map +1 -1
- package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts +1 -1
- package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts.map +1 -1
- package/dist/types/src/auth/utils/verifyNonce.d.ts +1 -1
- package/dist/types/src/auth/utils/verifyNonce.d.ts.map +1 -1
- package/dist/types/src/identity/IdentityClient.d.ts +50 -0
- package/dist/types/src/identity/IdentityClient.d.ts.map +1 -0
- package/dist/types/src/identity/index.d.ts +3 -0
- package/dist/types/src/identity/index.d.ts.map +1 -0
- package/dist/types/src/identity/types/index.d.ts +30 -0
- package/dist/types/src/identity/types/index.d.ts.map +1 -0
- package/dist/types/src/primitives/utils.d.ts +4 -1
- package/dist/types/src/primitives/utils.d.ts.map +1 -1
- package/dist/types/src/registry/RegistryClient.d.ts +94 -0
- package/dist/types/src/registry/RegistryClient.d.ts.map +1 -0
- package/dist/types/src/registry/index.d.ts +3 -0
- package/dist/types/src/registry/index.d.ts.map +1 -0
- package/dist/types/src/registry/types/index.d.ts +86 -0
- package/dist/types/src/registry/types/index.d.ts.map +1 -0
- package/dist/types/src/storage/StorageUploader.d.ts +40 -0
- package/dist/types/src/storage/StorageUploader.d.ts.map +1 -0
- package/dist/types/src/storage/StorageUtils.d.ts +31 -0
- package/dist/types/src/storage/StorageUtils.d.ts.map +1 -0
- package/dist/types/src/storage/__test/StorageUploader.test.d.ts +2 -0
- package/dist/types/src/storage/__test/StorageUploader.test.d.ts.map +1 -0
- package/dist/types/src/storage/__test/StorageUtils.test.d.ts +2 -0
- package/dist/types/src/storage/__test/StorageUtils.test.d.ts.map +1 -0
- package/dist/types/src/storage/index.d.ts +3 -0
- package/dist/types/src/storage/index.d.ts.map +1 -0
- package/dist/types/src/wallet/substrates/XDM.d.ts +1 -1
- package/dist/types/src/wallet/substrates/XDM.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/primitives.md +4 -1
- package/docs/storage.md +210 -0
- package/docs/wallet-substrates.md +0 -225
- package/mod.ts +3 -0
- package/package.json +11 -1
- package/src/auth/Peer.ts +8 -5
- package/src/auth/__tests/Peer.test.ts +31 -31
- package/src/auth/certificates/Certificate.ts +5 -5
- package/src/auth/certificates/MasterCertificate.ts +5 -5
- package/src/auth/certificates/VerifiableCertificate.ts +6 -6
- package/src/auth/certificates/__tests/CompletedProtoWallet.ts +1 -15
- package/src/auth/clients/AuthFetch.ts +6 -1
- package/src/auth/transports/SimplifiedFetchTransport.ts +1 -1
- package/src/auth/utils/createNonce.ts +3 -3
- package/src/auth/utils/getVerifiableCertificates.ts +1 -1
- package/src/auth/utils/verifyNonce.ts +2 -1
- package/src/identity/IdentityClient.ts +305 -0
- package/src/identity/README.md +93 -0
- package/src/identity/__tests/IdentityClient.test.ts +278 -0
- package/src/identity/index.ts +2 -0
- package/src/identity/types/index.ts +46 -0
- package/src/overlay-tools/LookupResolver.ts +2 -2
- package/src/primitives/utils.ts +1 -1
- package/src/registry/RegistryClient.ts +493 -0
- package/src/registry/__tests/RegistryClient.test.ts +444 -0
- package/src/registry/index.ts +2 -0
- package/src/registry/types/index.ts +101 -0
- package/src/storage/StorageUploader.ts +108 -0
- package/src/storage/StorageUtils.ts +66 -0
- package/src/storage/__test/StorageUploader.test.ts +80 -0
- package/src/storage/__test/StorageUtils.test.ts +86 -0
- package/src/storage/index.ts +2 -0
- package/src/wallet/WalletClient.ts +4 -4
- package/src/wallet/substrates/HTTPWalletWire.ts +1 -1
- package/src/wallet/substrates/WalletWireProcessor.ts +1 -1
- package/src/wallet/substrates/WalletWireTransceiver.ts +2 -2
- package/src/wallet/substrates/XDM.ts +3 -2
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegistryClient = void 0;
|
|
4
|
+
const index_js_1 = require("../wallet/index.js");
|
|
5
|
+
const index_js_2 = require("../primitives/index.js");
|
|
6
|
+
const index_js_3 = require("../transaction/index.js");
|
|
7
|
+
const index_js_4 = require("../overlay-tools/index.js");
|
|
8
|
+
const index_js_5 = require("../script/index.js");
|
|
9
|
+
const REGISTRANT_TOKEN_AMOUNT = 1;
|
|
10
|
+
/**
|
|
11
|
+
* RegistryClient manages on-chain registry definitions for three types:
|
|
12
|
+
* - BasketMap (basket-based items)
|
|
13
|
+
* - ProtoMap (protocol-based items)
|
|
14
|
+
* - CertMap (certificate-based items)
|
|
15
|
+
*
|
|
16
|
+
* It provides methods to:
|
|
17
|
+
* - Register new definitions using pushdrop-based UTXOs.
|
|
18
|
+
* - Resolve existing definitions using a overlay lookup service.
|
|
19
|
+
* - List registry entries associated with the operator's wallet.
|
|
20
|
+
* - Revoke an existing registry entry by spending its UTXO.
|
|
21
|
+
*
|
|
22
|
+
* Registry operators use this client to establish and manage
|
|
23
|
+
* canonical references for baskets, protocols, and certificates types.
|
|
24
|
+
*/
|
|
25
|
+
class RegistryClient {
|
|
26
|
+
constructor(wallet = new index_js_1.WalletClient()) {
|
|
27
|
+
this.wallet = wallet;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Publishes a new on-chain definition for baskets, protocols, or certificates.
|
|
31
|
+
* The definition data is encoded in a pushdrop-based UTXO.
|
|
32
|
+
*
|
|
33
|
+
* Registry operators (i.e., identity key owners) can create these definitions
|
|
34
|
+
* to establish canonical references for basket IDs, protocol specs, or certificate schemas.
|
|
35
|
+
*
|
|
36
|
+
* @param data - The structured information needed to register an item of kind 'basket', 'protocol', or 'certificate'.
|
|
37
|
+
* @returns A promise with the broadcast result or failure.
|
|
38
|
+
*/
|
|
39
|
+
async registerDefinition(data) {
|
|
40
|
+
var _a;
|
|
41
|
+
const registryOperator = (await this.wallet.getPublicKey({ identityKey: true })).publicKey;
|
|
42
|
+
const pushdrop = new index_js_5.PushDrop(this.wallet);
|
|
43
|
+
// Build the array of fields, depending on the definition type
|
|
44
|
+
const fields = this.buildPushDropFields(data, registryOperator);
|
|
45
|
+
const protocol = this.getWalletProtocol(data.definitionType);
|
|
46
|
+
// Lock the fields
|
|
47
|
+
const lockingScript = await pushdrop.lock(fields, protocol, '1', 'self');
|
|
48
|
+
// Create a transaction
|
|
49
|
+
const { tx } = await this.wallet.createAction({
|
|
50
|
+
description: `Register a new ${data.definitionType} item`,
|
|
51
|
+
outputs: [
|
|
52
|
+
{
|
|
53
|
+
satoshis: REGISTRANT_TOKEN_AMOUNT,
|
|
54
|
+
lockingScript: lockingScript.toHex(),
|
|
55
|
+
outputDescription: `New ${data.definitionType} registration token`
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
if (tx === undefined) {
|
|
60
|
+
throw new Error(`Failed to create ${data.definitionType} registration transaction!`);
|
|
61
|
+
}
|
|
62
|
+
// Broadcast
|
|
63
|
+
const broadcaster = new index_js_4.TopicBroadcaster([this.getBroadcastTopic(data.definitionType)], {
|
|
64
|
+
networkPreset: (_a = this.network) !== null && _a !== void 0 ? _a : (this.network = (await (this.wallet.getNetwork({}))).network)
|
|
65
|
+
});
|
|
66
|
+
return await broadcaster.broadcast(index_js_3.Transaction.fromAtomicBEEF(tx));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resolves registrant tokens of a particular type using a lookup service.
|
|
70
|
+
*
|
|
71
|
+
* The query object shape depends on the registry type:
|
|
72
|
+
* - For "basket", the query is of type BasketMapQuery:
|
|
73
|
+
* { basketID?: string; name?: string; registryOperators?: string[]; }
|
|
74
|
+
* - For "protocol", the query is of type ProtoMapQuery:
|
|
75
|
+
* { name?: string; registryOperators?: string[]; protocolID?: string; securityLevel?: number; }
|
|
76
|
+
* - For "certificate", the query is of type CertMapQuery:
|
|
77
|
+
* { type?: string; name?: string; registryOperators?: string[]; }
|
|
78
|
+
*
|
|
79
|
+
* @param definitionType - The registry type, which can be 'basket', 'protocol', or 'certificate'.
|
|
80
|
+
* @param query - The query object used to filter registry records, whose shape is determined by the registry type.
|
|
81
|
+
* @returns A promise that resolves to an array of matching registry records.
|
|
82
|
+
*/
|
|
83
|
+
async resolve(definitionType, query) {
|
|
84
|
+
const resolver = new index_js_4.LookupResolver();
|
|
85
|
+
// The service name depends on the kind
|
|
86
|
+
const serviceName = this.getServiceName(definitionType);
|
|
87
|
+
const result = await resolver.query({
|
|
88
|
+
service: serviceName,
|
|
89
|
+
query
|
|
90
|
+
});
|
|
91
|
+
if (result.type !== 'output-list') {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
const parsedRegistryRecords = [];
|
|
95
|
+
for (const output of result.outputs) {
|
|
96
|
+
try {
|
|
97
|
+
const parsedTx = index_js_3.Transaction.fromAtomicBEEF(output.beef);
|
|
98
|
+
const record = await this.parseLockingScript(definitionType, parsedTx.outputs[output.outputIndex].lockingScript);
|
|
99
|
+
parsedRegistryRecords.push(record);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// skip
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return parsedRegistryRecords;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Lists the registry operator's published definitions for the given type.
|
|
109
|
+
*
|
|
110
|
+
* Returns parsed registry records including transaction details such as txid, outputIndex, satoshis, and the locking script.
|
|
111
|
+
*
|
|
112
|
+
* @param definitionType - The type of registry definition to list ('basket', 'protocol', or 'certificate').
|
|
113
|
+
* @returns A promise that resolves to an array of RegistryRecord objects.
|
|
114
|
+
*/
|
|
115
|
+
async listOwnRegistryEntries(definitionType) {
|
|
116
|
+
const relevantBasketName = this.getBasketName(definitionType);
|
|
117
|
+
const { outputs } = await this.wallet.listOutputs({
|
|
118
|
+
basket: relevantBasketName,
|
|
119
|
+
include: 'locking scripts'
|
|
120
|
+
});
|
|
121
|
+
const results = [];
|
|
122
|
+
for (const output of outputs) {
|
|
123
|
+
if (output.spendable) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const record = await this.parseLockingScript(definitionType, index_js_5.LockingScript.fromHex(output.lockingScript));
|
|
128
|
+
const [txid, outputIndex] = output.outpoint.split('.');
|
|
129
|
+
results.push({
|
|
130
|
+
...record,
|
|
131
|
+
txid,
|
|
132
|
+
outputIndex: Number(outputIndex),
|
|
133
|
+
satoshis: output.satoshis,
|
|
134
|
+
lockingScript: output.lockingScript
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// ignore parse errors
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return results;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Revokes a registry record by spending its associated UTXO.
|
|
145
|
+
*
|
|
146
|
+
* This function creates a transaction that spends the UTXO corresponding to the provided registry record,
|
|
147
|
+
* revoking the registry entry. It prepares an unlocker using the appropriate wallet protocol,
|
|
148
|
+
* builds a signable transaction, signs it, and then broadcasts the finalized transaction.
|
|
149
|
+
*
|
|
150
|
+
* @param registryRecord - The registry record to revoke. It must include a valid txid, outputIndex, and lockingScript.
|
|
151
|
+
* @returns A promise that resolves with either a BroadcastResponse upon success or a BroadcastFailure on error.
|
|
152
|
+
* @throws If required fields are missing or if transaction creation/signing fails.
|
|
153
|
+
*/
|
|
154
|
+
async revokeOwnRegistryEntry(registryRecord) {
|
|
155
|
+
var _a;
|
|
156
|
+
if (registryRecord.txid === undefined || typeof registryRecord.outputIndex === 'undefined' || registryRecord.lockingScript === undefined) {
|
|
157
|
+
throw new Error('Invalid record. Missing txid, outputIndex, or lockingScript.');
|
|
158
|
+
}
|
|
159
|
+
// Prepare the unlocker
|
|
160
|
+
const pushdrop = new index_js_5.PushDrop(this.wallet);
|
|
161
|
+
const unlocker = await pushdrop.unlock(this.getWalletProtocol(registryRecord.definitionType), '1', 'anyone');
|
|
162
|
+
const itemIdentifier = registryRecord.definitionType === 'basket'
|
|
163
|
+
? registryRecord.basketID
|
|
164
|
+
: registryRecord.definitionType === 'protocol'
|
|
165
|
+
? registryRecord.name
|
|
166
|
+
: registryRecord.definitionType === 'certificate'
|
|
167
|
+
? (registryRecord.name !== undefined ? registryRecord.name : registryRecord.type)
|
|
168
|
+
: 'unknown';
|
|
169
|
+
const description = `Revoke ${registryRecord.definitionType} item: ${String(itemIdentifier)}`;
|
|
170
|
+
// Create a new transaction that spends the UTXO
|
|
171
|
+
const outpoint = `${registryRecord.txid}.${registryRecord.outputIndex}`;
|
|
172
|
+
const { signableTransaction } = await this.wallet.createAction({
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
174
|
+
description,
|
|
175
|
+
inputs: [
|
|
176
|
+
{
|
|
177
|
+
outpoint,
|
|
178
|
+
unlockingScriptLength: 73,
|
|
179
|
+
inputDescription: `Revoking ${registryRecord.definitionType} token`
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
});
|
|
183
|
+
if (signableTransaction === undefined) {
|
|
184
|
+
throw new Error('Failed to create signable transaction.');
|
|
185
|
+
}
|
|
186
|
+
// Build a transaction object, sign with the unlock script
|
|
187
|
+
const tx = index_js_3.Transaction.fromBEEF(signableTransaction.tx);
|
|
188
|
+
const finalUnlockScript = await unlocker.sign(tx, registryRecord.outputIndex);
|
|
189
|
+
// Complete the signing
|
|
190
|
+
const { tx: signedTx } = await this.wallet.signAction({
|
|
191
|
+
reference: signableTransaction.reference,
|
|
192
|
+
spends: {
|
|
193
|
+
[registryRecord.outputIndex]: {
|
|
194
|
+
unlockingScript: finalUnlockScript.toHex()
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
if (signedTx === undefined) {
|
|
199
|
+
throw new Error('Failed to finalize the transaction signature.');
|
|
200
|
+
}
|
|
201
|
+
// Broadcast
|
|
202
|
+
const broadcaster = new index_js_4.TopicBroadcaster([this.getBroadcastTopic(registryRecord.definitionType)], {
|
|
203
|
+
networkPreset: (_a = this.network) !== null && _a !== void 0 ? _a : (this.network = (await (this.wallet.getNetwork({}))).network)
|
|
204
|
+
});
|
|
205
|
+
return await broadcaster.broadcast(index_js_3.Transaction.fromAtomicBEEF(signedTx));
|
|
206
|
+
}
|
|
207
|
+
// --------------------------------------------------------------------------
|
|
208
|
+
// INTERNAL HELPER METHODS
|
|
209
|
+
// --------------------------------------------------------------------------
|
|
210
|
+
buildPushDropFields(data, registryOperator) {
|
|
211
|
+
let fields;
|
|
212
|
+
switch (data.definitionType) {
|
|
213
|
+
case 'basket':
|
|
214
|
+
fields = [
|
|
215
|
+
data.basketID,
|
|
216
|
+
data.name,
|
|
217
|
+
data.iconURL,
|
|
218
|
+
data.description,
|
|
219
|
+
data.documentationURL
|
|
220
|
+
];
|
|
221
|
+
break;
|
|
222
|
+
case 'protocol':
|
|
223
|
+
fields = [
|
|
224
|
+
data.securityLevel.toString(),
|
|
225
|
+
data.protocolID,
|
|
226
|
+
data.name,
|
|
227
|
+
data.iconURL,
|
|
228
|
+
data.description,
|
|
229
|
+
data.documentationURL
|
|
230
|
+
];
|
|
231
|
+
break;
|
|
232
|
+
case 'certificate':
|
|
233
|
+
fields = [
|
|
234
|
+
data.type,
|
|
235
|
+
data.name,
|
|
236
|
+
data.iconURL,
|
|
237
|
+
data.description,
|
|
238
|
+
data.documentationURL,
|
|
239
|
+
JSON.stringify(data.fields)
|
|
240
|
+
];
|
|
241
|
+
break;
|
|
242
|
+
default:
|
|
243
|
+
throw new Error('Invalid registry kind specified');
|
|
244
|
+
}
|
|
245
|
+
// Append the registry operator to all cases.
|
|
246
|
+
fields.push(registryOperator);
|
|
247
|
+
return fields.map(field => index_js_2.Utils.toArray(field));
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Decodes a pushdrop locking script for a given registry kind,
|
|
251
|
+
* returning a typed record with the appropriate fields.
|
|
252
|
+
*/
|
|
253
|
+
async parseLockingScript(definitionType, lockingScript) {
|
|
254
|
+
const decoded = index_js_5.PushDrop.decode(lockingScript);
|
|
255
|
+
if (decoded.fields.length === 0) {
|
|
256
|
+
throw new Error('Not a valid registry pushdrop script.');
|
|
257
|
+
}
|
|
258
|
+
let registryOperator;
|
|
259
|
+
let data;
|
|
260
|
+
switch (definitionType) {
|
|
261
|
+
case 'basket': {
|
|
262
|
+
if (decoded.fields.length !== 6) {
|
|
263
|
+
throw new Error('Unexpected field count for basket type.');
|
|
264
|
+
}
|
|
265
|
+
const [basketID, name, iconURL, description, docURL, operator] = decoded.fields;
|
|
266
|
+
registryOperator = index_js_2.Utils.toUTF8(operator);
|
|
267
|
+
data = {
|
|
268
|
+
definitionType: 'basket',
|
|
269
|
+
basketID: index_js_2.Utils.toUTF8(basketID),
|
|
270
|
+
name: index_js_2.Utils.toUTF8(name),
|
|
271
|
+
iconURL: index_js_2.Utils.toUTF8(iconURL),
|
|
272
|
+
description: index_js_2.Utils.toUTF8(description),
|
|
273
|
+
documentationURL: index_js_2.Utils.toUTF8(docURL)
|
|
274
|
+
};
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
case 'protocol': {
|
|
278
|
+
if (decoded.fields.length !== 7) {
|
|
279
|
+
throw new Error('Unexpected field count for proto type.');
|
|
280
|
+
}
|
|
281
|
+
const [securityLevel, protocolID, name, iconURL, description, docURL, operator] = decoded.fields;
|
|
282
|
+
registryOperator = index_js_2.Utils.toUTF8(operator);
|
|
283
|
+
data = {
|
|
284
|
+
definitionType: 'protocol',
|
|
285
|
+
securityLevel: parseInt(index_js_2.Utils.toUTF8(securityLevel), 10),
|
|
286
|
+
protocolID: index_js_2.Utils.toUTF8(protocolID),
|
|
287
|
+
name: index_js_2.Utils.toUTF8(name),
|
|
288
|
+
iconURL: index_js_2.Utils.toUTF8(iconURL),
|
|
289
|
+
description: index_js_2.Utils.toUTF8(description),
|
|
290
|
+
documentationURL: index_js_2.Utils.toUTF8(docURL)
|
|
291
|
+
};
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
case 'certificate': {
|
|
295
|
+
if (decoded.fields.length !== 7) {
|
|
296
|
+
throw new Error('Unexpected field count for certificate type.');
|
|
297
|
+
}
|
|
298
|
+
const [certType, name, iconURL, description, docURL, fieldsJSON, operator] = decoded.fields;
|
|
299
|
+
registryOperator = index_js_2.Utils.toUTF8(operator);
|
|
300
|
+
let parsedFields;
|
|
301
|
+
try {
|
|
302
|
+
parsedFields = JSON.parse(index_js_2.Utils.toUTF8(fieldsJSON));
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
parsedFields = {};
|
|
306
|
+
}
|
|
307
|
+
data = {
|
|
308
|
+
definitionType: 'certificate',
|
|
309
|
+
type: index_js_2.Utils.toUTF8(certType),
|
|
310
|
+
name: index_js_2.Utils.toUTF8(name),
|
|
311
|
+
iconURL: index_js_2.Utils.toUTF8(iconURL),
|
|
312
|
+
description: index_js_2.Utils.toUTF8(description),
|
|
313
|
+
documentationURL: index_js_2.Utils.toUTF8(docURL),
|
|
314
|
+
fields: parsedFields
|
|
315
|
+
};
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
default:
|
|
319
|
+
throw new Error('Invalid registry kind for parsing.');
|
|
320
|
+
}
|
|
321
|
+
const currentIdentityKey = (await this.wallet.getPublicKey({ identityKey: true })).publicKey;
|
|
322
|
+
if (registryOperator !== currentIdentityKey) {
|
|
323
|
+
throw new Error('This registry token does not belong to the current wallet.');
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
...data,
|
|
327
|
+
registryOperator
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Returns the (protocolID, keyID) used for pushdrop based on the registry kind.
|
|
332
|
+
*/
|
|
333
|
+
getWalletProtocol(definitionType) {
|
|
334
|
+
switch (definitionType) {
|
|
335
|
+
case 'basket':
|
|
336
|
+
return [1, 'basketmap'];
|
|
337
|
+
case 'protocol':
|
|
338
|
+
return [1, 'protomap'];
|
|
339
|
+
case 'certificate':
|
|
340
|
+
return [1, 'certmap'];
|
|
341
|
+
default:
|
|
342
|
+
throw new Error(`Unknown registry type: ${definitionType}`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Returns the name of the basket used by the wallet
|
|
347
|
+
*/
|
|
348
|
+
getBasketName(definitionType) {
|
|
349
|
+
switch (definitionType) {
|
|
350
|
+
case 'basket':
|
|
351
|
+
return 'basketmap';
|
|
352
|
+
case 'protocol':
|
|
353
|
+
return 'protomap';
|
|
354
|
+
case 'certificate':
|
|
355
|
+
return 'certmap';
|
|
356
|
+
default:
|
|
357
|
+
throw new Error(`Unknown basket type: ${definitionType}`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Returns the broadcast topic to be used with SHIPBroadcaster.
|
|
362
|
+
*/
|
|
363
|
+
getBroadcastTopic(definitionType) {
|
|
364
|
+
switch (definitionType) {
|
|
365
|
+
case 'basket':
|
|
366
|
+
return 'tm_basketmap';
|
|
367
|
+
case 'protocol':
|
|
368
|
+
return 'tm_protomap';
|
|
369
|
+
case 'certificate':
|
|
370
|
+
return 'tm_certmap';
|
|
371
|
+
default:
|
|
372
|
+
throw new Error(`Unknown topic type: ${definitionType}`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Returns the lookup service name to use.
|
|
377
|
+
*/
|
|
378
|
+
getServiceName(definitionType) {
|
|
379
|
+
switch (definitionType) {
|
|
380
|
+
case 'basket':
|
|
381
|
+
return 'ls_basketmap';
|
|
382
|
+
case 'protocol':
|
|
383
|
+
return 'ls_protomap';
|
|
384
|
+
case 'certificate':
|
|
385
|
+
return 'ls_certmap';
|
|
386
|
+
default:
|
|
387
|
+
throw new Error(`Unknown service type: ${definitionType}`);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
exports.RegistryClient = RegistryClient;
|
|
392
|
+
//# sourceMappingURL=RegistryClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RegistryClient.js","sourceRoot":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O,cAAc,CAAA;YACvB,KAAK,UAAU;gBACb,OAAO,aAAa,CAAA;YACtB,KAAK,aAAa;gBAChB,OAAO,YAAY,CAAA;YACrB;gBACE,MAAM,IAAI,KAAK,CAAC,yBAAyB,cAAwB,EAAE,CAAC,CAAA;SACvE;IACH,CAAC;CACF;AA5bD,wCA4bC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./RegistryClient.js"), exports);
|
|
18
|
+
__exportStar(require("./types/index.js"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/registry/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAmC;AACnC,mDAAgC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/registry/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.StorageUploader = void 0;
|
|
27
|
+
const AuthFetch_js_1 = require("../auth/clients/AuthFetch.js");
|
|
28
|
+
const StorageUtils = __importStar(require("./StorageUtils.js"));
|
|
29
|
+
class StorageUploader {
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this.baseURL = config.storageURL;
|
|
32
|
+
this.authFetch = new AuthFetch_js_1.AuthFetch(config.wallet);
|
|
33
|
+
}
|
|
34
|
+
async getUploadInfo(fileSize, retentionPeriod) {
|
|
35
|
+
const url = `${this.baseURL}/upload`;
|
|
36
|
+
const body = { fileSize, retentionPeriod };
|
|
37
|
+
const response = await this.authFetch.fetch(url, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: { 'Content-Type': 'application/json' },
|
|
40
|
+
body: JSON.stringify(body)
|
|
41
|
+
});
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
throw new Error(`Upload info request failed: HTTP ${response.status}`);
|
|
44
|
+
}
|
|
45
|
+
const data = await response.json();
|
|
46
|
+
if (data.status === 'error') {
|
|
47
|
+
throw new Error('Upload route returned an error.');
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
uploadURL: data.uploadURL,
|
|
51
|
+
amount: data.amount
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async uploadFile(uploadURL, file) {
|
|
55
|
+
const body = Uint8Array.from(file.data);
|
|
56
|
+
const response = await fetch(uploadURL, {
|
|
57
|
+
method: 'PUT',
|
|
58
|
+
body,
|
|
59
|
+
headers: { 'Content-Type': file.type }
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
throw new Error(`File upload failed: HTTP ${response.status}`);
|
|
63
|
+
}
|
|
64
|
+
const uhrpURL = await StorageUtils.getURLForFile(file.data);
|
|
65
|
+
return {
|
|
66
|
+
published: true,
|
|
67
|
+
uhrpURL
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Publishes a file to the storage server with the specified retention period.
|
|
72
|
+
*
|
|
73
|
+
* This will:
|
|
74
|
+
* 1. Request an upload URL from the server.
|
|
75
|
+
* 2. Perform an HTTP PUT to upload the file’s raw bytes.
|
|
76
|
+
* 3. Return a UHRP URL referencing the file once published.
|
|
77
|
+
*
|
|
78
|
+
* @param params.file - An object describing the file’s data (number[] array of bytes) and mime type.
|
|
79
|
+
* @param params.retentionPeriod - Number of minutes to keep the file hosted.
|
|
80
|
+
*
|
|
81
|
+
* @returns An object indicating whether the file was published successfully and the resulting UHRP URL.
|
|
82
|
+
*
|
|
83
|
+
* @throws If either the upload info request or the subsequent file upload request fails (non-OK HTTP status).
|
|
84
|
+
*/
|
|
85
|
+
async publishFile(params) {
|
|
86
|
+
const { file, retentionPeriod } = params;
|
|
87
|
+
const fileSize = file.data.length;
|
|
88
|
+
const { uploadURL } = await this.getUploadInfo(fileSize, retentionPeriod);
|
|
89
|
+
return await this.uploadFile(uploadURL, file);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.StorageUploader = StorageUploader;
|
|
93
|
+
//# sourceMappingURL=StorageUploader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageUploader.js","sourceRoot":"","sources":["../../../../src/storage/StorageUploader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAAwD;AAExD,gEAAiD;AAiBjD,MAAa,eAAe;IAI1B,YAAa,MAAsB;QACjC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAA;QAChC,IAAI,CAAC,SAAS,GAAG,IAAI,wBAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC/C,CAAC;IAEO,KAAK,CAAC,aAAa,CACzB,QAAgB,EAChB,eAAuB;QAKvB,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,SAAS,CAAA;QACpC,MAAM,IAAI,GAAG,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAA;QAE1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE;YAC/C,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAA;QACF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,oCAAoC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;SACvE;QACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAI/B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
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidURL = exports.getHashFromURL = exports.getURLForFile = exports.getURLForHash = exports.normalizeURL = void 0;
|
|
4
|
+
const Hash_js_1 = require("../primitives/Hash.js");
|
|
5
|
+
const utils_js_1 = require("../primitives/utils.js");
|
|
6
|
+
/**
|
|
7
|
+
* Takes a UHRP URL and removes any prefixes.
|
|
8
|
+
* @param {string} URL - The UHRP URL.
|
|
9
|
+
* @returns {string} - Normalized URL.
|
|
10
|
+
*/
|
|
11
|
+
const normalizeURL = (URL) => {
|
|
12
|
+
if (URL.toLowerCase().startsWith('uhrp:'))
|
|
13
|
+
URL = URL.slice(5);
|
|
14
|
+
if (URL.startsWith('//'))
|
|
15
|
+
URL = URL.slice(2);
|
|
16
|
+
return URL;
|
|
17
|
+
};
|
|
18
|
+
exports.normalizeURL = normalizeURL;
|
|
19
|
+
/**
|
|
20
|
+
* Generates a UHRP URL from a given SHA-256 hash.
|
|
21
|
+
* @param {number[]} hash - 32-byte SHA-256 hash.
|
|
22
|
+
* @returns {string} - Base58Check encoded URL.
|
|
23
|
+
*/
|
|
24
|
+
const getURLForHash = (hash) => {
|
|
25
|
+
if (hash.length !== 32) {
|
|
26
|
+
throw new Error('Hash length must be 32 bytes (sha256)');
|
|
27
|
+
}
|
|
28
|
+
return (0, utils_js_1.toBase58Check)(hash, (0, utils_js_1.toArray)('ce00', 'hex'));
|
|
29
|
+
};
|
|
30
|
+
exports.getURLForHash = getURLForHash;
|
|
31
|
+
/**
|
|
32
|
+
* Generates a UHRP URL for a given file.
|
|
33
|
+
* @param {number[] | string} file - File content as number array or string.
|
|
34
|
+
* @returns {string} - Base58Check encoded URL.
|
|
35
|
+
*/
|
|
36
|
+
const getURLForFile = (file) => {
|
|
37
|
+
const hash = (0, Hash_js_1.sha256)(file);
|
|
38
|
+
return (0, exports.getURLForHash)(hash);
|
|
39
|
+
};
|
|
40
|
+
exports.getURLForFile = getURLForFile;
|
|
41
|
+
/**
|
|
42
|
+
* Extracts the hash from a UHRP URL.
|
|
43
|
+
* @param {string} URL - UHRP URL.
|
|
44
|
+
* @returns {number[]} - Extracted SHA-256 hash.
|
|
45
|
+
*/
|
|
46
|
+
const getHashFromURL = (URL) => {
|
|
47
|
+
URL = (0, exports.normalizeURL)(URL);
|
|
48
|
+
const { data, prefix } = (0, utils_js_1.fromBase58Check)(URL, undefined, 2);
|
|
49
|
+
if (data.length !== 32) {
|
|
50
|
+
throw new Error('Invalid length!');
|
|
51
|
+
}
|
|
52
|
+
if ((0, utils_js_1.toHex)(prefix) !== 'ce00') {
|
|
53
|
+
throw new Error('Bad prefix');
|
|
54
|
+
}
|
|
55
|
+
return data;
|
|
56
|
+
};
|
|
57
|
+
exports.getHashFromURL = getHashFromURL;
|
|
58
|
+
/**
|
|
59
|
+
* Checks if a URL is a valid UHRP URL.
|
|
60
|
+
* @param {string} URL - The URL to validate.
|
|
61
|
+
* @returns {boolean} - True if valid, false otherwise.
|
|
62
|
+
*/
|
|
63
|
+
const isValidURL = (URL) => {
|
|
64
|
+
try {
|
|
65
|
+
(0, exports.getHashFromURL)(URL);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
exports.isValidURL = isValidURL;
|
|
73
|
+
//# sourceMappingURL=StorageUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageUtils.js","sourceRoot":"","sources":["../../../../src/storage/StorageUtils.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAC9C,qDAAuF;AAEvF;;;;GAIG;AACI,MAAM,YAAY,GAAG,CAAC,GAAW,EAAU,EAAE;IAClD,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC7D,IAAI,GAAG,CAAC,UA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