@arcadiasystems/morse-sdk 0.3.0 → 0.4.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 +78 -0
- package/dist/codecs.d.ts +3 -7
- package/dist/codecs.d.ts.map +1 -1
- package/dist/codecs.js +3 -11
- package/dist/codecs.js.map +1 -1
- package/dist/config.d.ts +9 -9
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +13 -10
- 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 +1 -2
- package/dist/errors.format.js.map +1 -1
- package/dist/errors.js +29 -27
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/ops/index.d.ts +2 -3
- package/dist/ops/index.d.ts.map +1 -1
- package/dist/ops/index.js +2 -3
- package/dist/ops/index.js.map +1 -1
- package/dist/ops/recipient-file-from-bytes.d.ts +123 -0
- package/dist/ops/recipient-file-from-bytes.d.ts.map +1 -0
- package/dist/ops/recipient-file-from-bytes.js +142 -0
- package/dist/ops/recipient-file-from-bytes.js.map +1 -0
- package/dist/ops/recipient-file.d.ts +114 -0
- package/dist/ops/recipient-file.d.ts.map +1 -0
- package/dist/ops/recipient-file.js +151 -0
- package/dist/ops/recipient-file.js.map +1 -0
- package/dist/ptb/recipient-file.d.ts +82 -0
- package/dist/ptb/recipient-file.d.ts.map +1 -0
- package/dist/ptb/recipient-file.js +148 -0
- package/dist/ptb/recipient-file.js.map +1 -0
- package/dist/read/index.d.ts +2 -2
- package/dist/read/index.d.ts.map +1 -1
- package/dist/read/index.js +2 -2
- package/dist/read/index.js.map +1 -1
- package/dist/read/recipient-file-events.d.ts +65 -0
- package/dist/read/recipient-file-events.d.ts.map +1 -0
- package/dist/read/recipient-file-events.js +172 -0
- package/dist/read/recipient-file-events.js.map +1 -0
- package/dist/read/recipient-files-reader.d.ts +27 -0
- package/dist/read/recipient-files-reader.d.ts.map +1 -0
- package/dist/read/recipient-files-reader.js +170 -0
- package/dist/read/recipient-files-reader.js.map +1 -0
- package/dist/seal/adapter.d.ts +20 -19
- package/dist/seal/adapter.d.ts.map +1 -1
- package/dist/seal/adapter.js +9 -3
- package/dist/seal/adapter.js.map +1 -1
- package/dist/seal/default-adapter.d.ts +5 -5
- package/dist/seal/default-adapter.d.ts.map +1 -1
- package/dist/seal/default-adapter.js +13 -22
- package/dist/seal/default-adapter.js.map +1 -1
- package/dist/seal/index.d.ts +2 -2
- package/dist/seal/index.d.ts.map +1 -1
- package/dist/seal/index.js +1 -1
- package/dist/seal/index.js.map +1 -1
- package/dist/seal/recipient-file-identity.d.ts +53 -0
- package/dist/seal/recipient-file-identity.d.ts.map +1 -0
- package/dist/seal/recipient-file-identity.js +87 -0
- package/dist/seal/recipient-file-identity.js.map +1 -0
- package/dist/types.d.ts +43 -59
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/wallets/keypair-adapter.d.ts.map +1 -1
- package/dist/wallets/keypair-adapter.js +1 -2
- package/dist/wallets/keypair-adapter.js.map +1 -1
- package/package.json +1 -1
- package/dist/ops/allowlist.d.ts +0 -79
- package/dist/ops/allowlist.d.ts.map +0 -1
- package/dist/ops/allowlist.js +0 -122
- package/dist/ops/allowlist.js.map +0 -1
- package/dist/ops/file-from-bytes.d.ts +0 -84
- package/dist/ops/file-from-bytes.d.ts.map +0 -1
- package/dist/ops/file-from-bytes.js +0 -133
- package/dist/ops/file-from-bytes.js.map +0 -1
- package/dist/ops/file.d.ts +0 -88
- package/dist/ops/file.d.ts.map +0 -1
- package/dist/ops/file.js +0 -142
- package/dist/ops/file.js.map +0 -1
- package/dist/ptb/allowlist.d.ts +0 -65
- package/dist/ptb/allowlist.d.ts.map +0 -1
- package/dist/ptb/allowlist.js +0 -75
- package/dist/ptb/allowlist.js.map +0 -1
- package/dist/ptb/file.d.ts +0 -58
- package/dist/ptb/file.d.ts.map +0 -1
- package/dist/ptb/file.js +0 -108
- package/dist/ptb/file.js.map +0 -1
- package/dist/read/files-events.d.ts +0 -87
- package/dist/read/files-events.d.ts.map +0 -1
- package/dist/read/files-events.js +0 -194
- package/dist/read/files-events.js.map +0 -1
- package/dist/read/files-reader.d.ts +0 -59
- package/dist/read/files-reader.d.ts.map +0 -1
- package/dist/read/files-reader.js +0 -247
- package/dist/read/files-reader.js.map +0 -1
- package/dist/seal/allowlist-identity.d.ts +0 -36
- package/dist/seal/allowlist-identity.d.ts.map +0 -1
- package/dist/seal/allowlist-identity.js +0 -81
- package/dist/seal/allowlist-identity.js.map +0 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live object read for `RecipientFile`. Parses the shared object's JSON
|
|
3
|
+
* representation into the typed `RecipientFile` record.
|
|
4
|
+
*
|
|
5
|
+
* RecipientFile was introduced in the v3 contract upgrade; both the type
|
|
6
|
+
* filter and the move-call target paths use `config.packageId` (current
|
|
7
|
+
* published-at), not `originalPackageId` (publication-modules genesis).
|
|
8
|
+
*/
|
|
9
|
+
import { toBlobObjectId, toRecipientFileId, toSuiAddress, toWalrusBlobId, } from "../codecs.js";
|
|
10
|
+
import { NotFoundError, TransportError, ValidationError } from "../errors.js";
|
|
11
|
+
/** RPC-backed implementation. */
|
|
12
|
+
export class RpcRecipientFilesReader {
|
|
13
|
+
client;
|
|
14
|
+
packageId;
|
|
15
|
+
constructor(client, packageId) {
|
|
16
|
+
this.client = client;
|
|
17
|
+
this.packageId = packageId;
|
|
18
|
+
}
|
|
19
|
+
static fromConfig(client, config) {
|
|
20
|
+
return new RpcRecipientFilesReader(client, config.packageId);
|
|
21
|
+
}
|
|
22
|
+
async getRecipientFile(id, signal) {
|
|
23
|
+
const validated = toRecipientFileId(id);
|
|
24
|
+
let response;
|
|
25
|
+
try {
|
|
26
|
+
response = await callClient("getObject", () => this.client.getObject({
|
|
27
|
+
objectId: validated,
|
|
28
|
+
include: { json: true },
|
|
29
|
+
...(signal === undefined ? {} : { signal }),
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (error instanceof TransportError &&
|
|
34
|
+
isObjectNotFoundError(error.cause, validated)) {
|
|
35
|
+
throw new NotFoundError("recipient-file", validated, {
|
|
36
|
+
cause: error.cause,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
const object = response.object;
|
|
42
|
+
if (!object) {
|
|
43
|
+
throw new NotFoundError("recipient-file", validated);
|
|
44
|
+
}
|
|
45
|
+
return parseRecipientFile(object, this.packageId);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function parseRecipientFile(object, _expectedPackageId) {
|
|
49
|
+
const json = object.json;
|
|
50
|
+
if (!json) {
|
|
51
|
+
throw new NotFoundError("recipient-file", object.objectId);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
id: toRecipientFileId(object.objectId),
|
|
55
|
+
owner: toSuiAddress(readString(json, "owner", "recipient_file.owner")),
|
|
56
|
+
blobId: parseWalrusBlobIdField(json.blob_id, "recipient_file.blob_id"),
|
|
57
|
+
blobObjectId: parseOptionalBlobObjectId(json.blob_object_id),
|
|
58
|
+
name: readString(json, "name", "recipient_file.name"),
|
|
59
|
+
contentType: readString(json, "content_type", "recipient_file.content_type"),
|
|
60
|
+
size: readSafeInteger(json, "size", "recipient_file.size"),
|
|
61
|
+
members: parseVecSetAddresses(json.members, "recipient_file.members"),
|
|
62
|
+
createdAtMs: readSafeInteger(json, "created_at_ms", "recipient_file.created_at_ms"),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The Move contract stores `blob_id` as `vector<u8>` (raw 32 bytes). Sui
|
|
67
|
+
* gRPC serializes byte vectors as either a base64 string OR a number array,
|
|
68
|
+
* depending on the codepath. Accept both and re-encode to the canonical
|
|
69
|
+
* 43-char URL-safe-base64 Walrus blob id.
|
|
70
|
+
*/
|
|
71
|
+
function parseWalrusBlobIdField(value, field) {
|
|
72
|
+
const bytes = parseByteVector(value, field);
|
|
73
|
+
if (bytes.length !== 32) {
|
|
74
|
+
throw new ValidationError(`Field ${field} must decode to 32 bytes, got ${bytes.length}`, field);
|
|
75
|
+
}
|
|
76
|
+
let binary = "";
|
|
77
|
+
for (const b of bytes)
|
|
78
|
+
binary += String.fromCharCode(b);
|
|
79
|
+
const standardBase64 = btoa(binary);
|
|
80
|
+
const urlSafe = standardBase64
|
|
81
|
+
.replace(/\+/g, "-")
|
|
82
|
+
.replace(/\//g, "_")
|
|
83
|
+
.replace(/=+$/, "");
|
|
84
|
+
return toWalrusBlobId(urlSafe);
|
|
85
|
+
}
|
|
86
|
+
function parseByteVector(value, field) {
|
|
87
|
+
if (typeof value === "string") {
|
|
88
|
+
const binary = atob(value);
|
|
89
|
+
const out = new Uint8Array(binary.length);
|
|
90
|
+
for (let i = 0; i < binary.length; i += 1)
|
|
91
|
+
out[i] = binary.charCodeAt(i);
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(value)) {
|
|
95
|
+
const out = new Uint8Array(value.length);
|
|
96
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
97
|
+
const n = typeof value[i] === "string" ? Number(value[i]) : value[i];
|
|
98
|
+
if (!Number.isInteger(n) || n < 0 || n > 255) {
|
|
99
|
+
throw new ValidationError(`Field ${field}[${i}] is not a valid u8`, field);
|
|
100
|
+
}
|
|
101
|
+
out[i] = n;
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
throw new ValidationError(`Field ${field} is missing or not a byte vector`, field);
|
|
106
|
+
}
|
|
107
|
+
function parseOptionalBlobObjectId(value) {
|
|
108
|
+
// `Option<ID>` JSON shape: { vec: [] } for none, { vec: ["0x..."] } for some.
|
|
109
|
+
if (value === null || value === undefined)
|
|
110
|
+
return null;
|
|
111
|
+
if (typeof value === "object" &&
|
|
112
|
+
"vec" in value) {
|
|
113
|
+
const vec = value.vec;
|
|
114
|
+
if (Array.isArray(vec) && vec.length === 0)
|
|
115
|
+
return null;
|
|
116
|
+
if (Array.isArray(vec) && vec.length === 1 && typeof vec[0] === "string") {
|
|
117
|
+
return toBlobObjectId(vec[0]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
throw new ValidationError(`Field recipient_file.blob_object_id has unexpected shape: ${JSON.stringify(value)}`, "recipient_file.blob_object_id");
|
|
121
|
+
}
|
|
122
|
+
function parseVecSetAddresses(value, field) {
|
|
123
|
+
// `VecSet<address>` JSON shape: { contents: ["0x...", "0x..."] }.
|
|
124
|
+
if (value === null || typeof value !== "object") {
|
|
125
|
+
throw new ValidationError(`Field ${field} is missing or not an object`, field);
|
|
126
|
+
}
|
|
127
|
+
const contents = value.contents;
|
|
128
|
+
if (!Array.isArray(contents)) {
|
|
129
|
+
throw new ValidationError(`Field ${field}.contents is not an array`, `${field}.contents`);
|
|
130
|
+
}
|
|
131
|
+
return contents.map((entry, index) => {
|
|
132
|
+
if (typeof entry !== "string") {
|
|
133
|
+
throw new ValidationError(`Field ${field}.contents[${index}] is not a string`, `${field}.contents[${index}]`);
|
|
134
|
+
}
|
|
135
|
+
return toSuiAddress(entry);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function readString(json, key, field) {
|
|
139
|
+
const value = json[key];
|
|
140
|
+
if (typeof value !== "string") {
|
|
141
|
+
throw new ValidationError(`Field ${field} is missing or not a string`, field);
|
|
142
|
+
}
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
function readSafeInteger(json, key, field) {
|
|
146
|
+
const raw = json[key];
|
|
147
|
+
const value = typeof raw === "string" ? Number(raw) : raw;
|
|
148
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
149
|
+
throw new ValidationError(`Field ${field} is not a non-negative safe integer: ${JSON.stringify(raw)}`, field);
|
|
150
|
+
}
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
async function callClient(operation, call) {
|
|
154
|
+
try {
|
|
155
|
+
return await call();
|
|
156
|
+
}
|
|
157
|
+
catch (cause) {
|
|
158
|
+
throw new TransportError(`${operation} failed`, {
|
|
159
|
+
cause,
|
|
160
|
+
operation: `sui.${operation}`,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function isObjectNotFoundError(cause, objectId) {
|
|
165
|
+
if (!(cause instanceof Error))
|
|
166
|
+
return false;
|
|
167
|
+
const escaped = objectId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
168
|
+
return new RegExp(`^Object ${escaped} not found(\\b|$)`).test(cause.message);
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=recipient-files-reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recipient-files-reader.js","sourceRoot":"","sources":["../../src/read/recipient-files-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EACN,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,cAAc,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAuB9E,iCAAiC;AACjC,MAAM,OAAO,uBAAuB;IAClB,MAAM,CAAe;IACrB,SAAS,CAAY;IAEtC,YAAoB,MAAoB,EAAE,SAAoB;QAC7D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,UAAU,CAChB,MAAoB,EACpB,MAAqC;QAErC,OAAO,IAAI,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,gBAAgB,CACrB,EAAmB,EACnB,MAAoB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AC;QAChB,MAAM,IAAI,cAAc,CAAC,GAAG,SAAS,SAAS,EAAE;YAC/C,KAAK;YACL,SAAS,EAAE,OAAO,SAAS,EAAE;SAC7B,CAAC,CAAC;IACJ,CAAC;AACF,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc,EAAE,QAAgB;IAC9D,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;IAChE,OAAO,IAAI,MAAM,CAAC,WAAW,OAAO,mBAAmB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC9E,CAAC"}
|
package/dist/seal/adapter.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Seal adapter interface: encrypt content under a
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Seal adapter interface: encrypt content under a Seal identity and decrypt
|
|
3
|
+
* with a consumer-supplied `SessionKey`. Configuration (key servers,
|
|
4
|
+
* threshold, package id) is bound at construction time.
|
|
5
|
+
*
|
|
6
|
+
* Two policies coexist on the same adapter:
|
|
7
|
+
* - Publisher policy (`decrypt`) gates content via a `PublisherCap` against
|
|
8
|
+
* a publication's revoked-cap denylist.
|
|
9
|
+
* - Recipient-file policy (`decryptUnderRecipientFile`) gates content via
|
|
10
|
+
* the per-file recipient set embedded on a `RecipientFile`.
|
|
5
11
|
*/
|
|
6
12
|
import type { SessionKey } from "@mysten/seal";
|
|
7
|
-
import type {
|
|
13
|
+
import type { PublisherCapId, RecipientFileId, SealId } from "../types.js";
|
|
8
14
|
export interface SealEncryptOptions {
|
|
9
15
|
readonly sealId: SealId;
|
|
10
16
|
/** Optional additional authenticated data bound into the ciphertext. */
|
|
@@ -22,11 +28,11 @@ export interface SealDecryptOptions {
|
|
|
22
28
|
readonly sealId: SealId;
|
|
23
29
|
readonly publisherCapId: PublisherCapId;
|
|
24
30
|
}
|
|
25
|
-
/** Options for decrypting content gated by the
|
|
26
|
-
export interface
|
|
31
|
+
/** Options for decrypting content gated by the recipient-file policy. */
|
|
32
|
+
export interface SealDecryptUnderRecipientFileOptions {
|
|
27
33
|
readonly sessionKey: SessionKey;
|
|
28
34
|
readonly sealId: SealId;
|
|
29
|
-
readonly
|
|
35
|
+
readonly fileId: RecipientFileId;
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
38
|
* Combined Seal adapter. Implementations bundle a `SealClient`, the morse
|
|
@@ -52,26 +58,21 @@ export interface SealAdapter {
|
|
|
52
58
|
* a revoked cap surfaces as `SealError("no-access")`.
|
|
53
59
|
*
|
|
54
60
|
* @throws {SealError} On Seal authorization failure (`no-access`),
|
|
55
|
-
* decryption failure (`decrypt-failed
|
|
56
|
-
* malformed), session-key expiry (`session-expired`), or rate
|
|
57
|
-
* limiting (`rate-limited`).
|
|
61
|
+
* decryption failure (`decrypt-failed`, also raised when `sealId` is
|
|
62
|
+
* malformed), session-key expiry (`session-expired`), or rate limiting.
|
|
58
63
|
* @throws {TransportError} On network or PTB build failure.
|
|
59
64
|
*/
|
|
60
65
|
decrypt(ciphertext: Uint8Array, options: SealDecryptOptions): Promise<Uint8Array>;
|
|
61
66
|
/**
|
|
62
|
-
* Decrypt content gated by the
|
|
63
|
-
* verify that `sessionKey.getAddress()` is a current
|
|
64
|
-
* by dry-running `
|
|
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.
|
|
67
|
+
* Decrypt content gated by the recipient-file policy. The Seal key
|
|
68
|
+
* servers verify that `sessionKey.getAddress()` is a current recipient
|
|
69
|
+
* of `fileId` by dry-running `recipient_file::seal_approve(sealId, file)`;
|
|
70
|
+
* non-recipients surface as `SealError("no-access")`.
|
|
70
71
|
*
|
|
71
72
|
* @throws {SealError} On Seal authorization failure (`no-access`),
|
|
72
73
|
* decryption failure (`decrypt-failed`), session-key expiry, or rate limiting.
|
|
73
74
|
* @throws {TransportError} On network or PTB build failure.
|
|
74
75
|
*/
|
|
75
|
-
|
|
76
|
+
decryptUnderRecipientFile(ciphertext: Uint8Array, options: SealDecryptUnderRecipientFileOptions): Promise<Uint8Array>;
|
|
76
77
|
}
|
|
77
78
|
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/seal/adapter.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/seal/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE3E,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,yEAAyE;AACzE,MAAM,WAAW,oCAAoC;IACpD,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;CACjC;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;;;;;;;;;;OAUG;IACH,OAAO,CACN,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,kBAAkB,GACzB,OAAO,CAAC,UAAU,CAAC,CAAC;IACvB;;;;;;;;;OASG;IACH,yBAAyB,CACxB,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,oCAAoC,GAC3C,OAAO,CAAC,UAAU,CAAC,CAAC;CACvB"}
|
package/dist/seal/adapter.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Seal adapter interface: encrypt content under a
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Seal adapter interface: encrypt content under a Seal identity and decrypt
|
|
3
|
+
* with a consumer-supplied `SessionKey`. Configuration (key servers,
|
|
4
|
+
* threshold, package id) is bound at construction time.
|
|
5
|
+
*
|
|
6
|
+
* Two policies coexist on the same adapter:
|
|
7
|
+
* - Publisher policy (`decrypt`) gates content via a `PublisherCap` against
|
|
8
|
+
* a publication's revoked-cap denylist.
|
|
9
|
+
* - Recipient-file policy (`decryptUnderRecipientFile`) gates content via
|
|
10
|
+
* the per-file recipient set embedded on a `RecipientFile`.
|
|
5
11
|
*/
|
|
6
12
|
export {};
|
|
7
13
|
//# sourceMappingURL=adapter.js.map
|
package/dist/seal/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/seal/adapter.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/seal/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { type KeyServerConfig, type SealCompatibleClient, type SessionKey } from "@mysten/seal";
|
|
10
10
|
import type { PackageId } from "../types.js";
|
|
11
|
-
import type { SealAdapter, SealDecryptOptions,
|
|
11
|
+
import type { SealAdapter, SealDecryptOptions, SealDecryptUnderRecipientFileOptions, 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
|
|
@@ -21,8 +21,8 @@ export interface SealAdapterConfig {
|
|
|
21
21
|
* Package id used as the target of `seal_approve*` PTBs. Defaults to
|
|
22
22
|
* `packageId` when omitted. Must be set explicitly when the seal_approve
|
|
23
23
|
* function lives in a module added in a package upgrade (e.g.
|
|
24
|
-
* `
|
|
25
|
-
*
|
|
24
|
+
* `recipient_file::seal_approve` was introduced in v3 and only exists at
|
|
25
|
+
* the v3 published-at address; calling it at the original-id fails because
|
|
26
26
|
* that address only has v1 bytecode). For backwards compat with the
|
|
27
27
|
* publisher policy (introduced in v1, present at all upgrade addresses),
|
|
28
28
|
* omit this field.
|
|
@@ -97,9 +97,9 @@ export declare class DefaultSealAdapter implements SealAdapter {
|
|
|
97
97
|
static fromConfig(config: SealAdapterConfig, suiClient: SealCompatibleClient): DefaultSealAdapter;
|
|
98
98
|
encrypt(plaintext: Uint8Array, options: SealEncryptOptions): Promise<SealEncryptResult>;
|
|
99
99
|
decrypt(ciphertext: Uint8Array, options: SealDecryptOptions): Promise<Uint8Array>;
|
|
100
|
-
|
|
100
|
+
decryptUnderRecipientFile(ciphertext: Uint8Array, options: SealDecryptUnderRecipientFileOptions): Promise<Uint8Array>;
|
|
101
101
|
private buildSealApproveTxBytes;
|
|
102
|
-
private
|
|
102
|
+
private buildRecipientFileApproveTxBytes;
|
|
103
103
|
}
|
|
104
104
|
export {};
|
|
105
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,EACX,SAAS,EAKT,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACX,WAAW,EACX,kBAAkB,EAClB,oCAAoC,EACpC,kBAAkB,EAClB,iBAAiB,EACjB,MAAM,cAAc,CAAC;AAGtB;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B;;;;;;;;;OASG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,CAAC;IACrC,QAAQ,CAAC,aAAa,EAAE,SAAS,eAAe,EAAE,CAAC;IACnD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,4EAA4E;AAC5E,UAAU,cAAc;IACvB,OAAO,CAAC,IAAI,EAAE;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,UAAU,CAAC;QACjB,GAAG,CAAC,EAAE,UAAU,CAAC;KACjB,GAAG,OAAO,CAAC;QAAE,eAAe,EAAE,UAAU,CAAC;QAAC,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AE,kBAAkB,GACzB,OAAO,CAAC,iBAAiB,CAAC;IAgBvB,OAAO,CACZ,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,kBAAkB,GACzB,OAAO,CAAC,UAAU,CAAC;IAkChB,yBAAyB,CAC9B,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,oCAAoC,GAC3C,OAAO,CAAC,UAAU,CAAC;YAsBR,uBAAuB;YA6BvB,gCAAgC;CA0B9C"}
|
|
@@ -9,7 +9,6 @@
|
|
|
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";
|
|
13
12
|
import { decodePublisherSealId } from "./identity.js";
|
|
14
13
|
/** `SealAdapter` implementation backed by `@mysten/seal`. */
|
|
15
14
|
export class DefaultSealAdapter {
|
|
@@ -131,23 +130,18 @@ export class DefaultSealAdapter {
|
|
|
131
130
|
txBytes,
|
|
132
131
|
}), "seal.decrypt");
|
|
133
132
|
}
|
|
134
|
-
async
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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);
|
|
133
|
+
async decryptUnderRecipientFile(ciphertext, options) {
|
|
134
|
+
// Unlike the publisher policy, the recipient-file seal identity is not
|
|
135
|
+
// self-validating client-side: the prefix is an opaque caller-chosen
|
|
136
|
+
// byte string bound to the file on chain via a dynamic field. The
|
|
137
|
+
// `seal_approve_with_prefix` PTB dry-run is the only authoritative
|
|
138
|
+
// check; we just forward the bytes and let Move (and Seal) verify.
|
|
139
|
+
const txBytes = await this.buildRecipientFileApproveTxBytes(options.fileId, options.sealId, options.sessionKey);
|
|
146
140
|
return runSealCall(() => this.client.decrypt({
|
|
147
141
|
data: ciphertext,
|
|
148
142
|
sessionKey: options.sessionKey,
|
|
149
143
|
txBytes,
|
|
150
|
-
}), "seal.
|
|
144
|
+
}), "seal.decryptUnderRecipientFile");
|
|
151
145
|
}
|
|
152
146
|
async buildSealApproveTxBytes(publicationId, publisherCapId, sealId, sessionKey) {
|
|
153
147
|
const tx = new Transaction();
|
|
@@ -173,14 +167,11 @@ export class DefaultSealAdapter {
|
|
|
173
167
|
});
|
|
174
168
|
}
|
|
175
169
|
}
|
|
176
|
-
async
|
|
170
|
+
async buildRecipientFileApproveTxBytes(fileId, sealId, sessionKey) {
|
|
177
171
|
const tx = new Transaction();
|
|
178
172
|
tx.moveCall({
|
|
179
|
-
target: `${this.targetPackageId}::
|
|
180
|
-
arguments: [
|
|
181
|
-
tx.pure.vector("u8", Array.from(sealId)),
|
|
182
|
-
tx.object(allowlistId),
|
|
183
|
-
],
|
|
173
|
+
target: `${this.targetPackageId}::recipient_file::seal_approve_with_prefix`,
|
|
174
|
+
arguments: [tx.pure.vector("u8", Array.from(sealId)), tx.object(fileId)],
|
|
184
175
|
});
|
|
185
176
|
tx.setSender(sessionKey.getAddress());
|
|
186
177
|
try {
|
|
@@ -190,9 +181,9 @@ export class DefaultSealAdapter {
|
|
|
190
181
|
});
|
|
191
182
|
}
|
|
192
183
|
catch (cause) {
|
|
193
|
-
throw new TransportError("Failed to build
|
|
184
|
+
throw new TransportError("Failed to build recipient_file seal_approve_with_prefix PTB", {
|
|
194
185
|
cause,
|
|
195
|
-
operation: "seal.
|
|
186
|
+
operation: "seal.buildRecipientFileApproveTx",
|
|
196
187
|
});
|
|
197
188
|
}
|
|
198
189
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-adapter.js","sourceRoot":"","sources":["../../src/seal/default-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACN,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EAEtB,aAAa,EACb,UAAU,EAGV,kCAAkC,GAClC,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACN,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,eAAe,GACf,MAAM,cAAc,CAAC;AAetB,OAAO,EAAE,qBAAqB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"default-adapter.js","sourceRoot":"","sources":["../../src/seal/default-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACN,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EAEtB,aAAa,EACb,UAAU,EAGV,kCAAkC,GAClC,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACN,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,eAAe,GACf,MAAM,cAAc,CAAC;AAetB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAmDtD,6DAA6D;AAC7D,MAAM,OAAO,kBAAkB;IACb,MAAM,CAAiB;IACvB,SAAS,CAAuB;IAChC,SAAS,CAAY;IACrB,eAAe,CAAY;IAC3B,SAAS,CAAS;IAEnC,YAAY,OAAkC;QAC7C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;QAC/C,IAAI,CAAC,SAAS,GAAG,OA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BAAuB,KAAK,CAAC,OAAO,EAAE,EAAE;YACzE,KAAK;SACL,CAAC,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,YAAY,sBAAsB,EAAE,CAAC;QAC7C,OAAO,IAAI,SAAS,CAAC,iBAAiB,EAAE,0BAA0B,EAAE;YACnE,KAAK;SACL,CAAC,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,YAAY,kCAAkC,EAAE,CAAC;QACzD,OAAO,IAAI,SAAS,CACnB,cAAc,EACd,6CAA6C,EAC7C,EAAE,KAAK,EAAE,CACT,CAAC;IACH,CAAC;IACD,IACC,KAAK,YAAY,eAAe;QAChC,KAAK,YAAY,sBAAsB,EACtC,CAAC;QACF,OAAO,IAAI,SAAS,CACnB,gBAAgB,EAChB,2BAA2B,KAAK,CAAC,OAAO,EAAE,EAC1C,EAAE,KAAK,EAAE,CACT,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACvC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC5B,OAAO,qBAAqB,KAAK,CAAC,OAAO,EAAE,CAAC;IAC7C,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC3B,CAAC;AAED,SAAS,UAAU,CAAC,KAAiB;IACpC,IAAI,GAAG,GAAG,IAAI,CAAC;IACf,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
package/dist/seal/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Seal subpackage barrel: identity construction, the adapter interface, and
|
|
3
3
|
* the default adapter wrapping `@mysten/seal`.
|
|
4
4
|
*/
|
|
5
|
-
export type { SealAdapter, SealDecryptOptions,
|
|
6
|
-
export { type AllowlistSealIdParts, buildAllowlistSealId, decodeAllowlistSealId, } from "./allowlist-identity.js";
|
|
5
|
+
export type { SealAdapter, SealDecryptOptions, SealDecryptUnderRecipientFileOptions, SealEncryptOptions, SealEncryptResult, } from "./adapter.js";
|
|
7
6
|
export { DefaultSealAdapter, type SealAdapterConfig, } from "./default-adapter.js";
|
|
8
7
|
export { buildPublisherSealId, decodePublisherSealId, type SealIdParts, } from "./identity.js";
|
|
8
|
+
export { buildRecipientFileSealId, decodeRecipientFileSealId, RECOMMENDED_SEAL_NONCE_BYTES, RECOMMENDED_SEAL_PREFIX_BYTES, type RecipientFileSealIdParts, randomSealNonce, randomSealPrefix, } from "./recipient-file-identity.js";
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/seal/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/seal/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EACX,WAAW,EACX,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/seal/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EACX,WAAW,EACX,kBAAkB,EAClB,oCAAoC,EACpC,kBAAkB,EAClB,iBAAiB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,kBAAkB,EAClB,KAAK,iBAAiB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,WAAW,GAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,wBAAwB,EACxB,yBAAyB,EACzB,4BAA4B,EAC5B,6BAA6B,EAC7B,KAAK,wBAAwB,EAC7B,eAAe,EACf,gBAAgB,GAChB,MAAM,8BAA8B,CAAC"}
|
package/dist/seal/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Seal subpackage barrel: identity construction, the adapter interface, and
|
|
3
3
|
* the default adapter wrapping `@mysten/seal`.
|
|
4
4
|
*/
|
|
5
|
-
export { buildAllowlistSealId, decodeAllowlistSealId, } from "./allowlist-identity.js";
|
|
6
5
|
export { DefaultSealAdapter, } from "./default-adapter.js";
|
|
7
6
|
export { buildPublisherSealId, decodePublisherSealId, } from "./identity.js";
|
|
7
|
+
export { buildRecipientFileSealId, decodeRecipientFileSealId, RECOMMENDED_SEAL_NONCE_BYTES, RECOMMENDED_SEAL_PREFIX_BYTES, randomSealNonce, randomSealPrefix, } from "./recipient-file-identity.js";
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
package/dist/seal/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/seal/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/seal/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EACN,kBAAkB,GAElB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,oBAAoB,EACpB,qBAAqB,GAErB,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,wBAAwB,EACxB,yBAAyB,EACzB,4BAA4B,EAC5B,6BAA6B,EAE7B,eAAe,EACf,gBAAgB,GAChB,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seal identity (`SealId`) construction and inspection for the recipient-file
|
|
3
|
+
* policy. The Move layer (`recipient_file::seal_approve_with_prefix`) enforces
|
|
4
|
+
* the byte format against a caller-supplied prefix stored on the file as a
|
|
5
|
+
* dynamic field, so the prefix bytes used at encrypt time and the bytes
|
|
6
|
+
* bound on chain at file creation must match exactly.
|
|
7
|
+
*
|
|
8
|
+
* Layout: `seal_id_prefix(>=1) || policy_tag(u8=3) || nonce(>=1)`. Both the
|
|
9
|
+
* prefix and the nonce must be at least 1 byte (Move contract's
|
|
10
|
+
* `id.length() > prefix_len + 1` invariant); 32 random prefix bytes + 16
|
|
11
|
+
* random nonce bytes is the recommended default.
|
|
12
|
+
*
|
|
13
|
+
* The prefix is no longer derived from the file's Sui object id (that scheme
|
|
14
|
+
* required knowing the id before signing the transaction that creates it, an
|
|
15
|
+
* impossible ordering for single-PTB encrypted upload). Callers pick a fresh
|
|
16
|
+
* random prefix per file; the file is created with the prefix attached.
|
|
17
|
+
*/
|
|
18
|
+
import { type SealId, SealPolicyTag } from "../types.js";
|
|
19
|
+
/** Recommended prefix length: 32 random bytes. Long enough to collision-avoid across files. */
|
|
20
|
+
export declare const RECOMMENDED_SEAL_PREFIX_BYTES = 32;
|
|
21
|
+
/** Recommended nonce length: 16 random bytes. Distinct envelopes per encrypt. */
|
|
22
|
+
export declare const RECOMMENDED_SEAL_NONCE_BYTES = 16;
|
|
23
|
+
/** Structured view of a recipient-file Seal identity built around a custom prefix. */
|
|
24
|
+
export interface RecipientFileSealIdParts {
|
|
25
|
+
readonly prefix: Uint8Array;
|
|
26
|
+
readonly policyTag: SealPolicyTag;
|
|
27
|
+
readonly nonce: Uint8Array;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build a recipient-file Seal identity. The prefix is the bytes the on-chain
|
|
31
|
+
* file must carry (attached via `new_recipient_file_with_seal_prefix`); the
|
|
32
|
+
* nonce is per-encryption.
|
|
33
|
+
*
|
|
34
|
+
* @throws {ValidationError} If `prefix` or `nonce` is empty.
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildRecipientFileSealId(prefix: Uint8Array, nonce: Uint8Array): SealId;
|
|
37
|
+
/**
|
|
38
|
+
* Decode a recipient-file Seal identity into prefix + tag + nonce. Requires
|
|
39
|
+
* the caller to provide `prefixLength` because the layout is not
|
|
40
|
+
* self-delimiting (the prefix is arbitrary-length). Throws `ValidationError`
|
|
41
|
+
* if the bytes carry a different policy tag or the length is insufficient.
|
|
42
|
+
*/
|
|
43
|
+
export declare function decodeRecipientFileSealId(id: SealId, prefixLength: number): RecipientFileSealIdParts;
|
|
44
|
+
/**
|
|
45
|
+
* Convenience: 32 random bytes suitable for `buildRecipientFileSealId`'s
|
|
46
|
+
* `prefix` argument. Uses Web Crypto; throws on environments without
|
|
47
|
+
* `crypto.getRandomValues`. The same value must be passed to
|
|
48
|
+
* `new_recipient_file_with_seal_prefix` so the on-chain prefix matches.
|
|
49
|
+
*/
|
|
50
|
+
export declare function randomSealPrefix(): Uint8Array;
|
|
51
|
+
/** Convenience: 16 random bytes suitable for `buildRecipientFileSealId`'s `nonce` argument. */
|
|
52
|
+
export declare function randomSealNonce(): Uint8Array;
|
|
53
|
+
//# sourceMappingURL=recipient-file-identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recipient-file-identity.d.ts","sourceRoot":"","sources":["../../src/seal/recipient-file-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,KAAK,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAKzD,+FAA+F;AAC/F,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAChD,iFAAiF;AACjF,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAE/C,sFAAsF;AACtF,MAAM,WAAW,wBAAwB;IACxC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACvC,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,UAAU,GACf,MAAM,CAkBR;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACxC,EAAE,EAAE,MAAM,EACV,YAAY,EAAE,MAAM,GAClB,wBAAwB,CAyB1B;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,UAAU,CAI7C;AAED,+FAA+F;AAC/F,wBAAgB,eAAe,IAAI,UAAU,CAI5C"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seal identity (`SealId`) construction and inspection for the recipient-file
|
|
3
|
+
* policy. The Move layer (`recipient_file::seal_approve_with_prefix`) enforces
|
|
4
|
+
* the byte format against a caller-supplied prefix stored on the file as a
|
|
5
|
+
* dynamic field, so the prefix bytes used at encrypt time and the bytes
|
|
6
|
+
* bound on chain at file creation must match exactly.
|
|
7
|
+
*
|
|
8
|
+
* Layout: `seal_id_prefix(>=1) || policy_tag(u8=3) || nonce(>=1)`. Both the
|
|
9
|
+
* prefix and the nonce must be at least 1 byte (Move contract's
|
|
10
|
+
* `id.length() > prefix_len + 1` invariant); 32 random prefix bytes + 16
|
|
11
|
+
* random nonce bytes is the recommended default.
|
|
12
|
+
*
|
|
13
|
+
* The prefix is no longer derived from the file's Sui object id (that scheme
|
|
14
|
+
* required knowing the id before signing the transaction that creates it, an
|
|
15
|
+
* impossible ordering for single-PTB encrypted upload). Callers pick a fresh
|
|
16
|
+
* random prefix per file; the file is created with the prefix attached.
|
|
17
|
+
*/
|
|
18
|
+
import { ValidationError } from "../errors.js";
|
|
19
|
+
import { SealPolicyTag } from "../types.js";
|
|
20
|
+
const POLICY_TAG_BYTES = 1;
|
|
21
|
+
const MIN_PREFIX_BYTES = 1;
|
|
22
|
+
const MIN_NONCE_BYTES = 1;
|
|
23
|
+
/** Recommended prefix length: 32 random bytes. Long enough to collision-avoid across files. */
|
|
24
|
+
export const RECOMMENDED_SEAL_PREFIX_BYTES = 32;
|
|
25
|
+
/** Recommended nonce length: 16 random bytes. Distinct envelopes per encrypt. */
|
|
26
|
+
export const RECOMMENDED_SEAL_NONCE_BYTES = 16;
|
|
27
|
+
/**
|
|
28
|
+
* Build a recipient-file Seal identity. The prefix is the bytes the on-chain
|
|
29
|
+
* file must carry (attached via `new_recipient_file_with_seal_prefix`); the
|
|
30
|
+
* nonce is per-encryption.
|
|
31
|
+
*
|
|
32
|
+
* @throws {ValidationError} If `prefix` or `nonce` is empty.
|
|
33
|
+
*/
|
|
34
|
+
export function buildRecipientFileSealId(prefix, nonce) {
|
|
35
|
+
if (prefix.length < MIN_PREFIX_BYTES) {
|
|
36
|
+
throw new ValidationError(`Seal prefix must be at least ${MIN_PREFIX_BYTES} byte(s), got ${prefix.length}`, "prefix");
|
|
37
|
+
}
|
|
38
|
+
if (nonce.length < MIN_NONCE_BYTES) {
|
|
39
|
+
throw new ValidationError(`Seal nonce must be at least ${MIN_NONCE_BYTES} byte(s), got ${nonce.length}`, "nonce");
|
|
40
|
+
}
|
|
41
|
+
const out = new Uint8Array(prefix.length + POLICY_TAG_BYTES + nonce.length);
|
|
42
|
+
out.set(prefix, 0);
|
|
43
|
+
out[prefix.length] = SealPolicyTag.RecipientFile;
|
|
44
|
+
out.set(nonce, prefix.length + POLICY_TAG_BYTES);
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Decode a recipient-file Seal identity into prefix + tag + nonce. Requires
|
|
49
|
+
* the caller to provide `prefixLength` because the layout is not
|
|
50
|
+
* self-delimiting (the prefix is arbitrary-length). Throws `ValidationError`
|
|
51
|
+
* if the bytes carry a different policy tag or the length is insufficient.
|
|
52
|
+
*/
|
|
53
|
+
export function decodeRecipientFileSealId(id, prefixLength) {
|
|
54
|
+
if (prefixLength < MIN_PREFIX_BYTES) {
|
|
55
|
+
throw new ValidationError(`prefixLength must be at least ${MIN_PREFIX_BYTES}, got ${prefixLength}`, "prefixLength");
|
|
56
|
+
}
|
|
57
|
+
if (id.length < prefixLength + POLICY_TAG_BYTES + MIN_NONCE_BYTES) {
|
|
58
|
+
throw new ValidationError(`Seal identity is shorter than prefix(${prefixLength}) + tag(1) + nonce(>=1)`, "id");
|
|
59
|
+
}
|
|
60
|
+
const tagByte = id[prefixLength] ?? 0;
|
|
61
|
+
if (tagByte !== SealPolicyTag.RecipientFile) {
|
|
62
|
+
throw new ValidationError(`Seal identity has policy tag ${tagByte}, expected ${SealPolicyTag.RecipientFile} (RecipientFile). Use decodePublisherSealId for publisher-policy identities.`, "policyTag");
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
prefix: id.slice(0, prefixLength),
|
|
66
|
+
policyTag: SealPolicyTag.RecipientFile,
|
|
67
|
+
nonce: id.slice(prefixLength + POLICY_TAG_BYTES),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Convenience: 32 random bytes suitable for `buildRecipientFileSealId`'s
|
|
72
|
+
* `prefix` argument. Uses Web Crypto; throws on environments without
|
|
73
|
+
* `crypto.getRandomValues`. The same value must be passed to
|
|
74
|
+
* `new_recipient_file_with_seal_prefix` so the on-chain prefix matches.
|
|
75
|
+
*/
|
|
76
|
+
export function randomSealPrefix() {
|
|
77
|
+
const bytes = new Uint8Array(RECOMMENDED_SEAL_PREFIX_BYTES);
|
|
78
|
+
crypto.getRandomValues(bytes);
|
|
79
|
+
return bytes;
|
|
80
|
+
}
|
|
81
|
+
/** Convenience: 16 random bytes suitable for `buildRecipientFileSealId`'s `nonce` argument. */
|
|
82
|
+
export function randomSealNonce() {
|
|
83
|
+
const bytes = new Uint8Array(RECOMMENDED_SEAL_NONCE_BYTES);
|
|
84
|
+
crypto.getRandomValues(bytes);
|
|
85
|
+
return bytes;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=recipient-file-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recipient-file-identity.js","sourceRoot":"","sources":["../../src/seal/recipient-file-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAe,aAAa,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,gBAAgB,GAAG,CAAC,CAAC;AA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