@arcadiasystems/morse-sdk 0.1.3 → 0.2.0
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 +115 -0
- package/README.md +31 -9
- package/dist/codecs.d.ts +7 -1
- package/dist/codecs.d.ts.map +1 -1
- package/dist/codecs.js +12 -0
- package/dist/codecs.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -1
- package/dist/config.js.map +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.format.js +2 -0
- package/dist/errors.format.js.map +1 -1
- package/dist/errors.js +44 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/ops/allowlist.d.ts +79 -0
- package/dist/ops/allowlist.d.ts.map +1 -0
- package/dist/ops/allowlist.js +122 -0
- package/dist/ops/allowlist.js.map +1 -0
- package/dist/ops/file-from-bytes.d.ts +84 -0
- package/dist/ops/file-from-bytes.d.ts.map +1 -0
- package/dist/ops/file-from-bytes.js +133 -0
- package/dist/ops/file-from-bytes.js.map +1 -0
- package/dist/ops/file.d.ts +88 -0
- package/dist/ops/file.d.ts.map +1 -0
- package/dist/ops/file.js +142 -0
- package/dist/ops/file.js.map +1 -0
- package/dist/ops/index.d.ts +3 -0
- package/dist/ops/index.d.ts.map +1 -1
- package/dist/ops/index.js +3 -0
- package/dist/ops/index.js.map +1 -1
- package/dist/ptb/allowlist.d.ts +65 -0
- package/dist/ptb/allowlist.d.ts.map +1 -0
- package/dist/ptb/allowlist.js +75 -0
- package/dist/ptb/allowlist.js.map +1 -0
- package/dist/ptb/file.d.ts +58 -0
- package/dist/ptb/file.d.ts.map +1 -0
- package/dist/ptb/file.js +108 -0
- package/dist/ptb/file.js.map +1 -0
- package/dist/read/files-reader.d.ts +59 -0
- package/dist/read/files-reader.d.ts.map +1 -0
- package/dist/read/files-reader.js +247 -0
- package/dist/read/files-reader.js.map +1 -0
- package/dist/read/index.d.ts +1 -0
- package/dist/read/index.d.ts.map +1 -1
- package/dist/read/index.js +1 -0
- package/dist/read/index.js.map +1 -1
- package/dist/seal/adapter.d.ts +22 -1
- package/dist/seal/adapter.d.ts.map +1 -1
- package/dist/seal/allowlist-identity.d.ts +36 -0
- package/dist/seal/allowlist-identity.d.ts.map +1 -0
- package/dist/seal/allowlist-identity.js +81 -0
- package/dist/seal/allowlist-identity.js.map +1 -0
- package/dist/seal/default-adapter.d.ts +16 -1
- package/dist/seal/default-adapter.d.ts.map +1 -1
- package/dist/seal/default-adapter.js +56 -1
- package/dist/seal/default-adapter.js.map +1 -1
- package/dist/seal/index.d.ts +2 -1
- package/dist/seal/index.d.ts.map +1 -1
- package/dist/seal/index.js +1 -0
- package/dist/seal/index.js.map +1 -1
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/dist/wallets/index.d.ts +1 -1
- package/dist/wallets/index.d.ts.map +1 -1
- package/dist/wallets/index.js +1 -1
- package/dist/wallets/index.js.map +1 -1
- package/dist/wallets/keypair-adapter.d.ts.map +1 -1
- package/dist/wallets/keypair-adapter.js +2 -0
- package/dist/wallets/keypair-adapter.js.map +1 -1
- package/dist/wallets/wallet-standard-signer.d.ts +51 -1
- package/dist/wallets/wallet-standard-signer.d.ts.map +1 -1
- package/dist/wallets/wallet-standard-signer.js +96 -1
- package/dist/wallets/wallet-standard-signer.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RPC-backed reader for the allowlist + file modules. EncryptedFile objects
|
|
3
|
+
* are shared (every successful create_*_file flow calls share_file), so
|
|
4
|
+
* "list files owned by an address" is not exposed at the RPC layer — there
|
|
5
|
+
* is no on-chain owner field for `listOwnedObjects` to filter on. Listing
|
|
6
|
+
* accessible files requires event-based indexing; a future indexer-backed
|
|
7
|
+
* implementation will expose it through this same interface.
|
|
8
|
+
*/
|
|
9
|
+
import { toAllowlistCapId, toAllowlistId, toBlobObjectId, toEncryptedFileId, toSuiAddress, toWalrusBlobId, } from "../codecs.js";
|
|
10
|
+
import { NotFoundError, TransportError, ValidationError } from "../errors.js";
|
|
11
|
+
const DEFAULT_PAGE_LIMIT = 50;
|
|
12
|
+
export class RpcFilesReader {
|
|
13
|
+
client;
|
|
14
|
+
typePackageId;
|
|
15
|
+
constructor(client, typePackageId) {
|
|
16
|
+
this.client = client;
|
|
17
|
+
this.typePackageId = typePackageId;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Build a reader from a morse package config. Uses `packageId` (the
|
|
21
|
+
* current published-at) for type filters because the allowlist + file
|
|
22
|
+
* modules were introduced in the v2 upgrade — Sui identifies a type by
|
|
23
|
+
* the package id where it was DEFINED, not by the package's genesis
|
|
24
|
+
* original-id. This differs from `RpcPublicationReader`, which uses
|
|
25
|
+
* `originalPackageId` because publication / collection / entry were
|
|
26
|
+
* defined in v1.
|
|
27
|
+
*/
|
|
28
|
+
static fromMorseConfig(config, client) {
|
|
29
|
+
return new RpcFilesReader(client, config.packageId);
|
|
30
|
+
}
|
|
31
|
+
async getAllowlist(id, signal) {
|
|
32
|
+
const validated = toAllowlistId(id);
|
|
33
|
+
let response;
|
|
34
|
+
try {
|
|
35
|
+
response = await this.callClient("getObject", () => this.client.getObject({
|
|
36
|
+
objectId: validated,
|
|
37
|
+
include: { json: true },
|
|
38
|
+
...(signal === undefined ? {} : { signal }),
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error instanceof TransportError &&
|
|
43
|
+
isObjectNotFoundError(error.cause, validated)) {
|
|
44
|
+
throw new NotFoundError("allowlist", validated, {
|
|
45
|
+
cause: error.cause,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
const object = response.object;
|
|
51
|
+
if (!object) {
|
|
52
|
+
throw new NotFoundError("allowlist", validated);
|
|
53
|
+
}
|
|
54
|
+
return parseAllowlist(object);
|
|
55
|
+
}
|
|
56
|
+
async getEncryptedFile(id, signal) {
|
|
57
|
+
const validated = toEncryptedFileId(id);
|
|
58
|
+
let response;
|
|
59
|
+
try {
|
|
60
|
+
response = await this.callClient("getObject", () => this.client.getObject({
|
|
61
|
+
objectId: validated,
|
|
62
|
+
include: { json: true },
|
|
63
|
+
...(signal === undefined ? {} : { signal }),
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (error instanceof TransportError &&
|
|
68
|
+
isObjectNotFoundError(error.cause, validated)) {
|
|
69
|
+
throw new NotFoundError("encrypted-file", validated, {
|
|
70
|
+
cause: error.cause,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
const object = response.object;
|
|
76
|
+
if (!object) {
|
|
77
|
+
throw new NotFoundError("encrypted-file", validated);
|
|
78
|
+
}
|
|
79
|
+
return parseEncryptedFile(object);
|
|
80
|
+
}
|
|
81
|
+
async listAllowlistCapsOwnedBy(address, options = {}) {
|
|
82
|
+
const validated = toSuiAddress(address);
|
|
83
|
+
const { limit = DEFAULT_PAGE_LIMIT, cursor, signal } = options;
|
|
84
|
+
const capType = `${this.typePackageId}::allowlist::Cap`;
|
|
85
|
+
const response = await this.callClient("listOwnedObjects", () => this.client.listOwnedObjects({
|
|
86
|
+
owner: validated,
|
|
87
|
+
type: capType,
|
|
88
|
+
limit,
|
|
89
|
+
cursor: cursor ?? null,
|
|
90
|
+
include: { json: true },
|
|
91
|
+
...(signal === undefined ? {} : { signal }),
|
|
92
|
+
}));
|
|
93
|
+
const results = response.objects.map((object) => parseAllowlistCap(object));
|
|
94
|
+
return { results, nextCursor: response.cursor };
|
|
95
|
+
}
|
|
96
|
+
async callClient(operation, call) {
|
|
97
|
+
try {
|
|
98
|
+
return await call();
|
|
99
|
+
}
|
|
100
|
+
catch (cause) {
|
|
101
|
+
throw new TransportError(`${operation} failed`, {
|
|
102
|
+
cause,
|
|
103
|
+
operation: `sui.${operation}`,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function parseAllowlist(object) {
|
|
109
|
+
const json = object.json;
|
|
110
|
+
if (!json || typeof json !== "object") {
|
|
111
|
+
throw new NotFoundError("allowlist", object.objectId);
|
|
112
|
+
}
|
|
113
|
+
const record = json;
|
|
114
|
+
const name = readString(record, "name", "allowlist.name");
|
|
115
|
+
const members = readMembers(record);
|
|
116
|
+
return {
|
|
117
|
+
id: toAllowlistId(object.objectId),
|
|
118
|
+
name,
|
|
119
|
+
members,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function parseAllowlistCap(object) {
|
|
123
|
+
const json = object.json;
|
|
124
|
+
if (!json || typeof json !== "object") {
|
|
125
|
+
throw new NotFoundError("allowlist", object.objectId);
|
|
126
|
+
}
|
|
127
|
+
const record = json;
|
|
128
|
+
const allowlistIdField = record.allowlist_id;
|
|
129
|
+
if (typeof allowlistIdField !== "string") {
|
|
130
|
+
throw new ValidationError("allowlist::Cap.allowlist_id missing or not a string", "cap.allowlist_id");
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
id: toAllowlistCapId(object.objectId),
|
|
134
|
+
allowlistId: toAllowlistId(allowlistIdField),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function parseEncryptedFile(object) {
|
|
138
|
+
const json = object.json;
|
|
139
|
+
if (!json || typeof json !== "object") {
|
|
140
|
+
throw new NotFoundError("encrypted-file", object.objectId);
|
|
141
|
+
}
|
|
142
|
+
const record = json;
|
|
143
|
+
const owner = toSuiAddress(readString(record, "owner", "file.owner"));
|
|
144
|
+
// Sui gRPC serializes vector<u8> either as a base64 string (standard JSON
|
|
145
|
+
// representation) or as a number array (older RPC variants). Accept both.
|
|
146
|
+
const blobId = toWalrusBlobId(parseBlobIdField(record.blob_id));
|
|
147
|
+
const blobObjectId = readOptionalString(record, "blob_object_id");
|
|
148
|
+
const name = readString(record, "name", "file.name");
|
|
149
|
+
const contentType = readString(record, "content_type", "file.content_type");
|
|
150
|
+
const size = readSafeIntFromBig(record, "size", "file.size");
|
|
151
|
+
const encrypted = record.encrypted === true;
|
|
152
|
+
const allowlistIdRaw = readOptionalString(record, "allowlist_id");
|
|
153
|
+
const createdAtMs = readSafeIntFromBig(record, "created_at_ms", "file.created_at_ms");
|
|
154
|
+
return {
|
|
155
|
+
id: toEncryptedFileId(object.objectId),
|
|
156
|
+
owner,
|
|
157
|
+
blobId,
|
|
158
|
+
blobObjectId: blobObjectId === null ? null : toBlobObjectId(blobObjectId),
|
|
159
|
+
name,
|
|
160
|
+
contentType,
|
|
161
|
+
size,
|
|
162
|
+
encrypted,
|
|
163
|
+
allowlistId: allowlistIdRaw === null ? null : toAllowlistId(allowlistIdRaw),
|
|
164
|
+
createdAtMs,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function readMembers(record) {
|
|
168
|
+
const raw = record.members;
|
|
169
|
+
if (!raw || typeof raw !== "object") {
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
const contents = raw.contents;
|
|
173
|
+
if (!Array.isArray(contents)) {
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
const out = [];
|
|
177
|
+
for (const entry of contents) {
|
|
178
|
+
if (typeof entry === "string") {
|
|
179
|
+
out.push(toSuiAddress(entry));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
function readString(record, field, errorField) {
|
|
185
|
+
const value = record[field];
|
|
186
|
+
if (typeof value !== "string") {
|
|
187
|
+
throw new ValidationError(`${errorField} missing or not a string`, errorField);
|
|
188
|
+
}
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
function readOptionalString(record, field) {
|
|
192
|
+
const value = record[field];
|
|
193
|
+
if (value === null || value === undefined) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
return typeof value === "string" ? value : null;
|
|
197
|
+
}
|
|
198
|
+
function readSafeIntFromBig(record, field, errorField) {
|
|
199
|
+
const value = record[field];
|
|
200
|
+
if (typeof value !== "string" && typeof value !== "number") {
|
|
201
|
+
throw new ValidationError(`${errorField} missing or not a number`, errorField);
|
|
202
|
+
}
|
|
203
|
+
const big = BigInt(value);
|
|
204
|
+
if (big > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
205
|
+
throw new ValidationError(`${errorField} exceeds Number.MAX_SAFE_INTEGER`, errorField);
|
|
206
|
+
}
|
|
207
|
+
return Number(big);
|
|
208
|
+
}
|
|
209
|
+
function bytesArrayToBase64Url(bytes) {
|
|
210
|
+
let binary = "";
|
|
211
|
+
for (const byte of bytes) {
|
|
212
|
+
binary += String.fromCharCode(byte);
|
|
213
|
+
}
|
|
214
|
+
const b64 = btoa(binary);
|
|
215
|
+
return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Sui gRPC may serialize `vector<u8>` as:
|
|
219
|
+
* - a base64 string (standard JSON encoding)
|
|
220
|
+
* - a base64URL string (some RPC variants)
|
|
221
|
+
* - an array of numbers (older variants, or when the field is small)
|
|
222
|
+
* Return the URL-safe-base64 form Walrus uses for blob ids regardless of input shape.
|
|
223
|
+
*/
|
|
224
|
+
function parseBlobIdField(raw) {
|
|
225
|
+
if (Array.isArray(raw)) {
|
|
226
|
+
return bytesArrayToBase64Url(raw);
|
|
227
|
+
}
|
|
228
|
+
if (typeof raw !== "string") {
|
|
229
|
+
throw new ValidationError("file.blob_id must be a byte array or base64 string", "file.blob_id");
|
|
230
|
+
}
|
|
231
|
+
// Already URL-safe? Strip padding and return.
|
|
232
|
+
if (/^[A-Za-z0-9_-]+={0,2}$/.test(raw)) {
|
|
233
|
+
return raw.replace(/=+$/g, "");
|
|
234
|
+
}
|
|
235
|
+
// Standard base64 with + and / — convert to URL-safe.
|
|
236
|
+
if (/^[A-Za-z0-9+/]+={0,2}$/.test(raw)) {
|
|
237
|
+
return raw.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
238
|
+
}
|
|
239
|
+
throw new ValidationError("file.blob_id is not a recognized base64 string", "file.blob_id");
|
|
240
|
+
}
|
|
241
|
+
function isObjectNotFoundError(cause, _objectId) {
|
|
242
|
+
if (!(cause instanceof Error)) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
return /not found|NotFound|object.*not.*exist/i.test(cause.message);
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=files-reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files-reader.js","sourceRoot":"","sources":["../../src/read/files-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EACN,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,cAAc,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAW9E,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAqC9B,MAAM,OAAO,cAAc;IAER;IACA;IAFlB,YACkB,MAAoB,EACpB,aAAwB;QADxB,WAAM,GAAN,MAAM,CAAc;QACpB,kBAAa,GAAb,aAAa,CAAW;IACvC,CAAC;IAEJ;;;;;;;;OAQG;IACH,MAAM,CAAC,eAAe,CACrB,MAA+D,EAC/D,MAAoB;QAEpB,OAAO,IAAI,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,YAAY,CACjB,EAAe,EACf,MAAoB;QAEpB,MAAM,SAAS,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;QACpC,I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AC;AACrE,CAAC"}
|
package/dist/read/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Public barrel for the read layer.
|
|
3
3
|
*/
|
|
4
|
+
export { type AllowlistCapListPage, type FilesListOptions, type FilesReader, RpcFilesReader, } from "./files-reader.js";
|
|
4
5
|
export { type EntryListPage, type ListEntriesOptions, type ListPublicationsOptions, type ListPublisherCapsOptions, type OwnedPublication, type PublicationListPage, type PublicationReader, type PublisherCapListPage, RpcPublicationReader, type ScanEntriesOptions, } from "./reader.js";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/read/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/read/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,oBAAoB,EACpB,KAAK,kBAAkB,GACvB,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/read/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,cAAc,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,oBAAoB,EACpB,KAAK,kBAAkB,GACvB,MAAM,aAAa,CAAC"}
|
package/dist/read/index.js
CHANGED
package/dist/read/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/read/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EASN,oBAAoB,GAEpB,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/read/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAIN,cAAc,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EASN,oBAAoB,GAEpB,MAAM,aAAa,CAAC"}
|
package/dist/seal/adapter.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* (key servers, threshold, package id) is bound at construction time.
|
|
5
5
|
*/
|
|
6
6
|
import type { SessionKey } from "@mysten/seal";
|
|
7
|
-
import type { PublisherCapId, SealId } from "../types.js";
|
|
7
|
+
import type { AllowlistId, PublisherCapId, SealId } from "../types.js";
|
|
8
8
|
export interface SealEncryptOptions {
|
|
9
9
|
readonly sealId: SealId;
|
|
10
10
|
/** Optional additional authenticated data bound into the ciphertext. */
|
|
@@ -22,6 +22,12 @@ export interface SealDecryptOptions {
|
|
|
22
22
|
readonly sealId: SealId;
|
|
23
23
|
readonly publisherCapId: PublisherCapId;
|
|
24
24
|
}
|
|
25
|
+
/** Options for decrypting content gated by the allowlist policy. */
|
|
26
|
+
export interface SealDecryptUnderAllowlistOptions {
|
|
27
|
+
readonly sessionKey: SessionKey;
|
|
28
|
+
readonly sealId: SealId;
|
|
29
|
+
readonly allowlistId: AllowlistId;
|
|
30
|
+
}
|
|
25
31
|
/**
|
|
26
32
|
* Combined Seal adapter. Implementations bundle a `SealClient`, the morse
|
|
27
33
|
* package id (Seal binds it into ciphertext envelopes), and a TSS threshold.
|
|
@@ -52,5 +58,20 @@ export interface SealAdapter {
|
|
|
52
58
|
* @throws {TransportError} On network or PTB build failure.
|
|
53
59
|
*/
|
|
54
60
|
decrypt(ciphertext: Uint8Array, options: SealDecryptOptions): Promise<Uint8Array>;
|
|
61
|
+
/**
|
|
62
|
+
* Decrypt content gated by the allowlist policy. The Seal key servers
|
|
63
|
+
* verify that `sessionKey.getAddress()` is a current member of `allowlistId`
|
|
64
|
+
* by dry-running `allowlist::seal_approve(sealId, allowlist)`; non-members
|
|
65
|
+
* surface as `SealError("no-access")`.
|
|
66
|
+
*
|
|
67
|
+
* Distinct from `decrypt`, which targets the publisher policy. Both can
|
|
68
|
+
* coexist on the same adapter instance since policy targeting is decided
|
|
69
|
+
* by the seal_approve PTB the adapter constructs internally.
|
|
70
|
+
*
|
|
71
|
+
* @throws {SealError} On Seal authorization failure (`no-access`),
|
|
72
|
+
* decryption failure (`decrypt-failed`), session-key expiry, or rate limiting.
|
|
73
|
+
* @throws {TransportError} On network or PTB build failure.
|
|
74
|
+
*/
|
|
75
|
+
decryptUnderAllowlist(ciphertext: Uint8Array, options: SealDecryptUnderAllowlistOptions): Promise<Uint8Array>;
|
|
55
76
|
}
|
|
56
77
|
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/seal/adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/seal/adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEvE,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wEAAwE;IACxE,QAAQ,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IAClC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;CACxC;AAED,oEAAoE;AACpE,MAAM,WAAW,gCAAgC;IAChD,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CAClC;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;;;;;OAQG;IACH,OAAO,CACN,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,kBAAkB,GACzB,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC9B;;;;;;;;;;;OAWG;IACH,OAAO,CACN,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,kBAAkB,GACzB,OAAO,CAAC,UAAU,CAAC,CAAC;IACvB;;;;;;;;;;;;;OAaG;IACH,qBAAqB,CACpB,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,gCAAgC,GACvC,OAAO,CAAC,UAAU,CAAC,CAAC;CACvB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seal identity (`SealId`) construction and inspection for the allowlist policy.
|
|
3
|
+
* The Move layer (`allowlist::seal_approve`) enforces the byte format, so both
|
|
4
|
+
* encode and decode here must match the contract byte-for-byte.
|
|
5
|
+
*
|
|
6
|
+
* Layout: `allowlist_id(32) || policy_tag(u8=2) || nonce(>=1)`. Total length
|
|
7
|
+
* must be > 33 bytes (`allowlist::ESealInvalidId` otherwise).
|
|
8
|
+
*
|
|
9
|
+
* Distinct from the publisher policy (`publisher-identity.ts`) by policy tag
|
|
10
|
+
* (allowlist=2, publisher=1) so both can coexist in the same package without
|
|
11
|
+
* identity collisions.
|
|
12
|
+
*/
|
|
13
|
+
import { type AllowlistId, type SealId, SealPolicyTag } from "../types.js";
|
|
14
|
+
/** Structured view of an allowlist Seal identity. */
|
|
15
|
+
export interface AllowlistSealIdParts {
|
|
16
|
+
readonly allowlistId: AllowlistId;
|
|
17
|
+
readonly policyTag: SealPolicyTag;
|
|
18
|
+
readonly nonce: Uint8Array;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build an allowlist-policy Seal identity. The nonce must be at least 1 byte
|
|
22
|
+
* (the Move contract's `id.length() > 33` invariant); nonces of 16 random
|
|
23
|
+
* bytes are typical.
|
|
24
|
+
*
|
|
25
|
+
* @throws {ValidationError} If `allowlistId` is not a 0x-prefixed 64-char
|
|
26
|
+
* hex string, or `nonce` is shorter than 1 byte.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildAllowlistSealId(allowlistId: AllowlistId, nonce: Uint8Array): SealId;
|
|
29
|
+
/**
|
|
30
|
+
* Decode the structural fields of an allowlist Seal identity. The brand
|
|
31
|
+
* guarantees the byte layout, so this never throws on a properly-built
|
|
32
|
+
* identity. Throws `ValidationError` if the bytes carry a different policy
|
|
33
|
+
* tag (e.g. publisher) — use `decodePublisherSealId` for those.
|
|
34
|
+
*/
|
|
35
|
+
export declare function decodeAllowlistSealId(id: SealId): AllowlistSealIdParts;
|
|
36
|
+
//# sourceMappingURL=allowlist-identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allowlist-identity.d.ts","sourceRoot":"","sources":["../../src/seal/allowlist-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAO3E,qDAAqD;AACrD,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CACnC,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,UAAU,GACf,MAAM,CAaR;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,oBAAoB,CAetE"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seal identity (`SealId`) construction and inspection for the allowlist policy.
|
|
3
|
+
* The Move layer (`allowlist::seal_approve`) enforces the byte format, so both
|
|
4
|
+
* encode and decode here must match the contract byte-for-byte.
|
|
5
|
+
*
|
|
6
|
+
* Layout: `allowlist_id(32) || policy_tag(u8=2) || nonce(>=1)`. Total length
|
|
7
|
+
* must be > 33 bytes (`allowlist::ESealInvalidId` otherwise).
|
|
8
|
+
*
|
|
9
|
+
* Distinct from the publisher policy (`publisher-identity.ts`) by policy tag
|
|
10
|
+
* (allowlist=2, publisher=1) so both can coexist in the same package without
|
|
11
|
+
* identity collisions.
|
|
12
|
+
*/
|
|
13
|
+
import { ValidationError } from "../errors.js";
|
|
14
|
+
import { SealPolicyTag } from "../types.js";
|
|
15
|
+
const ALLOWLIST_ID_BYTES = 32;
|
|
16
|
+
const POLICY_TAG_OFFSET = ALLOWLIST_ID_BYTES;
|
|
17
|
+
const NONCE_OFFSET = POLICY_TAG_OFFSET + 1;
|
|
18
|
+
const MIN_NONCE_BYTES = 1;
|
|
19
|
+
/**
|
|
20
|
+
* Build an allowlist-policy Seal identity. The nonce must be at least 1 byte
|
|
21
|
+
* (the Move contract's `id.length() > 33` invariant); nonces of 16 random
|
|
22
|
+
* bytes are typical.
|
|
23
|
+
*
|
|
24
|
+
* @throws {ValidationError} If `allowlistId` is not a 0x-prefixed 64-char
|
|
25
|
+
* hex string, or `nonce` is shorter than 1 byte.
|
|
26
|
+
*/
|
|
27
|
+
export function buildAllowlistSealId(allowlistId, nonce) {
|
|
28
|
+
if (nonce.length < MIN_NONCE_BYTES) {
|
|
29
|
+
throw new ValidationError(`Seal nonce must be at least ${MIN_NONCE_BYTES} byte(s), got ${nonce.length}`, "nonce");
|
|
30
|
+
}
|
|
31
|
+
const prefix = allowlistIdToBytes(allowlistId);
|
|
32
|
+
const out = new Uint8Array(ALLOWLIST_ID_BYTES + 1 + nonce.length);
|
|
33
|
+
out.set(prefix, 0);
|
|
34
|
+
out[POLICY_TAG_OFFSET] = SealPolicyTag.Allowlist;
|
|
35
|
+
out.set(nonce, NONCE_OFFSET);
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Decode the structural fields of an allowlist Seal identity. The brand
|
|
40
|
+
* guarantees the byte layout, so this never throws on a properly-built
|
|
41
|
+
* identity. Throws `ValidationError` if the bytes carry a different policy
|
|
42
|
+
* tag (e.g. publisher) — use `decodePublisherSealId` for those.
|
|
43
|
+
*/
|
|
44
|
+
export function decodeAllowlistSealId(id) {
|
|
45
|
+
const prefix = id.subarray(0, ALLOWLIST_ID_BYTES);
|
|
46
|
+
const policyTagByte = id[POLICY_TAG_OFFSET] ?? 0;
|
|
47
|
+
if (policyTagByte !== SealPolicyTag.Allowlist) {
|
|
48
|
+
throw new ValidationError(`Seal identity has policy tag ${policyTagByte}, expected ${SealPolicyTag.Allowlist} (Allowlist). Use decodePublisherSealId for publisher-policy identities.`, "policyTag");
|
|
49
|
+
}
|
|
50
|
+
const nonce = id.slice(NONCE_OFFSET);
|
|
51
|
+
return {
|
|
52
|
+
allowlistId: bytesToAllowlistId(prefix),
|
|
53
|
+
policyTag: SealPolicyTag.Allowlist,
|
|
54
|
+
nonce,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function allowlistIdToBytes(value) {
|
|
58
|
+
const stripped = value.startsWith("0x")
|
|
59
|
+
? value.slice(2)
|
|
60
|
+
: value;
|
|
61
|
+
if (stripped.length > ALLOWLIST_ID_BYTES * 2) {
|
|
62
|
+
throw new ValidationError(`AllowlistId exceeds ${ALLOWLIST_ID_BYTES} bytes`, "allowlistId");
|
|
63
|
+
}
|
|
64
|
+
const padded = stripped.padStart(ALLOWLIST_ID_BYTES * 2, "0");
|
|
65
|
+
if (!/^[0-9a-f]+$/i.test(padded)) {
|
|
66
|
+
throw new ValidationError(`AllowlistId is not valid hex: ${value}`, "allowlistId");
|
|
67
|
+
}
|
|
68
|
+
const out = new Uint8Array(ALLOWLIST_ID_BYTES);
|
|
69
|
+
for (let i = 0; i < ALLOWLIST_ID_BYTES; i += 1) {
|
|
70
|
+
out[i] = Number.parseInt(padded.slice(i * 2, i * 2 + 2), 16);
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
function bytesToAllowlistId(bytes) {
|
|
75
|
+
let hex = "";
|
|
76
|
+
for (const byte of bytes) {
|
|
77
|
+
hex += byte.toString(16).padStart(2, "0");
|
|
78
|
+
}
|
|
79
|
+
return `0x${hex}`;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=allowlist-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allowlist-identity.js","sourceRoot":"","sources":["../../src/seal/allowlist-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAiC,aAAa,EAAE,MAAM,aAAa,CAAC;AAE3E,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC7C,MAAM,YAAY,GAAG,iBAAiB,GAAG,CAAC,CAAC;AAC3C,MAAM,eAAe,GAAG,CAAC,CAAC;AAS1B;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CACnC,WAAwB,EACxB,KAAiB;IAEjB,IAAI,KAAK,CAAC,MAAM,G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
11
|
-
import type { SealAdapter, SealDecryptOptions, SealEncryptOptions, SealEncryptResult } from "./adapter.js";
|
|
11
|
+
import type { SealAdapter, SealDecryptOptions, SealDecryptUnderAllowlistOptions, SealEncryptOptions, SealEncryptResult } from "./adapter.js";
|
|
12
12
|
/**
|
|
13
13
|
* Configuration for `DefaultSealAdapter`. `packageId` MUST be the deployment's
|
|
14
14
|
* `originalPackageId`: Seal binds the package address into ciphertext
|
|
@@ -17,6 +17,17 @@ import type { SealAdapter, SealDecryptOptions, SealEncryptOptions, SealEncryptRe
|
|
|
17
17
|
*/
|
|
18
18
|
export interface SealAdapterConfig {
|
|
19
19
|
readonly packageId: PackageId;
|
|
20
|
+
/**
|
|
21
|
+
* Package id used as the target of `seal_approve*` PTBs. Defaults to
|
|
22
|
+
* `packageId` when omitted. Must be set explicitly when the seal_approve
|
|
23
|
+
* function lives in a module added in a package upgrade (e.g.
|
|
24
|
+
* `allowlist::seal_approve` was introduced in v2 and only exists at the
|
|
25
|
+
* v2 published-at address; calling it at the original-id fails because
|
|
26
|
+
* that address only has v1 bytecode). For backwards compat with the
|
|
27
|
+
* publisher policy (introduced in v1, present at all upgrade addresses),
|
|
28
|
+
* omit this field.
|
|
29
|
+
*/
|
|
30
|
+
readonly targetPackageId?: PackageId;
|
|
20
31
|
readonly serverConfigs: readonly KeyServerConfig[];
|
|
21
32
|
readonly threshold: number;
|
|
22
33
|
readonly verifyKeyServers?: boolean;
|
|
@@ -44,6 +55,7 @@ interface DefaultSealAdapterOptions {
|
|
|
44
55
|
readonly client: SealClientLike;
|
|
45
56
|
readonly suiClient: SealCompatibleClient;
|
|
46
57
|
readonly packageId: PackageId;
|
|
58
|
+
readonly targetPackageId: PackageId;
|
|
47
59
|
readonly threshold: number;
|
|
48
60
|
}
|
|
49
61
|
/** `SealAdapter` implementation backed by `@mysten/seal`. */
|
|
@@ -51,6 +63,7 @@ export declare class DefaultSealAdapter implements SealAdapter {
|
|
|
51
63
|
private readonly client;
|
|
52
64
|
private readonly suiClient;
|
|
53
65
|
private readonly packageId;
|
|
66
|
+
private readonly targetPackageId;
|
|
54
67
|
private readonly threshold;
|
|
55
68
|
constructor(options: DefaultSealAdapterOptions);
|
|
56
69
|
/**
|
|
@@ -84,7 +97,9 @@ export declare class DefaultSealAdapter implements SealAdapter {
|
|
|
84
97
|
static fromConfig(config: SealAdapterConfig, suiClient: SealCompatibleClient): DefaultSealAdapter;
|
|
85
98
|
encrypt(plaintext: Uint8Array, options: SealEncryptOptions): Promise<SealEncryptResult>;
|
|
86
99
|
decrypt(ciphertext: Uint8Array, options: SealDecryptOptions): Promise<Uint8Array>;
|
|
100
|
+
decryptUnderAllowlist(ciphertext: Uint8Array, options: SealDecryptUnderAllowlistOptions): Promise<Uint8Array>;
|
|
87
101
|
private buildSealApproveTxBytes;
|
|
102
|
+
private buildAllowlistApproveTxBytes;
|
|
88
103
|
}
|
|
89
104
|
export {};
|
|
90
105
|
//# sourceMappingURL=default-adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-adapter.d.ts","sourceRoot":"","sources":["../../src/seal/default-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAIN,KAAK,eAAe,EAGpB,KAAK,oBAAoB,EACzB,KAAK,UAAU,EAEf,MAAM,cAAc,CAAC;AAUtB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"default-adapter.d.ts","sourceRoot":"","sources":["../../src/seal/default-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAIN,KAAK,eAAe,EAGpB,KAAK,oBAAoB,EACzB,KAAK,UAAU,EAEf,MAAM,cAAc,CAAC;AAUtB,OAAO,KAAK,EAEX,SAAS,EAIT,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACX,WAAW,EACX,kBAAkB,EAClB,gCAAgC,EAChC,kBAAkB,EAClB,iBAAiB,EACjB,MAAM,cAAc,CAAC;AAItB;;;;;GAKG;AAC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,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAY;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEvB,OAAO,EAAE,yBAAyB;IAQ9C;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,eAAe,CACrB,WAAW,EAAE;QACZ,SAAS,EAAE,SAAS,CAAC;QACrB,iBAAiB,CAAC,EAAE,SAAS,CAAC;QAC9B,cAAc,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;KAC5C,EACD,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC,EACnD,SAAS,EAAE,oBAAoB,GAC7B,kBAAkB;IAiCrB;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAChB,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,oBAAoB,GAC7B,kBAAkB;IAkCf,OAAO,CACZ,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,kBAAkB,GACzB,OAAO,CAAC,iBAAiB,CAAC;IAgBvB,OAAO,CACZ,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,kBAAkB,GACzB,OAAO,CAAC,UAAU,CAAC;IAkChB,qBAAqB,CAC1B,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,gCAAgC,GACvC,OAAO,CAAC,UAAU,CAAC;YAmCR,uBAAuB;YA6BvB,4BAA4B;CA0B1C"}
|
|
@@ -9,17 +9,20 @@
|
|
|
9
9
|
import { DecryptionError, ExpiredSessionKeyError, InvalidCiphertextError, NoAccessError, SealClient, TooManyFailedFetchKeyRequestsError, } from "@mysten/seal";
|
|
10
10
|
import { Transaction } from "@mysten/sui/transactions";
|
|
11
11
|
import { ConfigurationError, SealError, TransportError, ValidationError, } from "../errors.js";
|
|
12
|
+
import { decodeAllowlistSealId } from "./allowlist-identity.js";
|
|
12
13
|
import { decodePublisherSealId } from "./identity.js";
|
|
13
14
|
/** `SealAdapter` implementation backed by `@mysten/seal`. */
|
|
14
15
|
export class DefaultSealAdapter {
|
|
15
16
|
client;
|
|
16
17
|
suiClient;
|
|
17
18
|
packageId;
|
|
19
|
+
targetPackageId;
|
|
18
20
|
threshold;
|
|
19
21
|
constructor(options) {
|
|
20
22
|
this.client = options.client;
|
|
21
23
|
this.suiClient = options.suiClient;
|
|
22
24
|
this.packageId = options.packageId;
|
|
25
|
+
this.targetPackageId = options.targetPackageId;
|
|
23
26
|
this.threshold = options.threshold;
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
@@ -47,7 +50,17 @@ export class DefaultSealAdapter {
|
|
|
47
50
|
}
|
|
48
51
|
const threshold = seal.threshold ?? Math.min(2, serverConfigs.length);
|
|
49
52
|
return DefaultSealAdapter.fromConfig({
|
|
53
|
+
// Identity binding uses the original-id for crypto stability across
|
|
54
|
+
// upgrades. Ciphertexts encrypted under v1's package id remain
|
|
55
|
+
// decryptable after v2 / v3 upgrades.
|
|
50
56
|
packageId: morseConfig.originalPackageId ?? morseConfig.packageId,
|
|
57
|
+
// PTB targets use the current published-at because seal_approve
|
|
58
|
+
// functions in modules added by upgrades (e.g. allowlist) only
|
|
59
|
+
// exist at the current address. The publisher-policy
|
|
60
|
+
// seal_approve_publisher (defined in v1) is reachable at either
|
|
61
|
+
// the original-id or the current id; using the current id is
|
|
62
|
+
// safe for both cases.
|
|
63
|
+
targetPackageId: morseConfig.packageId,
|
|
51
64
|
serverConfigs,
|
|
52
65
|
threshold,
|
|
53
66
|
...(seal.verifyKeyServers === undefined
|
|
@@ -82,6 +95,7 @@ export class DefaultSealAdapter {
|
|
|
82
95
|
client,
|
|
83
96
|
suiClient,
|
|
84
97
|
packageId: config.packageId,
|
|
98
|
+
targetPackageId: config.targetPackageId ?? config.packageId,
|
|
85
99
|
threshold: config.threshold,
|
|
86
100
|
});
|
|
87
101
|
}
|
|
@@ -117,10 +131,28 @@ export class DefaultSealAdapter {
|
|
|
117
131
|
txBytes,
|
|
118
132
|
}), "seal.decrypt");
|
|
119
133
|
}
|
|
134
|
+
async decryptUnderAllowlist(ciphertext, options) {
|
|
135
|
+
let allowlistIdFromSealId;
|
|
136
|
+
try {
|
|
137
|
+
({ allowlistId: allowlistIdFromSealId } = decodeAllowlistSealId(options.sealId));
|
|
138
|
+
}
|
|
139
|
+
catch (cause) {
|
|
140
|
+
throw new SealError("decrypt-failed", `Seal identity is malformed or uses an unsupported policy tag for the allowlist policy: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
141
|
+
}
|
|
142
|
+
if (allowlistIdFromSealId !== options.allowlistId) {
|
|
143
|
+
throw new SealError("decrypt-failed", `sealId's embedded allowlistId (${allowlistIdFromSealId}) does not match the supplied allowlistId (${options.allowlistId})`);
|
|
144
|
+
}
|
|
145
|
+
const txBytes = await this.buildAllowlistApproveTxBytes(options.allowlistId, options.sealId, options.sessionKey);
|
|
146
|
+
return runSealCall(() => this.client.decrypt({
|
|
147
|
+
data: ciphertext,
|
|
148
|
+
sessionKey: options.sessionKey,
|
|
149
|
+
txBytes,
|
|
150
|
+
}), "seal.decryptUnderAllowlist");
|
|
151
|
+
}
|
|
120
152
|
async buildSealApproveTxBytes(publicationId, publisherCapId, sealId, sessionKey) {
|
|
121
153
|
const tx = new Transaction();
|
|
122
154
|
tx.moveCall({
|
|
123
|
-
target: `${this.
|
|
155
|
+
target: `${this.targetPackageId}::publication::seal_approve_publisher`,
|
|
124
156
|
arguments: [
|
|
125
157
|
tx.pure.vector("u8", Array.from(sealId)),
|
|
126
158
|
tx.object(publicationId),
|
|
@@ -141,6 +173,29 @@ export class DefaultSealAdapter {
|
|
|
141
173
|
});
|
|
142
174
|
}
|
|
143
175
|
}
|
|
176
|
+
async buildAllowlistApproveTxBytes(allowlistId, sealId, sessionKey) {
|
|
177
|
+
const tx = new Transaction();
|
|
178
|
+
tx.moveCall({
|
|
179
|
+
target: `${this.targetPackageId}::allowlist::seal_approve`,
|
|
180
|
+
arguments: [
|
|
181
|
+
tx.pure.vector("u8", Array.from(sealId)),
|
|
182
|
+
tx.object(allowlistId),
|
|
183
|
+
],
|
|
184
|
+
});
|
|
185
|
+
tx.setSender(sessionKey.getAddress());
|
|
186
|
+
try {
|
|
187
|
+
return await tx.build({
|
|
188
|
+
client: this.suiClient,
|
|
189
|
+
onlyTransactionKind: true,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
catch (cause) {
|
|
193
|
+
throw new TransportError("Failed to build allowlist seal_approve PTB", {
|
|
194
|
+
cause,
|
|
195
|
+
operation: "seal.buildAllowlistApproveTx",
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
144
199
|
}
|
|
145
200
|
async function runSealCall(call, operation = "seal.call") {
|
|
146
201
|
try {
|