@bsv/sdk 1.4.0 → 1.4.2

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.
Files changed (80) hide show
  1. package/dist/cjs/mod.js +2 -0
  2. package/dist/cjs/mod.js.map +1 -1
  3. package/dist/cjs/package.json +1 -1
  4. package/dist/cjs/src/identity/IdentityClient.js +258 -0
  5. package/dist/cjs/src/identity/IdentityClient.js.map +1 -0
  6. package/dist/cjs/src/identity/index.js +19 -0
  7. package/dist/cjs/src/identity/index.js.map +1 -0
  8. package/dist/cjs/src/identity/types/index.js +30 -0
  9. package/dist/cjs/src/identity/types/index.js.map +1 -0
  10. package/dist/cjs/src/registry/RegistryClient.js +392 -0
  11. package/dist/cjs/src/registry/RegistryClient.js.map +1 -0
  12. package/dist/cjs/src/registry/index.js +19 -0
  13. package/dist/cjs/src/registry/index.js.map +1 -0
  14. package/dist/cjs/src/registry/types/index.js +3 -0
  15. package/dist/cjs/src/registry/types/index.js.map +1 -0
  16. package/dist/cjs/src/storage/StorageDownloader.js +82 -0
  17. package/dist/cjs/src/storage/StorageDownloader.js.map +1 -0
  18. package/dist/cjs/src/storage/__test/StorageDownloader.test.js +144 -0
  19. package/dist/cjs/src/storage/__test/StorageDownloader.test.js.map +1 -0
  20. package/dist/cjs/src/storage/index.js +3 -1
  21. package/dist/cjs/src/storage/index.js.map +1 -1
  22. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  23. package/dist/esm/mod.js +2 -0
  24. package/dist/esm/mod.js.map +1 -1
  25. package/dist/esm/src/identity/IdentityClient.js +255 -0
  26. package/dist/esm/src/identity/IdentityClient.js.map +1 -0
  27. package/dist/esm/src/identity/index.js +3 -0
  28. package/dist/esm/src/identity/index.js.map +1 -0
  29. package/dist/esm/src/identity/types/index.js +27 -0
  30. package/dist/esm/src/identity/types/index.js.map +1 -0
  31. package/dist/esm/src/registry/RegistryClient.js +388 -0
  32. package/dist/esm/src/registry/RegistryClient.js.map +1 -0
  33. package/dist/esm/src/registry/index.js +3 -0
  34. package/dist/esm/src/registry/index.js.map +1 -0
  35. package/dist/esm/src/registry/types/index.js +2 -0
  36. package/dist/esm/src/registry/types/index.js.map +1 -0
  37. package/dist/esm/src/storage/StorageDownloader.js +75 -0
  38. package/dist/esm/src/storage/StorageDownloader.js.map +1 -0
  39. package/dist/esm/src/storage/__test/StorageDownloader.test.js +139 -0
  40. package/dist/esm/src/storage/__test/StorageDownloader.test.js.map +1 -0
  41. package/dist/esm/src/storage/index.js +1 -0
  42. package/dist/esm/src/storage/index.js.map +1 -1
  43. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  44. package/dist/types/mod.d.ts +2 -0
  45. package/dist/types/mod.d.ts.map +1 -1
  46. package/dist/types/src/identity/IdentityClient.d.ts +50 -0
  47. package/dist/types/src/identity/IdentityClient.d.ts.map +1 -0
  48. package/dist/types/src/identity/index.d.ts +3 -0
  49. package/dist/types/src/identity/index.d.ts.map +1 -0
  50. package/dist/types/src/identity/types/index.d.ts +30 -0
  51. package/dist/types/src/identity/types/index.d.ts.map +1 -0
  52. package/dist/types/src/registry/RegistryClient.d.ts +94 -0
  53. package/dist/types/src/registry/RegistryClient.d.ts.map +1 -0
  54. package/dist/types/src/registry/index.d.ts +3 -0
  55. package/dist/types/src/registry/index.d.ts.map +1 -0
  56. package/dist/types/src/registry/types/index.d.ts +86 -0
  57. package/dist/types/src/registry/types/index.d.ts.map +1 -0
  58. package/dist/types/src/storage/StorageDownloader.d.ts +25 -0
  59. package/dist/types/src/storage/StorageDownloader.d.ts.map +1 -0
  60. package/dist/types/src/storage/__test/StorageDownloader.test.d.ts +2 -0
  61. package/dist/types/src/storage/__test/StorageDownloader.test.d.ts.map +1 -0
  62. package/dist/types/src/storage/index.d.ts +1 -0
  63. package/dist/types/src/storage/index.d.ts.map +1 -1
  64. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  65. package/dist/umd/bundle.js +1 -1
  66. package/docs/storage.md +51 -0
  67. package/mod.ts +3 -1
  68. package/package.json +2 -2
  69. package/src/identity/IdentityClient.ts +305 -0
  70. package/src/identity/README.md +93 -0
  71. package/src/identity/__tests/IdentityClient.test.ts +278 -0
  72. package/src/identity/index.ts +2 -0
  73. package/src/identity/types/index.ts +46 -0
  74. package/src/registry/RegistryClient.ts +493 -0
  75. package/src/registry/__tests/RegistryClient.test.ts +444 -0
  76. package/src/registry/index.ts +2 -0
  77. package/src/registry/types/index.ts +101 -0
  78. package/src/storage/StorageDownloader.ts +91 -0
  79. package/src/storage/__test/StorageDownloader.test.ts +170 -0
  80. package/src/storage/index.ts +3 -0
