@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/CHANGELOG.md +17 -0
- package/README.md +31 -0
- package/dist/cjs/client.d.ts +10 -2
- package/dist/cjs/client.js +167 -128
- package/dist/cjs/client.js.map +3 -3
- package/dist/cjs/types.d.ts +13 -4
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/object-loader.d.ts +4 -3
- package/dist/cjs/utils/object-loader.js +10 -36
- package/dist/cjs/utils/object-loader.js.map +2 -2
- package/dist/cjs/wasm.d.ts +9 -7
- package/dist/cjs/wasm.js +61 -58
- package/dist/cjs/wasm.js.map +2 -2
- package/dist/esm/client.d.ts +10 -2
- package/dist/esm/client.js +169 -136
- package/dist/esm/client.js.map +2 -2
- package/dist/esm/types.d.ts +13 -4
- package/dist/esm/utils/object-loader.d.ts +4 -3
- package/dist/esm/utils/object-loader.js +10 -36
- package/dist/esm/utils/object-loader.js.map +2 -2
- package/dist/esm/wasm.d.ts +9 -7
- package/dist/esm/wasm.js +61 -58
- package/dist/esm/wasm.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/dist/cjs/utils/memo.d.ts +0 -5
- package/dist/cjs/utils/memo.js +0 -59
- package/dist/cjs/utils/memo.js.map +0 -7
- package/dist/esm/utils/memo.d.ts +0 -5
- package/dist/esm/utils/memo.js +0 -39
- package/dist/esm/utils/memo.js.map +0 -7
package/dist/cjs/wasm.d.ts
CHANGED
|
@@ -7,15 +7,17 @@ export interface EncodedBlob {
|
|
|
7
7
|
metadata: typeof BlobMetadata.$inferInput;
|
|
8
8
|
rootHash: Uint8Array;
|
|
9
9
|
}
|
|
10
|
-
export declare function encodeBlob(nShards: number, bytes: Uint8Array, encodingType?: EncodingType): Promise<EncodedBlob>;
|
|
11
10
|
export interface CombinedSignature {
|
|
12
11
|
signers: number[];
|
|
13
12
|
serializedMessage: Uint8Array;
|
|
14
13
|
signature: Uint8Array;
|
|
15
14
|
}
|
|
16
|
-
export declare function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
export declare function getWasmBindings(url?: string): Promise<{
|
|
16
|
+
encodeBlob: (nShards: number, bytes: Uint8Array, encodingType?: EncodingType) => EncodedBlob;
|
|
17
|
+
combineSignatures: (confirmations: StorageConfirmation[], signerIndices: number[]) => CombinedSignature;
|
|
18
|
+
decodePrimarySlivers: (blobId: string, nShards: number, size: number | bigint | string, slivers: (typeof SliverData.$inferInput)[], encodingType?: EncodingType) => Uint8Array;
|
|
19
|
+
getVerifySignature: () => (confirmation: StorageConfirmation, publicKey: Uint8Array) => boolean;
|
|
20
|
+
computeMetadata: (nShards: number, bytes: Uint8Array, encodingType?: EncodingType) => typeof BlobMetadataWithId.$inferInput & {
|
|
21
|
+
blob_id: string;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
package/dist/cjs/wasm.js
CHANGED
|
@@ -28,73 +28,76 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var wasm_exports = {};
|
|
30
30
|
__export(wasm_exports, {
|
|
31
|
-
|
|
32
|
-
computeMetadata: () => computeMetadata,
|
|
33
|
-
decodePrimarySlivers: () => decodePrimarySlivers,
|
|
34
|
-
encodeBlob: () => encodeBlob,
|
|
35
|
-
getVerifySignature: () => getVerifySignature
|
|
31
|
+
getWasmBindings: () => getWasmBindings
|
|
36
32
|
});
|
|
37
33
|
module.exports = __toCommonJS(wasm_exports);
|
|
38
34
|
var import_bcs = require("@mysten/bcs");
|
|
39
35
|
var import_walrus_wasm = __toESM(require("@mysten/walrus-wasm"));
|
|
40
36
|
var import_bcs2 = require("./utils/bcs.js");
|
|
41
|
-
async function
|
|
42
|
-
await (0, import_walrus_wasm.default)();
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
async function getWasmBindings(url) {
|
|
38
|
+
await (0, import_walrus_wasm.default)({ module_or_path: url });
|
|
39
|
+
function encodeBlob(nShards, bytes, encodingType = "RS2") {
|
|
40
|
+
const encoder = new import_walrus_wasm.BlobEncoder(nShards);
|
|
41
|
+
if (encodingType !== "RS2") {
|
|
42
|
+
throw new Error(`Unsupported encoding type: ${encodingType}`);
|
|
43
|
+
}
|
|
44
|
+
const [sliverPairs, metadata, rootHash] = encoder.encode_with_metadata(bytes);
|
|
45
|
+
return {
|
|
46
|
+
sliverPairs,
|
|
47
|
+
blobId: (0, import_bcs2.blobIdFromBytes)(new Uint8Array(metadata.blob_id)),
|
|
48
|
+
metadata: metadata.metadata,
|
|
49
|
+
rootHash: new Uint8Array(rootHash.Digest)
|
|
50
|
+
};
|
|
46
51
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
await (0, import_walrus_wasm.default)();
|
|
57
|
-
const signature = (0, import_walrus_wasm.bls12381_min_pk_aggregate)(
|
|
58
|
-
confirmations.map((confirmation) => (0, import_bcs.fromBase64)(confirmation.signature))
|
|
59
|
-
);
|
|
60
|
-
return {
|
|
61
|
-
signers: signerIndices,
|
|
62
|
-
serializedMessage: (0, import_bcs.fromBase64)(confirmations[0].serializedMessage),
|
|
63
|
-
signature
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function decodePrimarySlivers(blobId, nShards, size, slivers, encodingType = "RS2") {
|
|
67
|
-
const encoder = new import_walrus_wasm.BlobEncoder(nShards);
|
|
68
|
-
if (encodingType !== "RS2") {
|
|
69
|
-
throw new Error(`Unsupported encoding type: ${encodingType}`);
|
|
52
|
+
function combineSignatures(confirmations, signerIndices) {
|
|
53
|
+
const signature = (0, import_walrus_wasm.bls12381_min_pk_aggregate)(
|
|
54
|
+
confirmations.map((confirmation) => (0, import_bcs.fromBase64)(confirmation.signature))
|
|
55
|
+
);
|
|
56
|
+
return {
|
|
57
|
+
signers: signerIndices,
|
|
58
|
+
serializedMessage: (0, import_bcs.fromBase64)(confirmations[0].serializedMessage),
|
|
59
|
+
signature
|
|
60
|
+
};
|
|
70
61
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
62
|
+
function decodePrimarySlivers(blobId, nShards, size, slivers, encodingType = "RS2") {
|
|
63
|
+
const encoder = new import_walrus_wasm.BlobEncoder(nShards);
|
|
64
|
+
if (encodingType !== "RS2") {
|
|
65
|
+
throw new Error(`Unsupported encoding type: ${encodingType}`);
|
|
66
|
+
}
|
|
67
|
+
const [bytes] = encoder.decode(
|
|
68
|
+
import_bcs2.BlobId.serialize(blobId).toBytes(),
|
|
69
|
+
BigInt(size),
|
|
70
|
+
slivers.map((sliver) => ({
|
|
71
|
+
...sliver,
|
|
72
|
+
_sliver_type: void 0
|
|
73
|
+
}))
|
|
74
|
+
);
|
|
75
|
+
return new Uint8Array(bytes);
|
|
76
|
+
}
|
|
77
|
+
function getVerifySignature() {
|
|
78
|
+
return (confirmation, publicKey) => (0, import_walrus_wasm.bls12381_min_pk_verify)(
|
|
79
|
+
(0, import_bcs.fromBase64)(confirmation.signature),
|
|
80
|
+
publicKey,
|
|
81
|
+
(0, import_bcs.fromBase64)(confirmation.serializedMessage)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
function computeMetadata(nShards, bytes, encodingType = "RS2") {
|
|
85
|
+
const encoder = new import_walrus_wasm.BlobEncoder(nShards);
|
|
86
|
+
const metadata = encoder.compute_metadata(bytes);
|
|
87
|
+
if (encodingType !== "RS2") {
|
|
88
|
+
throw new Error(`Unsupported encoding type: ${encodingType}`);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
...metadata,
|
|
92
|
+
blob_id: (0, import_bcs2.blobIdFromBytes)(new Uint8Array(metadata.blob_id))
|
|
93
|
+
};
|
|
94
94
|
}
|
|
95
95
|
return {
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
encodeBlob,
|
|
97
|
+
combineSignatures,
|
|
98
|
+
decodePrimarySlivers,
|
|
99
|
+
getVerifySignature,
|
|
100
|
+
computeMetadata
|
|
98
101
|
};
|
|
99
102
|
}
|
|
100
103
|
//# sourceMappingURL=wasm.js.map
|
package/dist/cjs/wasm.js.map
CHANGED
|
@@ -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):
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA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;AAC7B,WAAO,CAAC,cAAmC,kBAC1C;AAAA,UACC,uBAAW,aAAa,SAAS;AAAA,MACjC;AAAA,UACA,uBAAW,aAAa,iBAAiB;AAAA,IAC1C;AAAA,EACF;AAEA,WAAS,gBACR,SACA,OACA,eAA6B,OACiC;AAC9D,UAAM,UAAU,IAAI,+BAAY,OAAO;AACvC,UAAM,WAAW,QAAQ,iBAAiB,KAAK;AAE/C,QAAI,iBAAiB,OAAO;AAC3B,YAAM,IAAI,MAAM,8BAA8B,YAAY,EAAE;AAAA,IAC7D;AAEA,WAAO;AAAA,MACN,GAAG;AAAA,MACH,aAAS,6BAAgB,IAAI,WAAW,SAAS,OAAO,CAAC;AAAA,IAC1D;AAAA,EACD;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["import_bcs", "init"]
|
|
7
7
|
}
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
import { SuiClient } from '@mysten/sui/client';
|
|
1
2
|
import type { Signer } from '@mysten/sui/cryptography';
|
|
3
|
+
import type { ClientWithExtensions } from '@mysten/sui/experimental';
|
|
2
4
|
import { Transaction } from '@mysten/sui/transactions';
|
|
3
5
|
import { Blob } from './contracts/blob.js';
|
|
4
6
|
import type { BlobStatus } from './storage-node/types.js';
|
|
5
|
-
import type { CertifyBlobOptions, DeleteBlobOptions, ExtendBlobOptions, GetBlobMetadataOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageWithSizeOptions, WalrusClientConfig, WriteBlobAttributesOptions, WriteBlobOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteMetadataOptions, WriteSliverOptions, WriteSliversToNodeOptions } from './types.js';
|
|
7
|
+
import type { CertifyBlobOptions, DeleteBlobOptions, ExtendBlobOptions, GetBlobMetadataOptions, GetSliversOptions, GetStorageConfirmationOptions, GetVerifiedBlobStatusOptions, ReadBlobOptions, RegisterBlobOptions, SliversForNode, StorageWithSizeOptions, WalrusClientConfig, WalrusClientExtensionOptions, WriteBlobAttributesOptions, WriteBlobOptions, WriteEncodedBlobOptions, WriteEncodedBlobToNodesOptions, WriteMetadataOptions, WriteSliverOptions, WriteSliversToNodeOptions } from './types.js';
|
|
6
8
|
export declare class WalrusClient {
|
|
7
9
|
#private;
|
|
8
10
|
constructor(config: WalrusClientConfig);
|
|
11
|
+
static experimental_asClientExtension({ packageConfig, network, ...options }?: WalrusClientExtensionOptions): {
|
|
12
|
+
name: "walrus";
|
|
13
|
+
register: (client: ClientWithExtensions<{
|
|
14
|
+
jsonRpc: SuiClient;
|
|
15
|
+
}>) => WalrusClient;
|
|
16
|
+
};
|
|
9
17
|
/** The Move type for a Blob object */
|
|
10
|
-
getBlobType
|
|
18
|
+
getBlobType(): string | Promise<string>;
|
|
11
19
|
/** The cached system object for the walrus package */
|
|
12
20
|
systemObject(): Promise<{
|
|
13
21
|
id: {
|