@mysten/walrus 0.2.0 → 0.2.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 (167) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/client.d.ts +8 -1
  3. package/dist/cjs/client.js +100 -69
  4. package/dist/cjs/client.js.map +3 -3
  5. package/dist/cjs/contracts/subsidies/subsidies.d.ts +204 -41
  6. package/dist/cjs/contracts/subsidies/subsidies.js +213 -177
  7. package/dist/cjs/contracts/subsidies/subsidies.js.map +2 -2
  8. package/dist/cjs/contracts/utils/index.d.ts +1 -1
  9. package/dist/cjs/contracts/utils/index.js +53 -5
  10. package/dist/cjs/contracts/utils/index.js.map +3 -3
  11. package/dist/cjs/contracts/wal/wal.d.ts +19 -8
  12. package/dist/cjs/contracts/wal/wal.js +26 -24
  13. package/dist/cjs/contracts/wal/wal.js.map +2 -2
  14. package/dist/cjs/contracts/wal_exchange/wal_exchange.d.ts +185 -44
  15. package/dist/cjs/contracts/wal_exchange/wal_exchange.js +208 -188
  16. package/dist/cjs/contracts/wal_exchange/wal_exchange.js.map +2 -2
  17. package/dist/cjs/contracts/walrus/apportionment_queue.d.ts +35 -14
  18. package/dist/cjs/contracts/walrus/apportionment_queue.js +42 -40
  19. package/dist/cjs/contracts/walrus/apportionment_queue.js.map +2 -2
  20. package/dist/cjs/contracts/walrus/auth.d.ts +34 -15
  21. package/dist/cjs/contracts/walrus/auth.js +47 -42
  22. package/dist/cjs/contracts/walrus/auth.js.map +2 -2
  23. package/dist/cjs/contracts/walrus/blob.d.ts +196 -56
  24. package/dist/cjs/contracts/walrus/blob.js +231 -200
  25. package/dist/cjs/contracts/walrus/blob.js.map +2 -2
  26. package/dist/cjs/contracts/walrus/committee.d.ts +37 -14
  27. package/dist/cjs/contracts/walrus/committee.js +50 -42
  28. package/dist/cjs/contracts/walrus/committee.js.map +2 -2
  29. package/dist/cjs/contracts/walrus/encoding.d.ts +18 -5
  30. package/dist/cjs/contracts/walrus/encoding.js +11 -12
  31. package/dist/cjs/contracts/walrus/encoding.js.map +2 -2
  32. package/dist/cjs/contracts/walrus/extended_field.d.ts +51 -22
  33. package/dist/cjs/contracts/walrus/extended_field.js +73 -62
  34. package/dist/cjs/contracts/walrus/extended_field.js.map +2 -2
  35. package/dist/cjs/contracts/walrus/init.d.ts +41 -8
  36. package/dist/cjs/contracts/walrus/init.js +42 -32
  37. package/dist/cjs/contracts/walrus/init.js.map +2 -2
  38. package/dist/cjs/contracts/walrus/metadata.d.ts +49 -14
  39. package/dist/cjs/contracts/walrus/metadata.js +54 -49
  40. package/dist/cjs/contracts/walrus/metadata.js.map +2 -2
  41. package/dist/cjs/contracts/walrus/node_metadata.d.ts +91 -29
  42. package/dist/cjs/contracts/walrus/node_metadata.js +123 -110
  43. package/dist/cjs/contracts/walrus/node_metadata.js.map +2 -2
  44. package/dist/cjs/contracts/walrus/shared_blob.d.ts +66 -20
  45. package/dist/cjs/contracts/walrus/shared_blob.js +83 -69
  46. package/dist/cjs/contracts/walrus/shared_blob.js.map +3 -3
  47. package/dist/cjs/contracts/walrus/staked_wal.d.ts +92 -26
  48. package/dist/cjs/contracts/walrus/staked_wal.js +98 -87
  49. package/dist/cjs/contracts/walrus/staked_wal.js.map +2 -2
  50. package/dist/cjs/contracts/walrus/staking.d.ts +425 -83
  51. package/dist/cjs/contracts/walrus/staking.js +445 -378
  52. package/dist/cjs/contracts/walrus/staking.js.map +2 -2
  53. package/dist/cjs/contracts/walrus/storage_accounting.d.ts +46 -17
  54. package/dist/cjs/contracts/walrus/storage_accounting.js +70 -59
  55. package/dist/cjs/contracts/walrus/storage_accounting.js.map +2 -2
  56. package/dist/cjs/contracts/walrus/storage_node.d.ts +57 -20
  57. package/dist/cjs/contracts/walrus/storage_node.js +71 -64
  58. package/dist/cjs/contracts/walrus/storage_node.js.map +2 -2
  59. package/dist/cjs/contracts/walrus/storage_resource.d.ts +96 -29
  60. package/dist/cjs/contracts/walrus/storage_resource.js +116 -109
  61. package/dist/cjs/contracts/walrus/storage_resource.js.map +2 -2
  62. package/dist/cjs/contracts/walrus/system.d.ts +316 -59
  63. package/dist/cjs/contracts/walrus/system.js +320 -269
  64. package/dist/cjs/contracts/walrus/system.js.map +2 -2
  65. package/dist/cjs/contracts/walrus/upgrade.d.ts +116 -20
  66. package/dist/cjs/contracts/walrus/upgrade.js +94 -87
  67. package/dist/cjs/contracts/walrus/upgrade.js.map +2 -2
  68. package/dist/cjs/fan-out-proxy/client.js +17 -1
  69. package/dist/cjs/fan-out-proxy/client.js.map +2 -2
  70. package/dist/cjs/read/quilt.d.ts +23 -0
  71. package/dist/cjs/read/quilt.js +253 -0
  72. package/dist/cjs/read/quilt.js.map +7 -0
  73. package/dist/cjs/types.d.ts +5 -1
  74. package/dist/cjs/types.js.map +1 -1
  75. package/dist/cjs/utils/bcs.d.ts +49 -0
  76. package/dist/cjs/utils/bcs.js +45 -0
  77. package/dist/cjs/utils/bcs.js.map +2 -2
  78. package/dist/cjs/utils/index.d.ts +2 -0
  79. package/dist/cjs/utils/index.js +9 -0
  80. package/dist/cjs/utils/index.js.map +2 -2
  81. package/dist/cjs/utils/quilts.d.ts +33 -0
  82. package/dist/cjs/utils/quilts.js +81 -0
  83. package/dist/cjs/utils/quilts.js.map +7 -0
  84. package/dist/esm/client.d.ts +8 -1
  85. package/dist/esm/client.js +105 -71
  86. package/dist/esm/client.js.map +3 -3
  87. package/dist/esm/contracts/subsidies/subsidies.d.ts +204 -41
  88. package/dist/esm/contracts/subsidies/subsidies.js +213 -177
  89. package/dist/esm/contracts/subsidies/subsidies.js.map +2 -2
  90. package/dist/esm/contracts/utils/index.d.ts +1 -1
  91. package/dist/esm/contracts/utils/index.js +53 -5
  92. package/dist/esm/contracts/utils/index.js.map +3 -3
  93. package/dist/esm/contracts/wal/wal.d.ts +19 -8
  94. package/dist/esm/contracts/wal/wal.js +26 -24
  95. package/dist/esm/contracts/wal/wal.js.map +2 -2
  96. package/dist/esm/contracts/wal_exchange/wal_exchange.d.ts +185 -44
  97. package/dist/esm/contracts/wal_exchange/wal_exchange.js +208 -188
  98. package/dist/esm/contracts/wal_exchange/wal_exchange.js.map +2 -2
  99. package/dist/esm/contracts/walrus/apportionment_queue.d.ts +35 -14
  100. package/dist/esm/contracts/walrus/apportionment_queue.js +42 -40
  101. package/dist/esm/contracts/walrus/apportionment_queue.js.map +2 -2
  102. package/dist/esm/contracts/walrus/auth.d.ts +34 -15
  103. package/dist/esm/contracts/walrus/auth.js +47 -42
  104. package/dist/esm/contracts/walrus/auth.js.map +2 -2
  105. package/dist/esm/contracts/walrus/blob.d.ts +196 -56
  106. package/dist/esm/contracts/walrus/blob.js +231 -200
  107. package/dist/esm/contracts/walrus/blob.js.map +2 -2
  108. package/dist/esm/contracts/walrus/committee.d.ts +37 -14
  109. package/dist/esm/contracts/walrus/committee.js +50 -42
  110. package/dist/esm/contracts/walrus/committee.js.map +2 -2
  111. package/dist/esm/contracts/walrus/encoding.d.ts +18 -5
  112. package/dist/esm/contracts/walrus/encoding.js +11 -12
  113. package/dist/esm/contracts/walrus/encoding.js.map +2 -2
  114. package/dist/esm/contracts/walrus/extended_field.d.ts +51 -22
  115. package/dist/esm/contracts/walrus/extended_field.js +73 -62
  116. package/dist/esm/contracts/walrus/extended_field.js.map +2 -2
  117. package/dist/esm/contracts/walrus/init.d.ts +41 -8
  118. package/dist/esm/contracts/walrus/init.js +42 -32
  119. package/dist/esm/contracts/walrus/init.js.map +2 -2
  120. package/dist/esm/contracts/walrus/metadata.d.ts +49 -14
  121. package/dist/esm/contracts/walrus/metadata.js +54 -49
  122. package/dist/esm/contracts/walrus/metadata.js.map +2 -2
  123. package/dist/esm/contracts/walrus/node_metadata.d.ts +91 -29
  124. package/dist/esm/contracts/walrus/node_metadata.js +123 -110
  125. package/dist/esm/contracts/walrus/node_metadata.js.map +2 -2
  126. package/dist/esm/contracts/walrus/shared_blob.d.ts +66 -20
  127. package/dist/esm/contracts/walrus/shared_blob.js +83 -69
  128. package/dist/esm/contracts/walrus/shared_blob.js.map +3 -3
  129. package/dist/esm/contracts/walrus/staked_wal.d.ts +92 -26
  130. package/dist/esm/contracts/walrus/staked_wal.js +98 -87
  131. package/dist/esm/contracts/walrus/staked_wal.js.map +2 -2
  132. package/dist/esm/contracts/walrus/staking.d.ts +425 -83
  133. package/dist/esm/contracts/walrus/staking.js +445 -378
  134. package/dist/esm/contracts/walrus/staking.js.map +2 -2
  135. package/dist/esm/contracts/walrus/storage_accounting.d.ts +46 -17
  136. package/dist/esm/contracts/walrus/storage_accounting.js +70 -59
  137. package/dist/esm/contracts/walrus/storage_accounting.js.map +2 -2
  138. package/dist/esm/contracts/walrus/storage_node.d.ts +57 -20
  139. package/dist/esm/contracts/walrus/storage_node.js +71 -64
  140. package/dist/esm/contracts/walrus/storage_node.js.map +2 -2
  141. package/dist/esm/contracts/walrus/storage_resource.d.ts +96 -29
  142. package/dist/esm/contracts/walrus/storage_resource.js +116 -109
  143. package/dist/esm/contracts/walrus/storage_resource.js.map +2 -2
  144. package/dist/esm/contracts/walrus/system.d.ts +316 -59
  145. package/dist/esm/contracts/walrus/system.js +320 -269
  146. package/dist/esm/contracts/walrus/system.js.map +2 -2
  147. package/dist/esm/contracts/walrus/upgrade.d.ts +116 -20
  148. package/dist/esm/contracts/walrus/upgrade.js +94 -87
  149. package/dist/esm/contracts/walrus/upgrade.js.map +2 -2
  150. package/dist/esm/fan-out-proxy/client.js +17 -1
  151. package/dist/esm/fan-out-proxy/client.js.map +2 -2
  152. package/dist/esm/read/quilt.d.ts +23 -0
  153. package/dist/esm/read/quilt.js +233 -0
  154. package/dist/esm/read/quilt.js.map +7 -0
  155. package/dist/esm/types.d.ts +5 -1
  156. package/dist/esm/utils/bcs.d.ts +49 -0
  157. package/dist/esm/utils/bcs.js +45 -0
  158. package/dist/esm/utils/bcs.js.map +2 -2
  159. package/dist/esm/utils/index.d.ts +2 -0
  160. package/dist/esm/utils/index.js +9 -0
  161. package/dist/esm/utils/index.js.map +2 -2
  162. package/dist/esm/utils/quilts.d.ts +33 -0
  163. package/dist/esm/utils/quilts.js +61 -0
  164. package/dist/esm/utils/quilts.js.map +7 -0
  165. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  166. package/dist/tsconfig.tsbuildinfo +1 -1
  167. package/package.json +8 -8
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/fan-out-proxy/client.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { ConnectionTimeoutError, StorageNodeAPIError } from '../storage-node/error.js';\nimport { UserAbortError } from '../storage-node/error.js';\nimport type { mergeHeaders } from '../storage-node/utils.js';\nimport type {\n\tEncodingType,\n\tFanOutTipConfig,\n\tProtocolMessageCertificate,\n\tTipStrategy,\n\tWalrusClientRequestOptions,\n} from '../types.js';\nimport { fromUrlSafeBase64, urlSafeBase64 } from '../utils/index.js';\n\nexport type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;\n\nexport type FanOutProxyClientOptions = {\n\thost: string;\n\t/**\n\t * An optional custom fetch function.\n\t *\n\t * If not provided, defaults to the global `fetch` function (`globalThis.fetch`).\n\t *\n\t * @default globalThis.fetch\n\t */\n\tfetch?: Fetch;\n\n\t/**\n\t * An optional timeout for requests.\n\t * @default 30_000ms (30 seconds)\n\t */\n\ttimeout?: number;\n\n\t/**\n\t * Callback for individual network errors.\n\t */\n\tonError?: (error: Error) => void;\n};\n\nexport type RequestOptions = {\n\tpath: string;\n\ttimeout?: number;\n\theaders?: ReturnType<typeof mergeHeaders>;\n} & Omit<RequestInit, 'headers'>;\n\nexport type WriteBlobToFanOutProxyOptions = {\n\tblobId: string;\n\tnonce: Uint8Array;\n\ttxDigest: string;\n\tblob: Uint8Array;\n\tblobObjectId: string;\n\tdeletable: boolean;\n\trequiresTip: boolean;\n\tencodingType?: EncodingType;\n} & WalrusClientRequestOptions;\n\nexport class FanOutProxyClient {\n\thost: string;\n\t#fetch: Fetch;\n\t#timeout: number;\n\t#onError?: (error: Error) => void;\n\tconstructor({ host, fetch: overriddenFetch, timeout, onError }: FanOutProxyClientOptions) {\n\t\tthis.host = host;\n\t\tthis.#fetch = overriddenFetch ?? globalThis.fetch;\n\t\tthis.#timeout = timeout ?? 30_000;\n\t\tthis.#onError = onError;\n\t}\n\n\tasync tipConfig(): Promise<FanOutTipConfig> {\n\t\tconst response = await this.#request({\n\t\t\tmethod: 'GET',\n\t\t\tpath: '/v1/tip-config',\n\t\t});\n\n\t\tconst data = (await response.json()) as {\n\t\t\tsend_tip: {\n\t\t\t\taddress: string;\n\t\t\t\tkind: TipStrategy;\n\t\t\t};\n\t\t};\n\n\t\treturn data.send_tip;\n\t}\n\n\tasync writeBlob({\n\t\tblobId,\n\t\tnonce,\n\t\ttxDigest,\n\t\tblob,\n\t\tdeletable,\n\t\tblobObjectId,\n\t\trequiresTip,\n\t\tencodingType,\n\t\t...options\n\t}: WriteBlobToFanOutProxyOptions): Promise<{\n\t\tblobId: string;\n\t\tcertificate: ProtocolMessageCertificate;\n\t}> {\n\t\tconst query = new URLSearchParams({\n\t\t\tblob_id: blobId,\n\t\t});\n\n\t\tif (requiresTip) {\n\t\t\tquery.set('nonce', urlSafeBase64(nonce));\n\t\t\tquery.set('tx_id', txDigest);\n\t\t}\n\n\t\tif (deletable) {\n\t\t\tquery.set('deletable_blob_object', blobObjectId);\n\t\t}\n\n\t\tif (encodingType) {\n\t\t\tquery.set('encoding_type', encodingType);\n\t\t}\n\n\t\tconst response = await this.#request({\n\t\t\tmethod: 'POST',\n\t\t\tpath: `/v1/blob-fan-out?${query.toString()}`,\n\t\t\tbody: blob,\n\t\t\t...options,\n\t\t});\n\n\t\tconst data: {\n\t\t\tblob_id: number[];\n\t\t\tconfirmation_certificate: {\n\t\t\t\tsigners: number[];\n\t\t\t\tserialized_message: number[];\n\t\t\t\tsignature: string;\n\t\t\t};\n\t\t} = await response.json();\n\n\t\treturn {\n\t\t\tblobId,\n\t\t\tcertificate: {\n\t\t\t\tsigners: data.confirmation_certificate.signers,\n\t\t\t\tserializedMessage: new Uint8Array(data.confirmation_certificate.serialized_message),\n\t\t\t\tsignature: fromUrlSafeBase64(data.confirmation_certificate.signature),\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #request(options: RequestOptions) {\n\t\tconst { signal, timeout, ...init } = options;\n\n\t\tif (signal?.aborted) {\n\t\t\tthrow new UserAbortError();\n\t\t}\n\n\t\tconst timeoutSignal = AbortSignal.timeout(timeout ?? this.#timeout);\n\n\t\tlet response: Response | undefined;\n\n\t\ttry {\n\t\t\tresponse = await (0, this.#fetch)(`${this.host}${options.path}`, {\n\t\t\t\t...init,\n\t\t\t\tsignal: signal ? AbortSignal.any([timeoutSignal, signal]) : timeoutSignal,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (signal?.aborted) {\n\t\t\t\tthrow new UserAbortError();\n\t\t\t}\n\n\t\t\tif (error instanceof Error && error.name === 'AbortError') {\n\t\t\t\tconst error = new ConnectionTimeoutError();\n\t\t\t\tthis.#onError?.(error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tthis.#onError?.(error as Error);\n\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!response.ok) {\n\t\t\tconst errorText = await response.text().catch((reason) => reason);\n\t\t\tconst errorJSON = safeParseJSON(errorText);\n\t\t\tconst errorMessage = errorJSON ? undefined : errorText;\n\t\t\tconst error = StorageNodeAPIError.generate(response.status, errorJSON, errorMessage);\n\t\t\tthis.#onError?.(error);\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn response;\n\t}\n}\n\nfunction safeParseJSON(value: string) {\n\ttry {\n\t\treturn JSON.parse(value);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA4D;AAC5D,IAAAA,gBAA+B;AAS/B,mBAA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odeAPIError } from '../storage-node/error.js';\nimport { UserAbortError } from '../storage-node/error.js';\nimport type { mergeHeaders } from '../storage-node/utils.js';\nimport type {\n\tEncodingType,\n\tFanOutTipConfig,\n\tProtocolMessageCertificate,\n\tWalrusClientRequestOptions,\n} from '../types.js';\nimport { fromUrlSafeBase64, urlSafeBase64 } from '../utils/index.js';\n\nexport type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;\n\nexport type FanOutProxyClientOptions = {\n\thost: string;\n\t/**\n\t * An optional custom fetch function.\n\t *\n\t * If not provided, defaults to the global `fetch` function (`globalThis.fetch`).\n\t *\n\t * @default globalThis.fetch\n\t */\n\tfetch?: Fetch;\n\n\t/**\n\t * An optional timeout for requests.\n\t * @default 30_000ms (30 seconds)\n\t */\n\ttimeout?: number;\n\n\t/**\n\t * Callback for individual network errors.\n\t */\n\tonError?: (error: Error) => void;\n};\n\nexport type RequestOptions = {\n\tpath: string;\n\ttimeout?: number;\n\theaders?: ReturnType<typeof mergeHeaders>;\n} & Omit<RequestInit, 'headers'>;\n\nexport type WriteBlobToFanOutProxyOptions = {\n\tblobId: string;\n\tnonce: Uint8Array;\n\ttxDigest: string;\n\tblob: Uint8Array;\n\tblobObjectId: string;\n\tdeletable: boolean;\n\trequiresTip: boolean;\n\tencodingType?: EncodingType;\n} & WalrusClientRequestOptions;\n\nexport class FanOutProxyClient {\n\thost: string;\n\t#fetch: Fetch;\n\t#timeout: number;\n\t#onError?: (error: Error) => void;\n\tconstructor({ host, fetch: overriddenFetch, timeout, onError }: FanOutProxyClientOptions) {\n\t\tthis.host = host;\n\t\tthis.#fetch = overriddenFetch ?? globalThis.fetch;\n\t\tthis.#timeout = timeout ?? 30_000;\n\t\tthis.#onError = onError;\n\t}\n\n\tasync tipConfig(): Promise<FanOutTipConfig> {\n\t\tconst response = await this.#request({\n\t\t\tmethod: 'GET',\n\t\t\tpath: '/v1/tip-config',\n\t\t});\n\n\t\tconst data = (await response.json()) as {\n\t\t\tsend_tip: {\n\t\t\t\taddress: string;\n\t\t\t\tkind:\n\t\t\t\t\t| {\n\t\t\t\t\t\t\tconst: number;\n\t\t\t\t\t }\n\t\t\t\t\t| {\n\t\t\t\t\t\t\tbase: number;\n\t\t\t\t\t\t\tencoded_size_mul_per_kb: number;\n\t\t\t\t\t };\n\t\t\t};\n\t\t};\n\n\t\tif ('const' in data.send_tip.kind) {\n\t\t\treturn {\n\t\t\t\taddress: data.send_tip.address,\n\t\t\t\tkind: {\n\t\t\t\t\tconst: data.send_tip.kind.const,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\taddress: data.send_tip.address,\n\t\t\tkind: {\n\t\t\t\tlinear: {\n\t\t\t\t\tbase: data.send_tip.kind.base,\n\t\t\t\t\tperEncodedKb: data.send_tip.kind.encoded_size_mul_per_kb,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\tasync writeBlob({\n\t\tblobId,\n\t\tnonce,\n\t\ttxDigest,\n\t\tblob,\n\t\tdeletable,\n\t\tblobObjectId,\n\t\trequiresTip,\n\t\tencodingType,\n\t\t...options\n\t}: WriteBlobToFanOutProxyOptions): Promise<{\n\t\tblobId: string;\n\t\tcertificate: ProtocolMessageCertificate;\n\t}> {\n\t\tconst query = new URLSearchParams({\n\t\t\tblob_id: blobId,\n\t\t});\n\n\t\tif (requiresTip) {\n\t\t\tquery.set('nonce', urlSafeBase64(nonce));\n\t\t\tquery.set('tx_id', txDigest);\n\t\t}\n\n\t\tif (deletable) {\n\t\t\tquery.set('deletable_blob_object', blobObjectId);\n\t\t}\n\n\t\tif (encodingType) {\n\t\t\tquery.set('encoding_type', encodingType);\n\t\t}\n\n\t\tconst response = await this.#request({\n\t\t\tmethod: 'POST',\n\t\t\tpath: `/v1/blob-fan-out?${query.toString()}`,\n\t\t\tbody: blob,\n\t\t\t...options,\n\t\t});\n\n\t\tconst data: {\n\t\t\tblob_id: number[];\n\t\t\tconfirmation_certificate: {\n\t\t\t\tsigners: number[];\n\t\t\t\tserialized_message: number[];\n\t\t\t\tsignature: string;\n\t\t\t};\n\t\t} = await response.json();\n\n\t\treturn {\n\t\t\tblobId,\n\t\t\tcertificate: {\n\t\t\t\tsigners: data.confirmation_certificate.signers,\n\t\t\t\tserializedMessage: new Uint8Array(data.confirmation_certificate.serialized_message),\n\t\t\t\tsignature: fromUrlSafeBase64(data.confirmation_certificate.signature),\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #request(options: RequestOptions) {\n\t\tconst { signal, timeout, ...init } = options;\n\n\t\tif (signal?.aborted) {\n\t\t\tthrow new UserAbortError();\n\t\t}\n\n\t\tconst timeoutSignal = AbortSignal.timeout(timeout ?? this.#timeout);\n\n\t\tlet response: Response | undefined;\n\n\t\ttry {\n\t\t\tresponse = await (0, this.#fetch)(`${this.host}${options.path}`, {\n\t\t\t\t...init,\n\t\t\t\tsignal: signal ? AbortSignal.any([timeoutSignal, signal]) : timeoutSignal,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (signal?.aborted) {\n\t\t\t\tthrow new UserAbortError();\n\t\t\t}\n\n\t\t\tif (error instanceof Error && error.name === 'AbortError') {\n\t\t\t\tconst error = new ConnectionTimeoutError();\n\t\t\t\tthis.#onError?.(error);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tthis.#onError?.(error as Error);\n\n\t\t\tthrow error;\n\t\t}\n\n\t\tif (!response.ok) {\n\t\t\tconst errorText = await response.text().catch((reason) => reason);\n\t\t\tconst errorJSON = safeParseJSON(errorText);\n\t\t\tconst errorMessage = errorJSON ? undefined : errorText;\n\t\t\tconst error = StorageNodeAPIError.generate(response.status, errorJSON, errorMessage);\n\t\t\tthis.#onError?.(error);\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn response;\n\t}\n}\n\nfunction safeParseJSON(value: string) {\n\ttry {\n\t\treturn JSON.parse(value);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;A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AW,MAAM;AAChE,UAAM,YAAY,cAAc,SAAS;AACzC,UAAM,eAAe,YAAY,SAAY;AAC7C,UAAM,QAAQ,iCAAoB,SAAS,SAAS,QAAQ,WAAW,YAAY;AACnF,6BAAK,cAAL,8BAAgB;AAChB,UAAM;AAAA,EACP;AAEA,SAAO;AACR;AAGD,SAAS,cAAc,OAAe;AACrC,MAAI;AACH,WAAO,KAAK,MAAM,KAAK;AAAA,EACxB,QAAQ;AACP,WAAO;AAAA,EACR;AACD;",
6
6
  "names": ["import_error", "error"]
7
7
  }