@@ -0,0 +1,94 @@
1
+ import { WalletInterface } from '../wallet/index.js';
2
+ import { BroadcastResponse, BroadcastFailure } from '../transaction/index.js';
3
+ import { DefinitionData, DefinitionType, RegistryQueryMapping, RegistryRecord } from './types/index.js';
4
+ /**
5
+ * RegistryClient manages on-chain registry definitions for three types:
6
+ * - BasketMap (basket-based items)
7
+ * - ProtoMap (protocol-based items)
8
+ * - CertMap (certificate-based items)
9
+ *
10
+ * It provides methods to:
11
+ * - Register new definitions using pushdrop-based UTXOs.
12
+ * - Resolve existing definitions using a overlay lookup service.
13
+ * - List registry entries associated with the operator's wallet.
14
+ * - Revoke an existing registry entry by spending its UTXO.
15
+ *
16
+ * Registry operators use this client to establish and manage
17
+ * canonical references for baskets, protocols, and certificates types.
18
+ */
19
+ export declare class RegistryClient {
20
+ private readonly wallet;
21
+ private network;
22
+ constructor(wallet?: WalletInterface);
23
+ /**
24
+ * Publishes a new on-chain definition for baskets, protocols, or certificates.
25
+ * The definition data is encoded in a pushdrop-based UTXO.
26
+ *
27
+ * Registry operators (i.e., identity key owners) can create these definitions
28
+ * to establish canonical references for basket IDs, protocol specs, or certificate schemas.
29
+ *
30
+ * @param data - The structured information needed to register an item of kind 'basket', 'protocol', or 'certificate'.
31
+ * @returns A promise with the broadcast result or failure.
32
+ */
33
+ registerDefinition(data: DefinitionData): Promise<BroadcastResponse | BroadcastFailure>;
34
+ /**
35
+ * Resolves registrant tokens of a particular type using a lookup service.
36
+ *
37
+ * The query object shape depends on the registry type:
38
+ * - For "basket", the query is of type BasketMapQuery:
39
+ * { basketID?: string; name?: string; registryOperators?: string[]; }
40
+ * - For "protocol", the query is of type ProtoMapQuery:
41
+ * { name?: string; registryOperators?: string[]; protocolID?: string; securityLevel?: number; }
42
+ * - For "certificate", the query is of type CertMapQuery:
43
+ * { type?: string; name?: string; registryOperators?: string[]; }
44
+ *
45
+ * @param definitionType - The registry type, which can be 'basket', 'protocol', or 'certificate'.
46
+ * @param query - The query object used to filter registry records, whose shape is determined by the registry type.
47
+ * @returns A promise that resolves to an array of matching registry records.
48
+ */
49
+ resolve<T extends DefinitionType>(definitionType: T, query: RegistryQueryMapping[T]): Promise<DefinitionData[]>;
50
+ /**
51
+ * Lists the registry operator's published definitions for the given type.
52
+ *
53
+ * Returns parsed registry records including transaction details such as txid, outputIndex, satoshis, and the locking script.
54
+ *
55
+ * @param definitionType - The type of registry definition to list ('basket', 'protocol', or 'certificate').
56
+ * @returns A promise that resolves to an array of RegistryRecord objects.
57
+ */
58
+ listOwnRegistryEntries(definitionType: DefinitionType): Promise<RegistryRecord[]>;
59
+ /**
60
+ * Revokes a registry record by spending its associated UTXO.
61
+ *
62
+ * This function creates a transaction that spends the UTXO corresponding to the provided registry record,
63
+ * revoking the registry entry. It prepares an unlocker using the appropriate wallet protocol,
64
+ * builds a signable transaction, signs it, and then broadcasts the finalized transaction.
65
+ *
66
+ * @param registryRecord - The registry record to revoke. It must include a valid txid, outputIndex, and lockingScript.
67
+ * @returns A promise that resolves with either a BroadcastResponse upon success or a BroadcastFailure on error.
68
+ * @throws If required fields are missing or if transaction creation/signing fails.
69
+ */
70
+ revokeOwnRegistryEntry(registryRecord: RegistryRecord): Promise<BroadcastResponse | BroadcastFailure>;
71
+ private buildPushDropFields;
72
+ /**
73
+ * Decodes a pushdrop locking script for a given registry kind,
74
+ * returning a typed record with the appropriate fields.
75
+ */
76
+ private parseLockingScript;
77
+ /**
78
+ * Returns the (protocolID, keyID) used for pushdrop based on the registry kind.
79
+ */
80
+ private getWalletProtocol;
81
+ /**
82
+ * Returns the name of the basket used by the wallet
83
+ */
84
+ private getBasketName;
85
+ /**
86
+ * Returns the broadcast topic to be used with SHIPBroadcaster.
87
+ */
88
+ private getBroadcastTopic;
89
+ /**
90
+ * Returns the lookup service name to use.
91
+ */
92
+ private getServiceName;
93
+ }
94
+ //# sourceMappingURL=RegistryClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegistryClient.d.ts","sourceRoot":"","sources":["../../../../src/registry/RegistryClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAKhB,MAAM,oBAAoB,CAAA;AAI3B,OAAO,EAEL,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,yBAAyB,CAAA;AAShC,OAAO,EAEL,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,cAAc,EACf,MAAM,kBAAkB,CAAA;AAIzB;;;;;;;;;;;;;;GAcG;AACH,qBAAa,cAAc;IAGvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFzB,OAAO,CAAC,OAAO,CAAuB;gBAEnB,MAAM,GAAE,eAAoC;IAG/D;;;;;;;;;OASG;IACG,kBAAkB,CAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;IA2C9F;;;;;;;;;;;;;;OAcG;IACG,OAAO,CAAC,CAAC,SAAS,cAAc,EACpC,cAAc,EAAE,CAAC,EACjB,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC7B,OAAO,CAAC,cAAc,EAAE,CAAC;IA2B5B;;;;;;;OAOG;IACG,sBAAsB,CAAE,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IA8BxF;;;;;;;;;;OAUG;IACG,sBAAsB,CAC1B,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;IA0EhD,OAAO,CAAC,mBAAmB;IA8C3B;;;OAGG;YACW,kBAAkB;IAsGhC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAazB;;OAEG;IACH,OAAO,CAAC,aAAa;IAarB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAazB;;OAEG;IACH,OAAO,CAAC,cAAc;CAYvB"}
@@ -0,0 +1,3 @@
1
+ export * from './RegistryClient.js';
2
+ export * from './types/index.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/registry/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,86 @@
1
+ import { PubKeyHex } from '../../wallet/index.js';
2
+ /**
3
+ * Determines which category of registry item we are working with.
4
+ * - "basket" corresponds to BasketMap
5
+ * - "protocol" corresponds to ProtoMap
6
+ * - "certificate" corresponds to CertMap
7
+ */
8
+ export type DefinitionType = 'basket' | 'protocol' | 'certificate';
9
+ /**
10
+ * Describes a re-usable structure for certificate fields (used by CertMap).
11
+ */
12
+ export interface CertificateFieldDescriptor {
13
+ friendlyName: string;
14
+ description: string;
15
+ type: 'text' | 'imageURL' | 'other';
16
+ fieldIcon: string;
17
+ }
18
+ /**
19
+ * Registry data for a Basket-style record (BasketMap).
20
+ */
21
+ export interface BasketDefinitionData {
22
+ definitionType: 'basket';
23
+ basketID: string;
24
+ name: string;
25
+ iconURL: string;
26
+ description: string;
27
+ documentationURL: string;
28
+ registryOperator?: PubKeyHex;
29
+ }
30
+ /**
31
+ * Registry data for a Proto-style record (ProtoMap).
32
+ */
33
+ export interface ProtocolDefinitionData {
34
+ definitionType: 'protocol';
35
+ protocolID: string;
36
+ securityLevel: 0 | 1 | 2;
37
+ name: string;
38
+ iconURL: string;
39
+ description: string;
40
+ documentationURL: string;
41
+ registryOperator?: PubKeyHex;
42
+ }
43
+ /**
44
+ * Registry data for a Cert-style record (CertMap).
45
+ */
46
+ export interface CertificateDefinitionData {
47
+ definitionType: 'certificate';
48
+ type: string;
49
+ name: string;
50
+ iconURL: string;
51
+ description: string;
52
+ documentationURL: string;
53
+ fields: Record<string, CertificateFieldDescriptor>;
54
+ registryOperator?: PubKeyHex;
55
+ }
56
+ export type DefinitionData = BasketDefinitionData | ProtocolDefinitionData | CertificateDefinitionData;
57
+ export interface TokenData {
58
+ txid: string;
59
+ outputIndex: number;
60
+ satoshis: number;
61
+ lockingScript: string;
62
+ }
63
+ export type RegistryRecord = DefinitionData & TokenData;
64
+ interface BasketMapQuery {
65
+ basketID?: string;
66
+ registryOperators?: string[];
67
+ name?: string;
68
+ }
69
+ interface ProtoMapQuery {
70
+ name?: string;
71
+ registryOperators?: string[];
72
+ protocolID?: string;
73
+ securityLevel?: number;
74
+ }
75
+ interface CertMapQuery {
76
+ type?: string;
77
+ name?: string;
78
+ registryOperators?: string[];
79
+ }
80
+ export interface RegistryQueryMapping {
81
+ basket: BasketMapQuery;
82
+ protocol: ProtoMapQuery;
83
+ certificate: CertMapQuery;
84
+ }
85
+ export {};
86
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/registry/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,UAAU,GAAG,aAAa,CAAA;AAElE;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAA;IACnC,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,QAAQ,CAAA;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,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,UAAU,YAAY;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC7B;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,cAAc,CAAA;IACtB,QAAQ,EAAE,aAAa,CAAA;IACvB,WAAW,EAAE,YAAY,CAAA;CAC1B"}
@@ -0,0 +1,25 @@
1
+ export interface DownloaderConfig {
2
+ networkPreset: 'mainnet' | 'testnet' | 'local';
3
+ }
4
+ export interface DownloadResult {
5
+ data: number[];
6
+ mimeType: string | null;
7
+ }
8
+ /**
9
+ * Locates HTTP URLs where content can be downloaded. It uses the passed or the default one.
10
+ *
11
+ * @param {Object} obj All parameters are passed in an object.
12
+ * @param {String} obj.uhrpUrl The UHRP url to resolve.
13
+ * @param {string} obj.confederacyHost HTTPS URL for for the with default setting.
14
+ *
15
+ * @return {Array<String>} An array of HTTP URLs where content can be downloaded.
16
+ * @throws {Error} If UHRP url parameter invalid or is not an array
17
+ * or there is an error retrieving url(s) stored in the UHRP token.
18
+ */
19
+ export declare class StorageDownloader {
20
+ private readonly networkPreset?;
21
+ constructor(config?: DownloaderConfig);
22
+ resolve(uhrpUrl: string): Promise<string[]>;
23
+ download(uhrpUrl: string): Promise<DownloadResult>;
24
+ }
25
+ //# sourceMappingURL=StorageDownloader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageDownloader.d.ts","sourceRoot":"","sources":["../../../../src/storage/StorageDownloader.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAAA;CAC/C;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB;AAED;;;;;;;;;;GAUG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAA6C;gBAE/D,MAAM,CAAC,EAAE,gBAAgB;IAIzB,OAAO,CAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAgB5C,QAAQ,CAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;CAyCjE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=StorageDownloader.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageDownloader.test.d.ts","sourceRoot":"","sources":["../../../../../src/storage/__test/StorageDownloader.test.ts"],"names":[],"mappings":""}
@@ -1,3 +1,4 @@
1
1
  export * as StorageUtils from './StorageUtils.js';
2
2
  export { StorageUploader } from './StorageUploader.js';
3
+ export { StorageDownloader } from './StorageDownloader.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAEtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA"}