@mysten/walrus 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/wasm.js CHANGED
@@ -5,70 +5,73 @@ import init, {
5
5
  bls12381_min_pk_verify
6
6
  } from "@mysten/walrus-wasm";
7
7
  import { BlobId, blobIdFromBytes } from "./utils/bcs.js";
8
- async function encodeBlob(nShards, bytes, encodingType = "RS2") {
9
- await init();
10
- const encoder = new BlobEncoder(nShards);
11
- if (encodingType !== "RS2") {
12
- throw new Error(`Unsupported encoding type: ${encodingType}`);
8
+ async function getWasmBindings(url) {
9
+ await init({ module_or_path: url });
10
+ function encodeBlob(nShards, bytes, encodingType = "RS2") {
11
+ const encoder = new BlobEncoder(nShards);
12
+ if (encodingType !== "RS2") {
13
+ throw new Error(`Unsupported encoding type: ${encodingType}`);
14
+ }
15
+ const [sliverPairs, metadata, rootHash] = encoder.encode_with_metadata(bytes);
16
+ return {
17
+ sliverPairs,
18
+ blobId: blobIdFromBytes(new Uint8Array(metadata.blob_id)),
19
+ metadata: metadata.metadata,
20
+ rootHash: new Uint8Array(rootHash.Digest)
21
+ };
13
22
  }
14
- const [sliverPairs, metadata, rootHash] = encoder.encode_with_metadata(bytes);
15
- return {
16
- sliverPairs,
17
- blobId: blobIdFromBytes(new Uint8Array(metadata.blob_id)),
18
- metadata: metadata.metadata,
19
- rootHash: new Uint8Array(rootHash.Digest)
20
- };
21
- }
22
- async function combineSignatures(confirmations, signerIndices) {
23
- await init();
24
- const signature = bls12381_min_pk_aggregate(
25
- confirmations.map((confirmation) => fromBase64(confirmation.signature))
26
- );
27
- return {
28
- signers: signerIndices,
29
- serializedMessage: fromBase64(confirmations[0].serializedMessage),
30
- signature
31
- };
32
- }
33
- function decodePrimarySlivers(blobId, nShards, size, slivers, encodingType = "RS2") {
34
- const encoder = new BlobEncoder(nShards);
35
- if (encodingType !== "RS2") {
36
- throw new Error(`Unsupported encoding type: ${encodingType}`);
23
+ function combineSignatures(confirmations, signerIndices) {
24
+ const signature = bls12381_min_pk_aggregate(
25
+ confirmations.map((confirmation) => fromBase64(confirmation.signature))
26
+ );
27
+ return {
28
+ signers: signerIndices,
29
+ serializedMessage: fromBase64(confirmations[0].serializedMessage),
30
+ signature
31
+ };
37
32
  }
38
- const [bytes] = encoder.decode(
39
- BlobId.serialize(blobId).toBytes(),
40
- BigInt(size),
41
- slivers.map((sliver) => ({
42
- ...sliver,
43
- _sliver_type: void 0
44
- }))
45
- );
46
- return new Uint8Array(bytes);
47
- }
48
- async function getVerifySignature() {
49
- await init();
50
- return (confirmation, publicKey) => bls12381_min_pk_verify(
51
- fromBase64(confirmation.signature),
52
- publicKey,
53
- fromBase64(confirmation.serializedMessage)
54
- );
55
- }
56
- function computeMetadata(nShards, bytes, encodingType = "RS2") {
57
- const encoder = new BlobEncoder(nShards);
58
- const metadata = encoder.compute_metadata(bytes);
59
- if (encodingType !== "RS2") {
60
- throw new Error(`Unsupported encoding type: ${encodingType}`);
33
+ function decodePrimarySlivers(blobId, nShards, size, slivers, encodingType = "RS2") {
34
+ const encoder = new BlobEncoder(nShards);
35
+ if (encodingType !== "RS2") {
36
+ throw new Error(`Unsupported encoding type: ${encodingType}`);
37
+ }
38
+ const [bytes] = encoder.decode(
39
+ BlobId.serialize(blobId).toBytes(),
40
+ BigInt(size),
41
+ slivers.map((sliver) => ({
42
+ ...sliver,
43
+ _sliver_type: void 0
44
+ }))
45
+ );
46
+ return new Uint8Array(bytes);
47
+ }
48
+ function getVerifySignature() {
49
+ return (confirmation, publicKey) => bls12381_min_pk_verify(
50
+ fromBase64(confirmation.signature),
51
+ publicKey,
52
+ fromBase64(confirmation.serializedMessage)
53
+ );
54
+ }
55
+ function computeMetadata(nShards, bytes, encodingType = "RS2") {
56
+ const encoder = new BlobEncoder(nShards);
57
+ const metadata = encoder.compute_metadata(bytes);
58
+ if (encodingType !== "RS2") {
59
+ throw new Error(`Unsupported encoding type: ${encodingType}`);
60
+ }
61
+ return {
62
+ ...metadata,
63
+ blob_id: blobIdFromBytes(new Uint8Array(metadata.blob_id))
64
+ };
61
65
  }
62
66
  return {
63
- ...metadata,
64
- blob_id: blobIdFromBytes(new Uint8Array(metadata.blob_id))
67
+ encodeBlob,
68
+ combineSignatures,
69
+ decodePrimarySlivers,
70
+ getVerifySignature,
71
+ computeMetadata
65
72
  };
66
73
  }
67
74
  export {
68
- combineSignatures,
69
- computeMetadata,
70
- decodePrimarySlivers,
71
- encodeBlob,
72
- getVerifySignature
75
+ getWasmBindings
73
76
  };
74
77
  //# sourceMappingURL=wasm.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/wasm.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@mysten/bcs';\nimport init, {\n\tBlobEncoder,\n\tbls12381_min_pk_aggregate,\n\tbls12381_min_pk_verify,\n} from '@mysten/walrus-wasm';\n\nimport type { StorageConfirmation } from './storage-node/types.js';\nimport type { EncodingType } from './types.js';\nimport type { BlobMetadata, BlobMetadataWithId, SliverData, SliverPair } from './utils/bcs.js';\nimport { BlobId, blobIdFromBytes } from './utils/bcs.js';\n\nexport interface EncodedBlob {\n\tsliverPairs: (typeof SliverPair.$inferInput)[];\n\tblobId: string;\n\tmetadata: typeof BlobMetadata.$inferInput;\n\trootHash: Uint8Array;\n}\n\nexport async function encodeBlob(\n\tnShards: number,\n\tbytes: Uint8Array,\n\tencodingType: EncodingType = 'RS2',\n): Promise<EncodedBlob> {\n\tawait init();\n\n\tconst encoder = new BlobEncoder(nShards);\n\n\tif (encodingType !== 'RS2') {\n\t\tthrow new Error(`Unsupported encoding type: ${encodingType}`);\n\t}\n\n\tconst [sliverPairs, metadata, rootHash] = encoder.encode_with_metadata(bytes);\n\n\treturn {\n\t\tsliverPairs,\n\t\tblobId: blobIdFromBytes(new Uint8Array(metadata.blob_id)),\n\t\tmetadata: metadata.metadata,\n\t\trootHash: new Uint8Array(rootHash.Digest),\n\t};\n}\n\nexport interface CombinedSignature {\n\tsigners: number[];\n\tserializedMessage: Uint8Array;\n\tsignature: Uint8Array;\n}\n\nexport async function combineSignatures(\n\tconfirmations: StorageConfirmation[],\n\tsignerIndices: number[],\n): Promise<CombinedSignature> {\n\tawait init();\n\n\tconst signature = bls12381_min_pk_aggregate(\n\t\tconfirmations.map((confirmation) => fromBase64(confirmation.signature)),\n\t);\n\n\treturn {\n\t\tsigners: signerIndices,\n\t\tserializedMessage: fromBase64(confirmations[0].serializedMessage),\n\t\tsignature,\n\t};\n}\n\nexport function decodePrimarySlivers(\n\tblobId: string,\n\tnShards: number,\n\tsize: number | bigint | string,\n\tslivers: (typeof SliverData.$inferInput)[],\n\tencodingType: EncodingType = 'RS2',\n): Uint8Array {\n\tconst encoder = new BlobEncoder(nShards);\n\n\tif (encodingType !== 'RS2') {\n\t\tthrow new Error(`Unsupported encoding type: ${encodingType}`);\n\t}\n\n\tconst [bytes] = encoder.decode(\n\t\tBlobId.serialize(blobId).toBytes(),\n\t\tBigInt(size),\n\t\tslivers.map((sliver) => ({\n\t\t\t...sliver,\n\t\t\t_sliver_type: undefined,\n\t\t})),\n\t);\n\n\treturn new Uint8Array(bytes);\n}\n\nexport async function getVerifySignature() {\n\tawait init();\n\treturn (confirmation: StorageConfirmation, publicKey: Uint8Array) =>\n\t\tbls12381_min_pk_verify(\n\t\t\tfromBase64(confirmation.signature),\n\t\t\tpublicKey,\n\t\t\tfromBase64(confirmation.serializedMessage),\n\t\t);\n}\n\nexport function computeMetadata(\n\tnShards: number,\n\tbytes: Uint8Array,\n\tencodingType: EncodingType = 'RS2',\n): typeof BlobMetadataWithId.$inferInput & { blob_id: string } {\n\tconst encoder = new BlobEncoder(nShards);\n\tconst metadata = encoder.compute_metadata(bytes);\n\n\tif (encodingType !== 'RS2') {\n\t\tthrow new Error(`Unsupported encoding type: ${encodingType}`);\n\t}\n\n\tre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;AAEA,SAAO,IAAI,WAAW,KAAK;AAC5B;AAEA,eAAsB,qBAAqB;AAC1C,QAAM,KAAK;AACX,SAAO,CAAC,cAAmC,cAC1C;AAAA,IACC,WAAW,aAAa,SAAS;AAAA,IACjC;AAAA,IACA,WAAW,aAAa,iBAAiB;AAAA,EAC1C;AACF;AAEO,SAAS,gBACf,SACA,OACA,eAA6B,OACiC;AAC9D,QAAM,UAAU,IAAI,YAAY,OAAO;AACvC,QAAM,WAAW,QAAQ,iBAAiB,KAAK;AAE/C,MAAI,iBAAiB,OAAO;AAC3B,UAAM,IAAI,MAAM,8BAA8B,YAAY,EAAE;AAAA,EAC7D;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,SAAS,gBAAgB,IAAI,WAAW,SAAS,OAAO,CAAC;AAAA,EAC1D;AACD;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@mysten/bcs';\nimport init, {\n\tBlobEncoder,\n\tbls12381_min_pk_aggregate,\n\tbls12381_min_pk_verify,\n} from '@mysten/walrus-wasm';\n\nimport type { StorageConfirmation } from './storage-node/types.js';\nimport type { EncodingType } from './types.js';\nimport type { BlobMetadata, BlobMetadataWithId, SliverData, SliverPair } from './utils/bcs.js';\nimport { BlobId, blobIdFromBytes } from './utils/bcs.js';\n\nexport interface EncodedBlob {\n\tsliverPairs: (typeof SliverPair.$inferInput)[];\n\tblobId: string;\n\tmetadata: typeof BlobMetadata.$inferInput;\n\trootHash: Uint8Array;\n}\n\nexport interface CombinedSignature {\n\tsigners: number[];\n\tserializedMessage: Uint8Array;\n\tsignature: Uint8Array;\n}\n\nexport async function getWasmBindings(url?: string) {\n\tawait init({ module_or_path: url });\n\n\tfunction encodeBlob(\n\t\tnShards: number,\n\t\tbytes: Uint8Array,\n\t\tencodingType: EncodingType = 'RS2',\n\t): EncodedBlob {\n\t\tconst encoder = new BlobEncoder(nShards);\n\n\t\tif (encodingType !== 'RS2') {\n\t\t\tthrow new Error(`Unsupported encoding type: ${encodingType}`);\n\t\t}\n\n\t\tconst [sliverPairs, metadata, rootHash] = encoder.encode_with_metadata(bytes);\n\n\t\treturn {\n\t\t\tsliverPairs,\n\t\t\tblobId: blobIdFromBytes(new Uint8Array(metadata.blob_id)),\n\t\t\tmetadata: metadata.metadata,\n\t\t\trootHash: new Uint8Array(rootHash.Digest),\n\t\t};\n\t}\n\n\tfunction combineSignatures(\n\t\tconfirmations: StorageConfirmation[],\n\t\tsignerIndices: number[],\n\t): CombinedSignature {\n\t\tconst signature = bls12381_min_pk_aggregate(\n\t\t\tconfirmations.map((confirmation) => fromBase64(confirmation.signature)),\n\t\t);\n\n\t\treturn {\n\t\t\tsigners: signerIndices,\n\t\t\tserializedMessage: fromBase64(confirmations[0].serializedMessage),\n\t\t\tsignature,\n\t\t};\n\t}\n\n\tfunction decodePrimarySlivers(\n\t\tblobId: string,\n\t\tnShards: number,\n\t\tsize: number | bigint | string,\n\t\tslivers: (typeof SliverData.$inferInput)[],\n\t\tencodingType: EncodingType = 'RS2',\n\t): Uint8Array {\n\t\tconst encoder = new BlobEncoder(nShards);\n\n\t\tif (encodingType !== 'RS2') {\n\t\t\tthrow new Error(`Unsupported encoding type: ${encodingType}`);\n\t\t}\n\n\t\tconst [bytes] = encoder.decode(\n\t\t\tBlobId.serialize(blobId).toBytes(),\n\t\t\tBigInt(size),\n\t\t\tslivers.map((sliver) => ({\n\t\t\t\t...sliver,\n\t\t\t\t_sliver_type: undefined,\n\t\t\t})),\n\t\t);\n\n\t\treturn new Uint8Array(bytes);\n\t}\n\n\tfunction getVerifySignature() {\n\t\treturn (confirmation: StorageConfirmation, publicKey: Uint8Array) =>\n\t\t\tbls12381_min_pk_verify(\n\t\t\t\tfromBase64(confirmation.signature),\n\t\t\t\tpublicKey,\n\t\t\t\tfromBase64(confirmation.serializedMessage),\n\t\t\t);\n\t}\n\n\tfunction computeMetadata(\n\t\tnShards: number,\n\t\tbytes: Uint8Array,\n\t\tencodingType: EncodingType = 'RS2',\n\t): typeof BlobMetadataWithId.$inferInput & { blob_id: string } {\n\t\tconst encoder = new BlobEncoder(nShards);\n\t\tconst metadata = encoder.compute_metadata(bytes);\n\n\t\tif (encodingType !== 'RS2') {\n\t\t\tthrow new Error(`Unsupported encoding type: ${encodingType}`);\n\t\t}\n\n\t\treturn {\n\t\t\t...metadata,\n\t\t\tblob_id: blobIdFromBytes(new Uint8Array(metadata.blob_id)),\n\t\t};\n\t}\n\n\treturn {\n\t\tencodeBlob,\n\t\tcombineSignatures,\n\t\tdecodePrimarySlivers,\n\t\tgetVerifySignature,\n\t\tcomputeMetadata,\n\t};\n}\n"],
5
+ "mappings": "AAGA,SAAS,kBAAkB;AAC3B,OAAO;AAAA,EACN;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,SAAS,QAAQ,uBAAuB;AAexC,eAAsB,gBAAgB,KAAc;AACnD,QAAM,KAAK,EAAE,gBAAgB,IAAI,CAAC;AAElC,WAAS,WACR,SACA,OACA,eAA6B,OACf;AACd,UAAM,UAAU,IAAI,YAAY,OAAO;AAEvC,QAAI,iBAAiB,OAAO;AAC3B,YAAM,IAAI,MAAM,8BAA8B,YAAY,EAAE;AAAA,IAC7D;AAEA,UAAM,CAAC,aAAa,UAAU,QAAQ,IAAI,QAAQ,qBAAqB,KAAK;AAE5E,WAAO;AAAA,MACN;AAAA,MACA,QAAQ,gBAAgB,IAAI,WAAW,SAAS,OAAO,CAAC;AAAA,MACxD,UAAU,SAAS;AAAA,MACnB,UAAU,IAAI,WAAW,SAAS,MAAM;AAAA,IACzC;AAAA,EACD;AAEA,WAAS,kBACR,eACA,eACoB;AACpB,UAAM,YAAY;AAAA,MACjB,cAAc,IAAI,CAAC,iBAAiB,WAAW,aAAa,SAAS,CAAC;AAAA,IACvE;AAEA,WAAO;AAAA,MACN,SAAS;AAAA,MACT,mBAAmB,WAAW,cAAc,CAAC,EAAE,iBAAiB;AAAA,MAChE;AAAA,IAC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