@@ -0,0 +1,23 @@
1
+ import type { WalrusClient } from '../client.js';
2
+ export interface QuiltReaderOptions {
3
+ client: WalrusClient;
4
+ blobId: string;
5
+ numShards: number;
6
+ }
7
+ export declare class QuiltReader {
8
+ #private;
9
+ blobId: string;
10
+ constructor({ client, blobId, numShards }: QuiltReaderOptions);
11
+ getFullBlob(): Promise<Uint8Array<ArrayBufferLike>>;
12
+ readByPatchId(id: string): Promise<{
13
+ identifier: string;
14
+ tags: Map<string, string> | null;
15
+ blobContents: Uint8Array<ArrayBuffer>;
16
+ }>;
17
+ readIndex(): Promise<{
18
+ endIndex: number;
19
+ identifier: string;
20
+ tags: Map<string, string>;
21
+ startIndex: number;
22
+ }[]>;
23
+ }
@@ -0,0 +1,253 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
26
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
27
+ var quilt_exports = {};
28
+ __export(quilt_exports, {
29
+ QuiltReader: () => QuiltReader
30
+ });
31
+ module.exports = __toCommonJS(quilt_exports);
32
+ var import_bcs = require("@mysten/bcs");
33
+ var import_bcs2 = require("../utils/bcs.js");
34
+ var import_quilts = require("../utils/quilts.js");
35
+ var import_utils = require("../utils/index.js");
36
+ var _client, _secondarySlivers, _numShards, _blobBytes, _columnSize, _QuiltReader_instances, getSecondarySliver_fn, sliverator_fn, readBytesFromSlivers_fn, readBytesFromBlob_fn, readBytes_fn, readBlob_fn, getColumnSize_fn, getSizes_fn;
37
+ const HAS_TAGS_FLAG = 1 << 0;
38
+ class QuiltReader {
39
+ constructor({ client, blobId, numShards }) {
40
+ __privateAdd(this, _QuiltReader_instances);
41
+ __privateAdd(this, _client);
42
+ __privateAdd(this, _secondarySlivers, /* @__PURE__ */ new Map());
43
+ __privateAdd(this, _numShards);
44
+ __privateAdd(this, _blobBytes, null);
45
+ __privateAdd(this, _columnSize, null);
46
+ __privateSet(this, _client, client);
47
+ this.blobId = blobId;
48
+ __privateSet(this, _numShards, numShards);
49
+ }
50
+ async getFullBlob() {
51
+ if (!__privateGet(this, _blobBytes)) {
52
+ __privateSet(this, _blobBytes, __privateGet(this, _client).readBlob({ blobId: this.blobId }));
53
+ }
54
+ return __privateGet(this, _blobBytes);
55
+ }
56
+ async readByPatchId(id) {
57
+ const { quiltId, patchId } = (0, import_quilts.parseQuiltPatchId)(id);
58
+ if (quiltId !== this.blobId) {
59
+ throw new Error(`The requested patch ${patchId} is not part of the quilt ${this.blobId}`);
60
+ }
61
+ const sliverIndexes = [];
62
+ for (let i = patchId.startIndex; i < patchId.endIndex; i++) {
63
+ sliverIndexes.push(i);
64
+ }
65
+ if (sliverIndexes.length === 0) {
66
+ throw new Error(`The requested patch ${patchId} is invalid`);
67
+ }
68
+ return __privateMethod(this, _QuiltReader_instances, readBlob_fn).call(this, sliverIndexes);
69
+ }
70
+ async readIndex() {
71
+ const header = new DataView((await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, 0, 5)).buffer);
72
+ const version = header.getUint8(0);
73
+ if (version !== 1) {
74
+ throw new Error(`Unsupported quilt version ${version}`);
75
+ }
76
+ const indexSize = header.getUint32(1, true);
77
+ const indexBytes = await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, 0, indexSize, 5);
78
+ const indexSlivers = Math.ceil(indexSize / await __privateMethod(this, _QuiltReader_instances, getColumnSize_fn).call(this));
79
+ const index = import_bcs2.QuiltIndexV1.parse(indexBytes);
80
+ return index.patches.map((patch, i) => ({
81
+ startIndex: i === 0 ? indexSlivers : index.patches[i - 1].endIndex,
82
+ ...patch
83
+ }));
84
+ }
85
+ }
86
+ _client = new WeakMap();
87
+ _secondarySlivers = new WeakMap();
88
+ _numShards = new WeakMap();
89
+ _blobBytes = new WeakMap();
90
+ _columnSize = new WeakMap();
91
+ _QuiltReader_instances = new WeakSet();
92
+ getSecondarySliver_fn = async function({
93
+ sliverIndex,
94
+ signal
95
+ }) {
96
+ if (__privateGet(this, _secondarySlivers).has(sliverIndex)) {
97
+ return __privateGet(this, _secondarySlivers).get(sliverIndex);
98
+ }
99
+ const sliverPromise = __privateGet(this, _client).getSecondarySliver({
100
+ blobId: this.blobId,
101
+ index: sliverIndex,
102
+ signal
103
+ }).then((sliver) => new Uint8Array(sliver.symbols.data));
104
+ __privateGet(this, _secondarySlivers).set(sliverIndex, sliverPromise);
105
+ try {
106
+ const sliver = await sliverPromise;
107
+ __privateGet(this, _secondarySlivers).set(sliverIndex, sliver);
108
+ return sliver;
109
+ } catch (error) {
110
+ __privateGet(this, _secondarySlivers).delete(sliverIndex);
111
+ throw error;
112
+ }
113
+ };
114
+ sliverator_fn = async function* (startIndex) {
115
+ for (let i = startIndex; i < __privateGet(this, _numShards); i++) {
116
+ yield __privateMethod(this, _QuiltReader_instances, getSecondarySliver_fn).call(this, { sliverIndex: i });
117
+ }
118
+ };
119
+ readBytesFromSlivers_fn = async function(sliver, length, offset = 0, columnSize) {
120
+ if (!length) {
121
+ return new Uint8Array(0);
122
+ }
123
+ columnSize = columnSize ?? (await __privateMethod(this, _QuiltReader_instances, getSecondarySliver_fn).call(this, { sliverIndex: sliver })).length;
124
+ const columnOffset = Math.floor(offset / columnSize);
125
+ let remainingOffset = offset % columnSize;
126
+ const slivers = __privateMethod(this, _QuiltReader_instances, sliverator_fn).call(this, sliver + columnOffset);
127
+ const bytes = new Uint8Array(length);
128
+ let bytesRead = 0;
129
+ for await (const sliver2 of slivers) {
130
+ let chunk = remainingOffset > 0 ? sliver2.subarray(remainingOffset) : sliver2;
131
+ remainingOffset -= chunk.length;
132
+ if (chunk.length > length - bytesRead) {
133
+ chunk = chunk.subarray(0, length - bytesRead);
134
+ }
135
+ bytes.set(chunk, bytesRead);
136
+ bytesRead += chunk.length;
137
+ if (bytesRead === length) {
138
+ break;
139
+ }
140
+ }
141
+ return bytes;
142
+ };
143
+ readBytesFromBlob_fn = async function(startColumn, length, offset = 0) {
144
+ const result = new Uint8Array(length);
145
+ if (!length) {
146
+ return result;
147
+ }
148
+ const blob = await this.getFullBlob();
149
+ const { rowSize, symbolSize } = __privateMethod(this, _QuiltReader_instances, getSizes_fn).call(this, blob.length);
150
+ const nRows = blob.length / rowSize;
151
+ const symbolsToSkip = Math.floor(offset / symbolSize);
152
+ let remainingOffset = offset % symbolSize;
153
+ let currentCol = startColumn + Math.floor(symbolsToSkip / nRows);
154
+ let currentRow = symbolsToSkip % nRows;
155
+ let bytesRead = 0;
156
+ function addSlice(col, row, skip, take) {
157
+ const baseIndex = row * rowSize + col * symbolSize;
158
+ const startIndex = baseIndex + skip;
159
+ const endIndex = Math.min(baseIndex + symbolSize, startIndex + take, blob.length);
160
+ if (startIndex >= blob.length) {
161
+ throw new Error("Index out of bounds");
162
+ }
163
+ const size = endIndex - startIndex;
164
+ const subArray = blob.subarray(startIndex, endIndex);
165
+ result.set(subArray, bytesRead);
166
+ bytesRead += size;
167
+ }
168
+ while (bytesRead < length) {
169
+ addSlice(currentCol, currentRow, remainingOffset, length - bytesRead);
170
+ remainingOffset = 0;
171
+ currentRow = (currentRow + 1) % nRows;
172
+ if (currentRow === 0) {
173
+ currentCol += 1;
174
+ }
175
+ }
176
+ return result;
177
+ };
178
+ readBytes_fn = async function(sliver, length, offset = 0, columnSize) {
179
+ if (__privateGet(this, _blobBytes)) {
180
+ return __privateMethod(this, _QuiltReader_instances, readBytesFromBlob_fn).call(this, sliver, length, offset);
181
+ }
182
+ try {
183
+ return await __privateMethod(this, _QuiltReader_instances, readBytesFromSlivers_fn).call(this, sliver, length, offset, columnSize);
184
+ } catch (_error) {
185
+ return __privateMethod(this, _QuiltReader_instances, readBytesFromBlob_fn).call(this, sliver, length, offset);
186
+ }
187
+ };
188
+ readBlob_fn = async function(sliverIndexes) {
189
+ const slivers = await Promise.all(
190
+ sliverIndexes.map((sliverIndex) => __privateMethod(this, _QuiltReader_instances, getSecondarySliver_fn).call(this, { sliverIndex }))
191
+ );
192
+ const firstSliver = slivers[0];
193
+ if (!firstSliver) {
194
+ throw new Error("Cannot read blob from an empty set of slivers");
195
+ }
196
+ const blobHeader = import_bcs2.QuiltPatchBlobHeader.parse(firstSliver);
197
+ let offset = import_quilts.QUILT_PATCH_BLOB_HEADER_SIZE;
198
+ let blobSize = blobHeader.length;
199
+ const identifierLength = new DataView(firstSliver.buffer, offset, 2).getUint16(0, true);
200
+ blobSize -= 2 + identifierLength;
201
+ offset += 2;
202
+ const identifier = import_bcs.bcs.string().parse(firstSliver.subarray(offset, offset + identifierLength));
203
+ offset += identifierLength;
204
+ let tags = null;
205
+ if (blobHeader.mask & HAS_TAGS_FLAG) {
206
+ const tagsSize = new DataView(firstSliver.buffer, offset, 2).getUint16(0, true);
207
+ offset += 2;
208
+ tags = import_bcs2.QuiltPatchTags.parse(firstSliver.subarray(offset, offset + tagsSize));
209
+ blobSize -= tagsSize + 2;
210
+ offset += tagsSize;
211
+ }
212
+ const blobContents = await __privateMethod(this, _QuiltReader_instances, readBytes_fn).call(this, sliverIndexes[0], blobSize, offset, firstSliver.length);
213
+ return {
214
+ identifier,
215
+ tags,
216
+ blobContents
217
+ };
218
+ };
219
+ getColumnSize_fn = async function() {
220
+ if (__privateGet(this, _columnSize)) {
221
+ return await __privateGet(this, _columnSize);
222
+ }
223
+ __privateSet(this, _columnSize, new Promise((resolve, reject) => {
224
+ if (__privateGet(this, _blobBytes)) {
225
+ Promise.resolve(__privateGet(this, _blobBytes)).then((bytes) => {
226
+ const { rowSize, symbolSize } = __privateMethod(this, _QuiltReader_instances, getSizes_fn).call(this, bytes.length);
227
+ return bytes.length / rowSize * symbolSize;
228
+ }).then(resolve).catch(reject);
229
+ }
230
+ return __privateMethod(this, _QuiltReader_instances, getSecondarySliver_fn).call(this, { sliverIndex: 0 }).then((sliver) => resolve(sliver.length)).catch(reject);
231
+ }).catch((error) => {
232
+ __privateSet(this, _columnSize, null);
233
+ throw error;
234
+ }));
235
+ return __privateGet(this, _columnSize);
236
+ };
237
+ getSizes_fn = function(encodedBlobSize) {
238
+ const { primarySymbols, secondarySymbols } = (0, import_utils.getSourceSymbols)(__privateGet(this, _numShards));
239
+ const totalSymbols = primarySymbols * secondarySymbols;
240
+ if (totalSymbols === 0) {
241
+ throw new Error("symbol size should not be 0");
242
+ }
243
+ if (encodedBlobSize % totalSymbols !== 0) {
244
+ throw new Error("blob length should be divisible by total symbols");
245
+ }
246
+ const symbolSize = encodedBlobSize / totalSymbols;
247
+ const rowSize = symbolSize * secondarySymbols;
248
+ return {
249
+ symbolSize,
250
+ rowSize
251
+ };
252
+ };
253
+ //# sourceMappingURL=quilt.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/read/quilt.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/bcs';\nimport { QuiltIndexV1, QuiltPatchBlobHeader, QuiltPatchTags } from '../utils/bcs.js';\nimport { parseQuiltPatchId, QUILT_PATCH_BLOB_HEADER_SIZE } from '../utils/quilts.js';\nimport type { WalrusClient } from '../client.js';\nimport { getSourceSymbols } from '../utils/index.js';\n\nconst HAS_TAGS_FLAG = 1 << 0;\n\nexport interface QuiltReaderOptions {\n\tclient: WalrusClient;\n\tblobId: string;\n\tnumShards: number;\n}\n\nexport class QuiltReader {\n\tblobId: string;\n\t#client: WalrusClient;\n\t#secondarySlivers = new Map<number, Uint8Array | Promise<Uint8Array>>();\n\t#numShards: number;\n\t#blobBytes: Uint8Array | Promise<Uint8Array> | null = null;\n\t#columnSize: number | Promise<number> | null = null;\n\n\tconstructor({ client, blobId, numShards }: QuiltReaderOptions) {\n\t\tthis.#client = client;\n\t\tthis.blobId = blobId;\n\t\tthis.#numShards = numShards;\n\t}\n\n\t// TODO: We should handle retries and epoch changes\n\tasync #getSecondarySliver({\n\t\tsliverIndex,\n\t\tsignal,\n\t}: {\n\t\tsliverIndex: number;\n\t\tsignal?: AbortSignal;\n\t}) {\n\t\tif (this.#secondarySlivers.has(sliverIndex)) {\n\t\t\treturn this.#secondarySlivers.get(sliverIndex)!;\n\t\t}\n\n\t\tconst sliverPromise = this.#client\n\t\t\t.getSecondarySliver({\n\t\t\t\tblobId: this.blobId,\n\t\t\t\tindex: sliverIndex,\n\t\t\t\tsignal,\n\t\t\t})\n\t\t\t.then((sliver) => new Uint8Array(sliver.symbols.data));\n\n\t\tthis.#secondarySlivers.set(sliverIndex, sliverPromise);\n\n\t\ttry {\n\t\t\tconst sliver = await sliverPromise;\n\t\t\tthis.#secondarySlivers.set(sliverIndex, sliver);\n\t\t\treturn sliver;\n\t\t} catch (error) {\n\t\t\tthis.#secondarySlivers.delete(sliverIndex);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync *#sliverator(startIndex: number) {\n\t\tfor (let i = startIndex; i < this.#numShards; i++) {\n\t\t\tyield this.#getSecondarySliver({ sliverIndex: i });\n\t\t}\n\t}\n\n\tasync #readBytesFromSlivers(sliver: number, length: number, offset = 0, columnSize?: number) {\n\t\tif (!length) {\n\t\t\treturn new Uint8Array(0);\n\t\t}\n\n\t\tcolumnSize = columnSize ?? (await this.#getSecondarySliver({ sliverIndex: sliver })).length;\n\t\tconst columnOffset = Math.floor(offset / columnSize);\n\t\tlet remainingOffset = offset % columnSize;\n\t\tconst slivers = this.#sliverator(sliver + columnOffset);\n\t\tconst bytes = new Uint8Array(length);\n\n\t\tlet bytesRead = 0;\n\n\t\tfor await (const sliver of slivers) {\n\t\t\tlet chunk = remainingOffset > 0 ? sliver.subarray(remainingOffset) : sliver;\n\t\t\tremainingOffset -= chunk.length;\n\t\t\tif (chunk.length > length - bytesRead) {\n\t\t\t\tchunk = chunk.subarray(0, length - bytesRead);\n\t\t\t}\n\n\t\t\tbytes.set(chunk, bytesRead);\n\t\t\tbytesRead += chunk.length;\n\n\t\t\tif (bytesRead === length) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn bytes;\n\t}\n\n\tasync #readBytesFromBlob(startColumn: number, length: number, offset = 0) {\n\t\tconst result = new Uint8Array(length);\n\n\t\tif (!length) {\n\t\t\treturn result;\n\t\t}\n\n\t\tconst blob = await this.getFullBlob();\n\t\tconst { rowSize, symbolSize } = this.#getSizes(blob.length);\n\n\t\tconst nRows = blob.length / rowSize;\n\t\tconst symbolsToSkip = Math.floor(offset / symbolSize);\n\t\tlet remainingOffset = offset % symbolSize;\n\t\tlet currentCol = startColumn + Math.floor(symbolsToSkip / nRows);\n\t\tlet currentRow = symbolsToSkip % nRows;\n\n\t\tlet bytesRead = 0;\n\n\t\tfunction addSlice(col: number, row: number, skip: number, take: number) {\n\t\t\tconst baseIndex = row * rowSize + col * symbolSize;\n\t\t\tconst startIndex = baseIndex + skip;\n\t\t\tconst endIndex = Math.min(baseIndex + symbolSize, startIndex + take, blob.length);\n\n\t\t\tif (startIndex >= blob.length) {\n\t\t\t\tthrow new Error('Index out of bounds');\n\t\t\t}\n\n\t\t\tconst size = endIndex - startIndex;\n\t\t\tconst subArray = blob.subarray(startIndex, endIndex);\n\t\t\tresult.set(subArray, bytesRead);\n\t\t\tbytesRead += size;\n\t\t}\n\n\t\twhile (bytesRead < length) {\n\t\t\taddSlice(currentCol, currentRow, remainingOffset, length - bytesRead);\n\t\t\tremainingOffset = 0;\n\n\t\t\tcurrentRow = (currentRow + 1) % nRows;\n\t\t\tif (currentRow === 0) {\n\t\t\t\tcurrentCol += 1;\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tasync #readBytes(sliver: number, length: number, offset = 0, columnSize?: number) {\n\t\tif (this.#blobBytes) {\n\t\t\treturn this.#readBytesFromBlob(sliver, length, offset);\n\t\t}\n\n\t\ttry {\n\t\t\treturn await this.#readBytesFromSlivers(sliver, length, offset, columnSize);\n\t\t} catch (_error) {\n\t\t\t// fallback to reading the full blob\n\t\t\treturn this.#readBytesFromBlob(sliver, length, offset);\n\t\t}\n\t}\n\n\tasync getFullBlob() {\n\t\tif (!this.#blobBytes) {\n\t\t\tthis.#blobBytes = this.#client.readBlob({ blobId: this.blobId });\n\t\t}\n\n\t\treturn this.#blobBytes;\n\t}\n\n\tasync #readBlob(sliverIndexes: number[]) {\n\t\tconst slivers = await Promise.all(\n\t\t\tsliverIndexes.map((sliverIndex) => this.#getSecondarySliver({ sliverIndex })),\n\t\t);\n\n\t\tconst firstSliver = slivers[0];\n\n\t\tif (!firstSliver) {\n\t\t\tthrow new Error('Cannot read blob from an empty set of slivers');\n\t\t}\n\n\t\tconst blobHeader = QuiltPatchBlobHeader.parse(firstSliver);\n\n\t\tlet offset = QUILT_PATCH_BLOB_HEADER_SIZE;\n\t\tlet blobSize = blobHeader.length;\n\t\tconst identifierLength = new DataView(firstSliver.buffer, offset, 2).getUint16(0, true);\n\t\tblobSize -= 2 + identifierLength;\n\t\toffset += 2;\n\n\t\tconst identifier = bcs.string().parse(firstSliver.subarray(offset, offset + identifierLength));\n\n\t\toffset += identifierLength;\n\n\t\tlet tags: Map<string, string> | null = null;\n\t\tif (blobHeader.mask & HAS_TAGS_FLAG) {\n\t\t\tconst tagsSize = new DataView(firstSliver.buffer, offset, 2).getUint16(0, true);\n\t\t\toffset += 2;\n\n\t\t\ttags = QuiltPatchTags.parse(firstSliver.subarray(offset, offset + tagsSize));\n\n\t\t\tblobSize -= tagsSize + 2;\n\t\t\toffset += tagsSize;\n\t\t}\n\n\t\tconst blobContents = await this.#readBytes(\n\t\t\tsliverIndexes[0],\n\t\t\tblobSize,\n\t\t\toffset,\n\t\t\tfirstSliver.length,\n\t\t);\n\n\t\treturn {\n\t\t\tidentifier,\n\t\t\ttags,\n\t\t\tblobContents,\n\t\t};\n\t}\n\n\tasync readByPatchId(id: string) {\n\t\tconst { quiltId, patchId } = parseQuiltPatchId(id);\n\n\t\tif (quiltId !== this.blobId) {\n\t\t\tthrow new Error(`The requested patch ${patchId} is not part of the quilt ${this.blobId}`);\n\t\t}\n\n\t\tconst sliverIndexes = [];\n\n\t\tfor (let i = patchId.startIndex; i < patchId.endIndex; i++) {\n\t\t\tsliverIndexes.push(i);\n\t\t}\n\n\t\tif (sliverIndexes.length === 0) {\n\t\t\tthrow new Error(`The requested patch ${patchId} is invalid`);\n\t\t}\n\n\t\treturn this.#readBlob(sliverIndexes);\n\t}\n\n\tasync #getColumnSize() {\n\t\tif (this.#columnSize) {\n\t\t\treturn await this.#columnSize;\n\t\t}\n\n\t\tthis.#columnSize = new Promise<number>((resolve, reject) => {\n\t\t\tif (this.#blobBytes) {\n\t\t\t\tPromise.resolve(this.#blobBytes)\n\t\t\t\t\t.then((bytes) => {\n\t\t\t\t\t\tconst { rowSize, symbolSize } = this.#getSizes(bytes.length);\n\n\t\t\t\t\t\treturn (bytes.length / rowSize) * symbolSize;\n\t\t\t\t\t})\n\t\t\t\t\t.then(resolve)\n\t\t\t\t\t.catch(reject);\n\t\t\t}\n\n\t\t\treturn this.#getSecondarySliver({ sliverIndex: 0 })\n\t\t\t\t.then((sliver) => resolve(sliver.length))\n\t\t\t\t.catch(reject);\n\t\t}).catch((error) => {\n\t\t\tthis.#columnSize = null;\n\t\t\tthrow error;\n\t\t});\n\n\t\treturn this.#columnSize;\n\t}\n\n\t#getSizes(encodedBlobSize: number) {\n\t\tconst { primarySymbols, secondarySymbols } = getSourceSymbols(this.#numShards);\n\t\tconst totalSymbols = primarySymbols * secondarySymbols;\n\n\t\tif (totalSymbols === 0) {\n\t\t\tthrow new Error('symbol size should not be 0');\n\t\t}\n\n\t\tif (encodedBlobSize % totalSymbols !== 0) {\n\t\t\tthrow new Error('blob length should be divisible by total symbols');\n\t\t}\n\n\t\tconst symbolSize = encodedBlobSize / totalSymbols;\n\t\tconst rowSize = symbolSize * secondarySymbols;\n\n\t\treturn {\n\t\t\tsymbolSize,\n\t\t\trowSize,\n\t\t};\n\t}\n\n\tasync readIndex() {\n\t\tconst header = new DataView((await this.#readBytes(0, 5)).buffer);\n\n\t\tconst version = header.getUint8(0);\n\n\t\tif (version !== 1) {\n\t\t\tthrow new Error(`Unsupported quilt version ${version}`);\n\t\t}\n\n\t\tconst indexSize = header.getUint32(1, true);\n\t\tconst indexBytes = await this.#readBytes(0, indexSize, 5);\n\t\tconst indexSlivers = Math.ceil(indexSize / (await this.#getColumnSize()));\n\t\tconst index = QuiltIndexV1.parse(indexBytes);\n\n\t\treturn index.patches.map((patch, i) => ({\n\t\t\tstartIndex: i === 0 ? indexSlivers : index.patches[i - 1].endIndex,\n\t\t\t...patch,\n\t\t}));\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAoB;AACpB,IAAAA,cAAmE;AACnE,oBAAgE;AAEhE,mBAAiC;AAPjC;AASA,MAAM,gBAAgB,KAAK;AAQpB,MAAM,YAAY;AAAA,EAQxB,YAAY,EAAE,QAAQ,QAAQ,UAAU,GAAuB;AARzD;AAEN;AACA,0CAAoB,oBAAI,IAA8C;AACtE;AACA,mCAAsD;AACtD,oCAA+C;AAG9C,uBAAK,SAAU;AACf,SAAK,SAAS;AACd,uBAAK,YAAa;AAAA,EACnB;AAAA,EAkIA,MAAM,cAAc;AACnB,QAAI,CAAC,mBAAK,aAAY;AACrB,yBAAK,YAAa,mBAAK,SAAQ,SAAS,EAAE,QAAQ,KAAK,OAAO,CAAC;AAAA,IAChE;AAEA,WAAO,mBAAK;AAAA,EACb;AAAA,EAkDA,MAAM,cAAc,IAAY;AAC/B,UAAM,EAAE,SAAS,QAAQ,QAAI,iCAAkB,EAAE;AAEjD,QAAI,YAAY,KAAK,QAAQ;AAC5B,YAAM,IAAI,MAAM,uBAAuB,OAAO,6BAA6B,KAAK,MAAM,EAAE;AAAA,IACzF;AAEA,UAAM,gBAAgB,CAAC;AAEvB,aAAS,IAAI,QAAQ,YAAY,IAAI,QAAQ,UAAU,KAAK;AAC3D,oBAAc,KAAK,CAAC;AAAA,IACrB;AAEA,QAAI,cAAc,WAAW,GAAG;AAC/B,YAAM,IAAI,MAAM,uBAAuB,OAAO,aAAa;AAAA,IAC5D;AAEA,WAAO,sBAAK,qCAAL,WAAe;AAAA,EACvB;AAAA,EAmDA,MAAM,YAAY;AACjB,UAAM,SAAS,IAAI,UAA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AAM,IAAI,MAAM,6BAA6B;AAAA,EAC9C;AAEA,MAAI,kBAAkB,iBAAiB,GAAG;AACzC,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACnE;AAEA,QAAM,aAAa,kBAAkB;AACrC,QAAM,UAAU,aAAa;AAE7B,SAAO;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;",
6
+ "names": ["import_bcs", "sliver"]
7
+ }
@@ -41,7 +41,7 @@ export type TipStrategy = {
41
41
  } | {
42
42
  linear: {
43
43
  base: number | bigint;
44
- multiplier: number | bigint;
44
+ perEncodedKb: number | bigint;
45
45
  };
46
46
  };
47
47
  export type FanOutTipConfig = {
@@ -131,6 +131,10 @@ export type ReadBlobOptions = {
131
131
  export type GetCertificationEpochOptions = ReadBlobOptions;
132
132
  export type GetBlobMetadataOptions = ReadBlobOptions;
133
133
  export type GetSliversOptions = ReadBlobOptions;
134
+ export interface GetSecondarySliverOptions extends WalrusClientRequestOptions {
135
+ blobId: string;
136
+ index: number;
137
+ }
134
138
  export type GetVerifiedBlobStatusOptions = ReadBlobOptions;
135
139
  export type ComputeBlobMetadataOptions = {
136
140
  bytes: Uint8Array;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/types.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiClient } from '@mysten/sui/client';\nimport type { Signer } from '@mysten/sui/cryptography';\nimport type { ClientWithExtensions } from '@mysten/sui/experimental';\nimport type { TransactionObjectArgument } from '@mysten/sui/transactions';\n\nimport type { StorageNodeInfo } from './contracts/walrus/storage_node.js';\nimport type { RequestOptions, StorageNodeClientOptions } from './storage-node/client.js';\nimport type {\n\tStorageConfirmation,\n\tStoreBlobMetadataRequestInput,\n\tStoreSliverRequestInput,\n\tUploadable,\n} from './storage-node/types.js';\nimport type { BlobMetadata, EncodingType } from './utils/bcs.js';\nimport type { FanOutProxyClientOptions } from './fan-out-proxy/client.js';\n\n/**\n * Configuration for the Walrus package on sui\n *\n * This is used to configure the Walrus package to use a specific package ID, system object ID, staking pool ID, and WAL package ID.\n */\nexport interface WalrusPackageConfig {\n\t/** The system object ID of the Walrus package */\n\tsystemObjectId: string;\n\t/** The staking pool ID of the Walrus package */\n\tstakingPoolId: string;\n\tsubsidiesObjectId?: string;\n\texchangeIds?: string[];\n}\n\ntype SuiClientOrRpcUrl =\n\t| {\n\t\t\tsuiClient: ClientWithExtensions<{\n\t\t\t\tjsonRpc: SuiClient;\n\t\t\t}>;\n\t\t\tsuiRpcUrl?: never;\n\t }\n\t| {\n\t\t\tsuiRpcUrl: string;\n\t\t\tsuiClient?: never;\n\t };\n\ntype WalrusNetworkOrPackageConfig =\n\t| {\n\t\t\tnetwork: 'mainnet' | 'testnet';\n\t\t\tpackageConfig?: WalrusPackageConfig;\n\t }\n\t| {\n\t\t\tnetwork?: never;\n\t\t\tpackageConfig: WalrusPackageConfig;\n\t };\n\nexport type TipStrategy =\n\t| {\n\t\t\tconst: number | bigint;\n\t }\n\t| {\n\t\t\tlinear: {\n\t\t\t\tbase: number | bigint;\n\t\t\t\tmultiplier: number | bigint;\n\t\t\t};\n\t };\n\nexport type FanOutTipConfig = {\n\taddress: string;\n\tmax?: number;\n\tkind: TipStrategy;\n};\n\nexport interface FanOutConfig extends FanOutProxyClientOptions {\n\tsendTip?:\n\t\t| null\n\t\t| FanOutTipConfig\n\t\t| {\n\t\t\t\tmax: number;\n\t\t };\n}\n\ninterface BaseWalrusClientConfig {\n\tstorageNodeClientOptions?: StorageNodeClientOptions;\n\twasmUrl?: string;\n\tfanOut?: FanOutConfig;\n}\n\n/**\n * Configuration for the Walrus client.\n *\n * This is used to configure the Walrus client to use a specific storage node client options, network, and Sui client or RPC URL.\n */\nexport type WalrusClientConfig = BaseWalrusClientConfig &\n\tWalrusNetworkOrPackageConfig &\n\tSuiClientOrRpcUrl;\n\nexport type WalrusClientExtensionOptions = BaseWalrusClientConfig & {\n\tpackageConfig?: WalrusPackageConfig;\n\tnetwork?: 'mainnet' | 'testnet';\n};\n\nexport type WalrusClientRequestOptions = Pick<RequestOptions, 'signal'>;\n\nexport interface StorageNode {\n\tnetworkUrl: string;\n\tinfo: ReturnType<typeof StorageNodeInfo>['$inferType'];\n\tshardIndices: number[];\n\tnodeIndex: number;\n\tid: string;\n}\n\nexport interface CommitteeInfo {\n\tbyShardIndex: Map<number, StorageNode>;\n\tnodes: StorageNode[];\n}\n\nexport interface StorageWithSizeOptions {\n\t/** The encoded size of the blob. */\n\tsize: number;\n\t/** The number of epoch the storage will be reserved for. */\n\tepochs: number;\n\t/** Owner of the storage object. */\n\towner: string;\n\t/** optionally specify a WAL coin pay for the registration. This will consume WAL from the signer by default. */\n\twalCoin?: TransactionObjectArgument;\n}\n\nexport interface RegisterBlobOptions extends StorageWithSizeOptions {\n\tblobId: string;\n\trootHash: Uint8Array;\n\tdeletable: boolean;\n\t/** optionally specify a WAL coin pay for the registration. This will consume WAL from the signer by default. */\n\twalCoin?: TransactionObjectArgument;\n\t/** The attributes to write for the blob. */\n\tattributes?: Record<string, string | null>;\n}\n\nexport type CertifyBlobOptions = {\n\tblobId: string;\n\tblobObjectId: string;\n\tdeletable: boolean;\n} & (\n\t| {\n\t\t\t/** An array of confirmations.\n\t\t\t * These confirmations must be provided in the same order as the nodes in the committee.\n\t\t\t * For nodes that have not provided a confirmation you can pass `null` */\n\t\t\tconfirmations: (StorageConfirmation | null)[];\n\t\t\tcertificate?: never;\n\t }\n\t| {\n\t\t\tcertificate: ProtocolMessageCertificate;\n\t\t\tconfirmations?: never;\n\t }\n);\n\nexport type DeletableConfirmationOptions =\n\t| { deletable: false; objectId?: string }\n\t| { deletable: true; objectId: string };\n\nexport type GetStorageConfirmationOptions = {\n\tblobId: string;\n\tnodeIndex: number;\n} & DeletableConfirmationOptions &\n\tWalrusClientRequestOptions;\n\nexport type ReadBlobOptions = {\n\tblobId: string;\n} & WalrusClientRequestOptions;\n\nexport type GetCertificationEpochOptions = ReadBlobOptions;\n\nexport type GetBlobMetadataOptions = ReadBlobOptions;\n\nexport type GetSliversOptions = ReadBlobOptions;\n\nexport type GetVerifiedBlobStatusOptions = ReadBlobOptions;\n\nexport type ComputeBlobMetadataOptions = {\n\tbytes: Uint8Array;\n\tnumShards?: number;\n};\n\nexport interface SliversForNode {\n\tprimary: {\n\t\tsliverIndex: number;\n\t\tsliverPairIndex: number;\n\t\tshardIndex: number;\n\t\tsliver: Uint8Array;\n\t}[];\n\tsecondary: {\n\t\tsliverIndex: number;\n\t\tsliverPairIndex: number;\n\t\tshardIndex: number;\n\t\tsliver: Uint8Array;\n\t}[];\n}\n\nexport type WriteSliversToNodeOptions = {\n\tblobId: string;\n\tnodeIndex: number;\n\tslivers: SliversForNode;\n} & WalrusClientRequestOptions;\n\nexport type WriteSliverOptions = StoreSliverRequestInput & WalrusClientRequestOptions;\n\nexport type WriteMetadataOptions = {\n\tnodeIndex: number;\n\tmetadata: Uploadable | typeof BlobMetadata.$inferInput;\n} & StoreBlobMetadataRequestInput &\n\tWalrusClientRequestOptions;\n\nexport type WriteEncodedBlobOptions = {\n\tblobId: string;\n\tnodeIndex: number;\n\tmetadata: Uploadable | typeof BlobMetadata.$inferInput;\n\tslivers: SliversForNode;\n} & DeletableConfirmationOptions &\n\tWalrusClientRequestOptions;\n\nexport type WriteEncodedBlobToNodesOptions = {\n\tblobId: string;\n\tmetadata: Uploadable | typeof BlobMetadata.$inferInput;\n\tsliversByNode: SliversForNode[];\n} & DeletableConfirmationOptions &\n\tWalrusClientRequestOptions;\n\nexport type WriteBlobToFanOutProxyOptions = {\n\tblobId: string;\n\tblob: Uint8Array;\n\tnonce: Uint8Array;\n\ttxDigest: string;\n\tblobObjectId: string;\n\tdeletable: boolean;\n\tencodingType?: EncodingType;\n} & WalrusClientRequestOptions;\n\nexport type WriteBlobOptions = {\n\tblob: Uint8Array;\n\tdeletable: boolean;\n\t/** The number of epochs the blob should be stored for. */\n\tepochs: number;\n\tsigner: Signer;\n\t/** Where the blob should be transferred to after it is registered. Defaults to the signer address. */\n\towner?: string;\n\t/** The attributes to write for the blob. */\n\tattributes?: Record<string, string | null>;\n} & WalrusClientRequestOptions;\n\nexport interface DeleteBlobOptions {\n\tblobObjectId: string;\n}\n\nexport type ExtendBlobOptions = {\n\tblobObjectId: string;\n\towner: string;\n\t/** optionally specify a WAL coin pay for the registration. This will consume WAL from the signer by default. */\n\twalCoin?: TransactionObjectArgument;\n} & (\n\t| {\n\t\t\t/** The number of epochs the blob should be stored for. */\n\t\t\tepochs: number;\n\t\t\tendEpoch?: never;\n\t }\n\t| {\n\t\t\t/** The new end epoch for the storage period of the blob. */\n\t\t\tendEpoch: number;\n\t\t\tepochs?: never;\n\t }\n);\n\nexport type WriteBlobAttributesOptions = {\n\tattributes: Record<string, string | null>;\n} & (\n\t| {\n\t\t\tblobObject: TransactionObjectArgument;\n\t\t\tblobObjectId?: never;\n\t }\n\t| {\n\t\t\tblobObjectId: string;\n\t\t\tblobObject?: never;\n\t }\n);\n\nexport type EncodingType = Extract<typeof EncodingType.$inferInput, string>;\n\nexport interface ProtocolMessageCertificate {\n\tsigners: number[];\n\tserializedMessage: Uint8Array;\n\tsignature: Uint8Array;\n}\n"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiClient } from '@mysten/sui/client';\nimport type { Signer } from '@mysten/sui/cryptography';\nimport type { ClientWithExtensions } from '@mysten/sui/experimental';\nimport type { TransactionObjectArgument } from '@mysten/sui/transactions';\n\nimport type { StorageNodeInfo } from './contracts/walrus/storage_node.js';\nimport type { RequestOptions, StorageNodeClientOptions } from './storage-node/client.js';\nimport type {\n\tStorageConfirmation,\n\tStoreBlobMetadataRequestInput,\n\tStoreSliverRequestInput,\n\tUploadable,\n} from './storage-node/types.js';\nimport type { BlobMetadata, EncodingType } from './utils/bcs.js';\nimport type { FanOutProxyClientOptions } from './fan-out-proxy/client.js';\n\n/**\n * Configuration for the Walrus package on sui\n *\n * This is used to configure the Walrus package to use a specific package ID, system object ID, staking pool ID, and WAL package ID.\n */\nexport interface WalrusPackageConfig {\n\t/** The system object ID of the Walrus package */\n\tsystemObjectId: string;\n\t/** The staking pool ID of the Walrus package */\n\tstakingPoolId: string;\n\tsubsidiesObjectId?: string;\n\texchangeIds?: string[];\n}\n\ntype SuiClientOrRpcUrl =\n\t| {\n\t\t\tsuiClient: ClientWithExtensions<{\n\t\t\t\tjsonRpc: SuiClient;\n\t\t\t}>;\n\t\t\tsuiRpcUrl?: never;\n\t }\n\t| {\n\t\t\tsuiRpcUrl: string;\n\t\t\tsuiClient?: never;\n\t };\n\ntype WalrusNetworkOrPackageConfig =\n\t| {\n\t\t\tnetwork: 'mainnet' | 'testnet';\n\t\t\tpackageConfig?: WalrusPackageConfig;\n\t }\n\t| {\n\t\t\tnetwork?: never;\n\t\t\tpackageConfig: WalrusPackageConfig;\n\t };\n\nexport type TipStrategy =\n\t| {\n\t\t\tconst: number | bigint;\n\t }\n\t| {\n\t\t\tlinear: {\n\t\t\t\tbase: number | bigint;\n\t\t\t\tperEncodedKb: number | bigint;\n\t\t\t};\n\t };\n\nexport type FanOutTipConfig = {\n\taddress: string;\n\tmax?: number;\n\tkind: TipStrategy;\n};\n\nexport interface FanOutConfig extends FanOutProxyClientOptions {\n\tsendTip?:\n\t\t| null\n\t\t| FanOutTipConfig\n\t\t| {\n\t\t\t\tmax: number;\n\t\t };\n}\n\ninterface BaseWalrusClientConfig {\n\tstorageNodeClientOptions?: StorageNodeClientOptions;\n\twasmUrl?: string;\n\tfanOut?: FanOutConfig;\n}\n\n/**\n * Configuration for the Walrus client.\n *\n * This is used to configure the Walrus client to use a specific storage node client options, network, and Sui client or RPC URL.\n */\nexport type WalrusClientConfig = BaseWalrusClientConfig &\n\tWalrusNetworkOrPackageConfig &\n\tSuiClientOrRpcUrl;\n\nexport type WalrusClientExtensionOptions = BaseWalrusClientConfig & {\n\tpackageConfig?: WalrusPackageConfig;\n\tnetwork?: 'mainnet' | 'testnet';\n};\n\nexport type WalrusClientRequestOptions = Pick<RequestOptions, 'signal'>;\n\nexport interface StorageNode {\n\tnetworkUrl: string;\n\tinfo: ReturnType<typeof StorageNodeInfo>['$inferType'];\n\tshardIndices: number[];\n\tnodeIndex: number;\n\tid: string;\n}\n\nexport interface CommitteeInfo {\n\tbyShardIndex: Map<number, StorageNode>;\n\tnodes: StorageNode[];\n}\n\nexport interface StorageWithSizeOptions {\n\t/** The encoded size of the blob. */\n\tsize: number;\n\t/** The number of epoch the storage will be reserved for. */\n\tepochs: number;\n\t/** Owner of the storage object. */\n\towner: string;\n\t/** optionally specify a WAL coin pay for the registration. This will consume WAL from the signer by default. */\n\twalCoin?: TransactionObjectArgument;\n}\n\nexport interface RegisterBlobOptions extends StorageWithSizeOptions {\n\tblobId: string;\n\trootHash: Uint8Array;\n\tdeletable: boolean;\n\t/** optionally specify a WAL coin pay for the registration. This will consume WAL from the signer by default. */\n\twalCoin?: TransactionObjectArgument;\n\t/** The attributes to write for the blob. */\n\tattributes?: Record<string, string | null>;\n}\n\nexport type CertifyBlobOptions = {\n\tblobId: string;\n\tblobObjectId: string;\n\tdeletable: boolean;\n} & (\n\t| {\n\t\t\t/** An array of confirmations.\n\t\t\t * These confirmations must be provided in the same order as the nodes in the committee.\n\t\t\t * For nodes that have not provided a confirmation you can pass `null` */\n\t\t\tconfirmations: (StorageConfirmation | null)[];\n\t\t\tcertificate?: never;\n\t }\n\t| {\n\t\t\tcertificate: ProtocolMessageCertificate;\n\t\t\tconfirmations?: never;\n\t }\n);\n\nexport type DeletableConfirmationOptions =\n\t| { deletable: false; objectId?: string }\n\t| { deletable: true; objectId: string };\n\nexport type GetStorageConfirmationOptions = {\n\tblobId: string;\n\tnodeIndex: number;\n} & DeletableConfirmationOptions &\n\tWalrusClientRequestOptions;\n\nexport type ReadBlobOptions = {\n\tblobId: string;\n} & WalrusClientRequestOptions;\n\nexport type GetCertificationEpochOptions = ReadBlobOptions;\n\nexport type GetBlobMetadataOptions = ReadBlobOptions;\n\nexport type GetSliversOptions = ReadBlobOptions;\n\nexport interface GetSecondarySliverOptions extends WalrusClientRequestOptions {\n\tblobId: string;\n\tindex: number;\n}\n\nexport type GetVerifiedBlobStatusOptions = ReadBlobOptions;\n\nexport type ComputeBlobMetadataOptions = {\n\tbytes: Uint8Array;\n\tnumShards?: number;\n};\n\nexport interface SliversForNode {\n\tprimary: {\n\t\tsliverIndex: number;\n\t\tsliverPairIndex: number;\n\t\tshardIndex: number;\n\t\tsliver: Uint8Array;\n\t}[];\n\tsecondary: {\n\t\tsliverIndex: number;\n\t\tsliverPairIndex: number;\n\t\tshardIndex: number;\n\t\tsliver: Uint8Array;\n\t}[];\n}\n\nexport type WriteSliversToNodeOptions = {\n\tblobId: string;\n\tnodeIndex: number;\n\tslivers: SliversForNode;\n} & WalrusClientRequestOptions;\n\nexport type WriteSliverOptions = StoreSliverRequestInput & WalrusClientRequestOptions;\n\nexport type WriteMetadataOptions = {\n\tnodeIndex: number;\n\tmetadata: Uploadable | typeof BlobMetadata.$inferInput;\n} & StoreBlobMetadataRequestInput &\n\tWalrusClientRequestOptions;\n\nexport type WriteEncodedBlobOptions = {\n\tblobId: string;\n\tnodeIndex: number;\n\tmetadata: Uploadable | typeof BlobMetadata.$inferInput;\n\tslivers: SliversForNode;\n} & DeletableConfirmationOptions &\n\tWalrusClientRequestOptions;\n\nexport type WriteEncodedBlobToNodesOptions = {\n\tblobId: string;\n\tmetadata: Uploadable | typeof BlobMetadata.$inferInput;\n\tsliversByNode: SliversForNode[];\n} & DeletableConfirmationOptions &\n\tWalrusClientRequestOptions;\n\nexport type WriteBlobToFanOutProxyOptions = {\n\tblobId: string;\n\tblob: Uint8Array;\n\tnonce: Uint8Array;\n\ttxDigest: string;\n\tblobObjectId: string;\n\tdeletable: boolean;\n\tencodingType?: EncodingType;\n} & WalrusClientRequestOptions;\n\nexport type WriteBlobOptions = {\n\tblob: Uint8Array;\n\tdeletable: boolean;\n\t/** The number of epochs the blob should be stored for. */\n\tepochs: number;\n\tsigner: Signer;\n\t/** Where the blob should be transferred to after it is registered. Defaults to the signer address. */\n\towner?: string;\n\t/** The attributes to write for the blob. */\n\tattributes?: Record<string, string | null>;\n} & WalrusClientRequestOptions;\n\nexport interface DeleteBlobOptions {\n\tblobObjectId: string;\n}\n\nexport type ExtendBlobOptions = {\n\tblobObjectId: string;\n\towner: string;\n\t/** optionally specify a WAL coin pay for the registration. This will consume WAL from the signer by default. */\n\twalCoin?: TransactionObjectArgument;\n} & (\n\t| {\n\t\t\t/** The number of epochs the blob should be stored for. */\n\t\t\tepochs: number;\n\t\t\tendEpoch?: never;\n\t }\n\t| {\n\t\t\t/** The new end epoch for the storage period of the blob. */\n\t\t\tendEpoch: number;\n\t\t\tepochs?: never;\n\t }\n);\n\nexport type WriteBlobAttributesOptions = {\n\tattributes: Record<string, string | null>;\n} & (\n\t| {\n\t\t\tblobObject: TransactionObjectArgument;\n\t\t\tblobObjectId?: never;\n\t }\n\t| {\n\t\t\tblobObjectId: string;\n\t\t\tblobObject?: never;\n\t }\n);\n\nexport type EncodingType = Extract<typeof EncodingType.$inferInput, string>;\n\nexport interface ProtocolMessageCertificate {\n\tsigners: number[];\n\tserializedMessage: Uint8Array;\n\tsignature: Uint8Array;\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -298,3 +298,52 @@ export declare function Field<T0 extends BcsType<any>, T1 extends BcsType<any>>(
298
298
  name: T0 extends BcsType<any, infer U_1> ? U_1 : never;
299
299
  value: T1 extends BcsType<any, infer U_1> ? U_1 : never;
300
300
  }>;
301
+ export declare const QuiltPatchTags: BcsType<Map<string, string>, Map<string, string>>;
302
+ export declare const QuiltPatchV1: BcsType<{
303
+ endIndex: number;
304
+ identifier: string;
305
+ tags: Map<string, string>;
306
+ }, {
307
+ endIndex: number;
308
+ identifier: string;
309
+ tags: Map<string, string>;
310
+ }>;
311
+ export declare const QuiltIndexV1: BcsType<{
312
+ patches: {
313
+ endIndex: number;
314
+ identifier: string;
315
+ tags: Map<string, string>;
316
+ }[];
317
+ }, {
318
+ patches: Iterable<{
319
+ endIndex: number;
320
+ identifier: string;
321
+ tags: Map<string, string>;
322
+ }> & {
323
+ length: number;
324
+ };
325
+ }>;
326
+ export declare const QuiltPatchId: BcsType<{
327
+ quiltId: string;
328
+ patchId: {
329
+ version: number;
330
+ startIndex: number;
331
+ endIndex: number;
332
+ };
333
+ }, {
334
+ quiltId: string | bigint;
335
+ patchId: {
336
+ version: number;
337
+ startIndex: number;
338
+ endIndex: number;
339
+ };
340
+ }>;
341
+ export declare const QuiltPatchBlobHeader: BcsType<{
342
+ version: number;
343
+ length: number;
344
+ mask: number;
345
+ }, {
346
+ version: number;
347
+ length: number;
348
+ mask: number;
349
+ }>;
@@ -28,6 +28,11 @@ __export(bcs_exports, {
28
28
  Intent: () => Intent,
29
29
  IntentType: () => IntentType,
30
30
  ProtocolMessage: () => ProtocolMessage,
31
+ QuiltIndexV1: () => QuiltIndexV1,
32
+ QuiltPatchBlobHeader: () => QuiltPatchBlobHeader,
33
+ QuiltPatchId: () => QuiltPatchId,
34
+ QuiltPatchTags: () => QuiltPatchTags,
35
+ QuiltPatchV1: () => QuiltPatchV1,
31
36
  Sliver: () => Sliver,
32
37
  SliverData: () => SliverData,
33
38
  SliverPair: () => SliverPair,
@@ -142,4 +147,44 @@ function Field(...typeParameters) {
142
147
  value: typeParameters[1]
143
148
  });
144
149
  }
150
+ const QuiltPatchTags = import_bcs.bcs.map(import_bcs.bcs.string(), import_bcs.bcs.string()).transform({
151
+ // tags is a BTreeMap, so we need to sort entries before serializing
152
+ input: (tags) => new Map(
153
+ [...tags.entries()].sort(
154
+ ([a], [b]) => compareBcsBytes(import_bcs.bcs.string().serialize(a).toBytes(), import_bcs.bcs.string().serialize(b).toBytes())
155
+ )
156
+ )
157
+ });
158
+ const QuiltPatchV1 = import_bcs.bcs.struct("QuiltPatchV1", {
159
+ endIndex: import_bcs.bcs.u16(),
160
+ identifier: import_bcs.bcs.string(),
161
+ tags: QuiltPatchTags
162
+ });
163
+ function compareBcsBytes(a, b) {
164
+ for (let i = 0; i < a.length; i++) {
165
+ if (i >= b.length) {
166
+ return 1;
167
+ }
168
+ if (a[i] !== b[i]) {
169
+ return a[i] - b[i];
170
+ }
171
+ }
172
+ return 0;
173
+ }
174
+ const QuiltIndexV1 = import_bcs.bcs.struct("QuiltIndexV1", {
175
+ patches: import_bcs.bcs.vector(QuiltPatchV1)
176
+ });
177
+ const QuiltPatchId = import_bcs.bcs.struct("QuiltPatchId", {
178
+ quiltId: BlobId,
179
+ patchId: import_bcs.bcs.struct("InternalQuiltPatchId", {
180
+ version: import_bcs.bcs.u8(),
181
+ startIndex: import_bcs.bcs.u16(),
182
+ endIndex: import_bcs.bcs.u16()
183
+ })
184
+ });
185
+ const QuiltPatchBlobHeader = import_bcs.bcs.struct("QuiltPatchBlobHeader", {
186
+ version: import_bcs.bcs.u8(),
187
+ length: import_bcs.bcs.u32(),
188
+ mask: import_bcs.bcs.u8()
189
+ });
145
190
  //# sourceMappingURL=bcs.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/utils/bcs.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { BcsType } from '@mysten/sui/bcs';\nimport { bcs } from '@mysten/sui/bcs';\n\nconst MerkleNode = bcs.enum('MerkleNode', {\n\tEmpty: null,\n\tDigest: bcs.bytes(32),\n});\n\nconst SliverPairMetadata = bcs.struct('SliverPairMetadata', {\n\tprimary_hash: MerkleNode,\n\tsecondary_hash: MerkleNode,\n});\n\nexport const EncodingType = bcs\n\t.enum('EncodingType', {\n\t\tRedStuff: null,\n\t\tRS2: null,\n\t})\n\t.transform({\n\t\tinput: (\n\t\t\tencodingType:\n\t\t\t\t| { RedStuff: boolean | object | null }\n\t\t\t\t| { RS2: boolean | object | null }\n\t\t\t\t| 'RedStuff'\n\t\t\t\t| 'RS2',\n\t\t) =>\n\t\t\ttypeof encodingType === 'string'\n\t\t\t\t? ({ [encodingType]: null } as Exclude<typeof encodingType, string>)\n\t\t\t\t: encodingType,\n\t\toutput: (encodingType) => encodingType,\n\t});\n\nexport const BlobMetadataV1 = bcs.struct('BlobMetadataV1', {\n\tencoding_type: EncodingType,\n\tunencoded_length: bcs.u64(),\n\thashes: bcs.vector(SliverPairMetadata),\n});\n\nexport const BlobMetadata = bcs.enum('BlobMetadata', {\n\tV1: BlobMetadataV1,\n});\n\nexport const BlobId = bcs.u256().transform({\n\tinput: (blobId: string | bigint) => (typeof blobId === 'string' ? blobIdToInt(blobId) : blobId),\n\toutput: (id: string) => blobIdFromInt(id),\n});\n\nexport function blobIdFromInt(blobId: bigint | string): string {\n\treturn bcs\n\t\t.u256()\n\t\t.serialize(blobId)\n\t\t.toBase64()\n\t\t.replace(/=*$/, '')\n\t\t.replaceAll('+', '-')\n\t\t.replaceAll('/', '_');\n}\n\nexport function blobIdFromBytes(blobId: Uint8Array): string {\n\treturn blobIdFromInt(bcs.u256().parse(blobId));\n}\n\nexport function blobIdToInt(blobId: string): bigint {\n\treturn BigInt(bcs.u256().fromBase64(blobId.replaceAll('-', '+').replaceAll('_', '/')));\n}\n\nexport const BlobMetadataWithId = bcs.struct('BlobMetadataWithId', {\n\tblobId: BlobId,\n\tmetadata: BlobMetadata,\n});\n\nconst Symbols = bcs.struct('Symbols', {\n\tdata: bcs.vector(bcs.u8()),\n\tsymbol_size: bcs.u16(),\n});\n\nexport const SliverData = bcs.struct('SliverData', {\n\tsymbols: Symbols,\n\tindex: bcs.u16(),\n});\n\nexport const Sliver = bcs.enum('Sliver', {\n\tPrimary: SliverData,\n\tSecondary: SliverData,\n});\n\nexport const SliverPair = bcs.struct('SliverPair', {\n\tprimary: SliverData,\n\tsecondary: SliverData,\n});\n\nexport enum IntentType {\n\tPROOF_OF_POSSESSION_MSG = 0,\n\tBLOB_CERT_MSG = 1,\n\tINVALID_BLOB_ID_MSG = 2,\n\tSYNC_SHARD_MSG = 3,\n}\n\nexport const Intent = bcs\n\t.struct('Intent', {\n\t\ttype: bcs.u8().transform({\n\t\t\tinput: (type: IntentType) => type,\n\t\t\toutput: (type: number) => type as IntentType,\n\t\t}),\n\t\tversion: bcs.u8(),\n\t\tappId: bcs.u8(),\n\t})\n\t.transform({\n\t\tinput: (intent: IntentType) => ({\n\t\t\ttype: intent,\n\t\t\tversion: 0,\n\t\t\tappId: 3,\n\t\t}),\n\t\toutput: (intent) => intent.type,\n\t});\n\nexport function ProtocolMessage<T extends BcsType<any>>(messageContents: T) {\n\treturn bcs.struct(`ProtocolMessage<${messageContents.name}>`, {\n\t\tintent: Intent,\n\t\tepoch: bcs.u32(),\n\t\tmessageContents,\n\t});\n}\n\nexport const BlobPersistenceType = bcs.enum('BlobPersistenceType', {\n\tPermanent: null,\n\tDeletable: bcs.struct('Deletable', {\n\t\tobjectId: bcs.Address,\n\t}),\n});\nexport const StorageConfirmationBody = bcs.struct('StorageConfirmationBody', {\n\tblobId: BlobId,\n\tblobType: BlobPersistenceType,\n});\n\nexport const StorageConfirmation = ProtocolMessage(StorageConfirmationBody);\n\nexport function Field<T0 extends BcsType<any>, T1 extends BcsType<any>>(\n\t...typeParameters: [T0, T1]\n) {\n\treturn bcs.struct('Field', {\n\t\tid: bcs.Address,\n\t\tname: typeParameters[0],\n\t\tvalue: typeParameters[1],\n\t});\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,iBAAoB;AAEpB,MAAM,aAAa,eAAI,KAAK,cAAc;AAAA,EACzC,OAAO;AAAA,EACP,QAAQ,eAAI,MAAM,EAAE;AACrB,CAAC;AAED,MA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OAAO,2BAA2B;AAAA,EAC5E,QAAQ;AAAA,EACR,UAAU;AACX,CAAC;AAEM,MAAM,sBAAsB,gBAAgB,uBAAuB;AAEnE,SAAS,SACZ,gBACF;AACD,SAAO,eAAI,OAAO,SAAS;AAAA,IAC1B,IAAI,eAAI;AAAA,IACR,MAAM,eAAe,CAAC;AAAA,IACtB,OAAO,eAAe,CAAC;AAAA,EACxB,CAAC;AACF;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { BcsType } from '@mysten/sui/bcs';\nimport { bcs } from '@mysten/sui/bcs';\n\nconst MerkleNode = bcs.enum('MerkleNode', {\n\tEmpty: null,\n\tDigest: bcs.bytes(32),\n});\n\nconst SliverPairMetadata = bcs.struct('SliverPairMetadata', {\n\tprimary_hash: MerkleNode,\n\tsecondary_hash: MerkleNode,\n});\n\nexport const EncodingType = bcs\n\t.enum('EncodingType', {\n\t\tRedStuff: null,\n\t\tRS2: null,\n\t})\n\t.transform({\n\t\tinput: (\n\t\t\tencodingType:\n\t\t\t\t| { RedStuff: boolean | object | null }\n\t\t\t\t| { RS2: boolean | object | null }\n\t\t\t\t| 'RedStuff'\n\t\t\t\t| 'RS2',\n\t\t) =>\n\t\t\ttypeof encodingType === 'string'\n\t\t\t\t? ({ [encodingType]: null } as Exclude<typeof encodingType, string>)\n\t\t\t\t: encodingType,\n\t\toutput: (encodingType) => encodingType,\n\t});\n\nexport const BlobMetadataV1 = bcs.struct('BlobMetadataV1', {\n\tencoding_type: EncodingType,\n\tunencoded_length: bcs.u64(),\n\thashes: bcs.vector(SliverPairMetadata),\n});\n\nexport const BlobMetadata = bcs.enum('BlobMetadata', {\n\tV1: BlobMetadataV1,\n});\n\nexport const BlobId = bcs.u256().transform({\n\tinput: (blobId: string | bigint) => (typeof blobId === 'string' ? blobIdToInt(blobId) : blobId),\n\toutput: (id: string) => blobIdFromInt(id),\n});\n\nexport function blobIdFromInt(blobId: bigint | string): string {\n\treturn bcs\n\t\t.u256()\n\t\t.serialize(blobId)\n\t\t.toBase64()\n\t\t.replace(/=*$/, '')\n\t\t.replaceAll('+', '-')\n\t\t.replaceAll('/', '_');\n}\n\nexport function blobIdFromBytes(blobId: Uint8Array): string {\n\treturn blobIdFromInt(bcs.u256().parse(blobId));\n}\n\nexport function blobIdToInt(blobId: string): bigint {\n\treturn BigInt(bcs.u256().fromBase64(blobId.replaceAll('-', '+').replaceAll('_', '/')));\n}\n\nexport const BlobMetadataWithId = bcs.struct('BlobMetadataWithId', {\n\tblobId: BlobId,\n\tmetadata: BlobMetadata,\n});\n\nconst Symbols = bcs.struct('Symbols', {\n\tdata: bcs.vector(bcs.u8()),\n\tsymbol_size: bcs.u16(),\n});\n\nexport const SliverData = bcs.struct('SliverData', {\n\tsymbols: Symbols,\n\tindex: bcs.u16(),\n});\n\nexport const Sliver = bcs.enum('Sliver', {\n\tPrimary: SliverData,\n\tSecondary: SliverData,\n});\n\nexport const SliverPair = bcs.struct('SliverPair', {\n\tprimary: SliverData,\n\tsecondary: SliverData,\n});\n\nexport enum IntentType {\n\tPROOF_OF_POSSESSION_MSG = 0,\n\tBLOB_CERT_MSG = 1,\n\tINVALID_BLOB_ID_MSG = 2,\n\tSYNC_SHARD_MSG = 3,\n}\n\nexport const Intent = bcs\n\t.struct('Intent', {\n\t\ttype: bcs.u8().transform({\n\t\t\tinput: (type: IntentType) => type,\n\t\t\toutput: (type: number) => type as IntentType,\n\t\t}),\n\t\tversion: bcs.u8(),\n\t\tappId: bcs.u8(),\n\t})\n\t.transform({\n\t\tinput: (intent: IntentType) => ({\n\t\t\ttype: intent,\n\t\t\tversion: 0,\n\t\t\tappId: 3,\n\t\t}),\n\t\toutput: (intent) => intent.type,\n\t});\n\nexport function ProtocolMessage<T extends BcsType<any>>(messageContents: T) {\n\treturn bcs.struct(`ProtocolMessage<${messageContents.name}>`, {\n\t\tintent: Intent,\n\t\tepoch: bcs.u32(),\n\t\tmessageContents,\n\t});\n}\n\nexport const BlobPersistenceType = bcs.enum('BlobPersistenceType', {\n\tPermanent: null,\n\tDeletable: bcs.struct('Deletable', {\n\t\tobjectId: bcs.Address,\n\t}),\n});\nexport const StorageConfirmationBody = bcs.struct('StorageConfirmationBody', {\n\tblobId: BlobId,\n\tblobType: BlobPersistenceType,\n});\n\nexport const StorageConfirmation = ProtocolMessage(StorageConfirmationBody);\n\nexport function Field<T0 extends BcsType<any>, T1 extends BcsType<any>>(\n\t...typeParameters: [T0, T1]\n) {\n\treturn bcs.struct('Field', {\n\t\tid: bcs.Address,\n\t\tname: typeParameters[0],\n\t\tvalue: typeParameters[1],\n\t});\n}\n\nexport const QuiltPatchTags = bcs.map(bcs.string(), bcs.string()).transform({\n\t// tags is a BTreeMap, so we need to sort entries before serializing\n\tinput: (tags: Map<string, string>) =>\n\t\tnew Map(\n\t\t\t[...tags.entries()].sort(([a], [b]) =>\n\t\t\t\tcompareBcsBytes(bcs.string().serialize(a).toBytes(), bcs.string().serialize(b).toBytes()),\n\t\t\t),\n\t\t),\n});\n\nexport const QuiltPatchV1 = bcs.struct('QuiltPatchV1', {\n\tendIndex: bcs.u16(),\n\tidentifier: bcs.string(),\n\ttags: QuiltPatchTags,\n});\n\nfunction compareBcsBytes(a: Uint8Array, b: Uint8Array) {\n\tfor (let i = 0; i < a.length; i++) {\n\t\tif (i >= b.length) {\n\t\t\treturn 1;\n\t\t}\n\n\t\tif (a[i] !== b[i]) {\n\t\t\treturn a[i] - b[i];\n\t\t}\n\t}\n\n\treturn 0;\n}\n\nexport const QuiltIndexV1 = bcs.struct('QuiltIndexV1', {\n\tpatches: bcs.vector(QuiltPatchV1),\n});\n\nexport const QuiltPatchId = bcs.struct('QuiltPatchId', {\n\tquiltId: BlobId,\n\tpatchId: bcs.struct('InternalQuiltPatchId', {\n\t\tversion: bcs.u8(),\n\t\tstartIndex: bcs.u16(),\n\t\tendIndex: bcs.u16(),\n\t}),\n});\n\nexport const QuiltPatchBlobHeader = bcs.struct('Qui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K;AAClC,QAAI,KAAK,EAAE,QAAQ;AAClB,aAAO;AAAA,IACR;AAEA,QAAI,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG;AAClB,aAAO,EAAE,CAAC,IAAI,EAAE,CAAC;AAAA,IAClB;AAAA,EACD;AAEA,SAAO;AACR;AAEO,MAAM,eAAe,eAAI,OAAO,gBAAgB;AAAA,EACtD,SAAS,eAAI,OAAO,YAAY;AACjC,CAAC;AAEM,MAAM,eAAe,eAAI,OAAO,gBAAgB;AAAA,EACtD,SAAS;AAAA,EACT,SAAS,eAAI,OAAO,wBAAwB;AAAA,IAC3C,SAAS,eAAI,GAAG;AAAA,IAChB,YAAY,eAAI,IAAI;AAAA,IACpB,UAAU,eAAI,IAAI;AAAA,EACnB,CAAC;AACF,CAAC;AAEM,MAAM,uBAAuB,eAAI,OAAO,wBAAwB;AAAA,EACtE,SAAS,eAAI,GAAG;AAAA,EAChB,QAAQ,eAAI,IAAI;AAAA,EAChB,MAAM,eAAI,GAAG;AACd,CAAC;",
6
6
  "names": ["IntentType"]
7
7
  }
@@ -12,6 +12,8 @@ export declare function isAboveValidity(size: number, nShards: number): boolean;
12
12
  export declare function getMaxFaultyNodes(nShards: number): number;
13
13
  export declare function storageUnitsFromSize(size: number): number;
14
14
  export declare function toShardIndex(sliverPairIndex: number, blobId: string, numShards: number): number;
15
+ export declare function sliverPairIndexFromSecondarySliverIndex(sliverIndex: number, numShards: number): number;
16
+ export declare function shardIndexFromSecondarySliverIndex(sliverIndex: number, blobId: string, numShards: number): number;
15
17
  export declare function toPairIndex(shardIndex: number, blobId: string, numShards: number): number;
16
18
  export declare function signersToBitmap(signers: number[], committeeSize: number): Uint8Array;
17
19
  export declare function getShardIndicesByNodeId(committee: InferBcsType<ReturnType<typeof Committee>>): Map<string, number[]>;
@@ -26,7 +26,9 @@ __export(utils_exports, {
26
26
  isAboveValidity: () => isAboveValidity,
27
27
  isQuorum: () => isQuorum,
28
28
  nodesByShardIndex: () => nodesByShardIndex,
29
+ shardIndexFromSecondarySliverIndex: () => shardIndexFromSecondarySliverIndex,
29
30
  signersToBitmap: () => signersToBitmap,
31
+ sliverPairIndexFromSecondarySliverIndex: () => sliverPairIndexFromSecondarySliverIndex,
30
32
  storageUnitsFromSize: () => storageUnitsFromSize,
31
33
  toPairIndex: () => toPairIndex,
32
34
  toShardIndex: () => toShardIndex,
@@ -89,6 +91,13 @@ function toShardIndex(sliverPairIndex, blobId, numShards) {
89
91
  const offset = rotationOffset(import_bcs2.BlobId.serialize(blobId).toBytes(), numShards);
90
92
  return (sliverPairIndex + offset) % numShards;
91
93
  }
94
+ function sliverPairIndexFromSecondarySliverIndex(sliverIndex, numShards) {
95
+ return numShards - sliverIndex - 1;
96
+ }
97
+ function shardIndexFromSecondarySliverIndex(sliverIndex, blobId, numShards) {
98
+ const sliverPairIndex = sliverPairIndexFromSecondarySliverIndex(sliverIndex, numShards);
99
+ return toShardIndex(sliverPairIndex, blobId, numShards);
100
+ }
92
101
  function toPairIndex(shardIndex, blobId, numShards) {
93
102
  const offset = rotationOffset(import_bcs2.BlobId.serialize(blobId).toBytes(), numShards);
94
103
  return (numShards + shardIndex - offset) % numShards;