@mysten/seal 0.1.0 → 0.3.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 +12 -0
- package/dist/cjs/bcs.d.ts +132 -0
- package/dist/cjs/bcs.js +67 -0
- package/dist/cjs/bcs.js.map +7 -0
- package/dist/cjs/client.d.ts +83 -0
- package/dist/cjs/client.js +283 -0
- package/dist/cjs/client.js.map +7 -0
- package/dist/cjs/decrypt.d.ts +15 -0
- package/dist/cjs/decrypt.js +93 -0
- package/dist/cjs/decrypt.js.map +7 -0
- package/dist/cjs/dem.d.ts +36 -0
- package/dist/cjs/dem.js +173 -0
- package/dist/cjs/dem.js.map +7 -0
- package/dist/cjs/elgamal.js.map +2 -2
- package/dist/cjs/encrypt.d.ts +14 -5
- package/dist/cjs/encrypt.js +51 -21
- package/dist/cjs/encrypt.js.map +3 -3
- package/dist/cjs/error.d.ts +58 -0
- package/dist/cjs/error.js +175 -0
- package/dist/cjs/error.js.map +7 -0
- package/dist/cjs/ibe.d.ts +10 -14
- package/dist/cjs/ibe.js +23 -26
- package/dist/cjs/ibe.js.map +2 -2
- package/dist/cjs/index.d.ts +2 -5
- package/dist/cjs/index.js +3 -11
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/kdf.d.ts +5 -0
- package/dist/cjs/kdf.js +28 -1
- package/dist/cjs/kdf.js.map +3 -3
- package/dist/cjs/key-server.d.ts +5 -5
- package/dist/cjs/key-server.js +24 -21
- package/dist/cjs/key-server.js.map +2 -2
- package/dist/cjs/keys.d.ts +17 -0
- package/dist/cjs/keys.js +61 -0
- package/dist/cjs/keys.js.map +7 -0
- package/dist/cjs/session-key.d.ts +20 -14
- package/dist/cjs/session-key.js +90 -23
- package/dist/cjs/session-key.js.map +2 -2
- package/dist/cjs/types.d.ts +1 -86
- package/dist/cjs/types.js +0 -32
- package/dist/cjs/types.js.map +2 -2
- package/dist/cjs/utils.d.ts +2 -1
- package/dist/cjs/utils.js +17 -5
- package/dist/cjs/utils.js.map +2 -2
- package/dist/cjs/version.d.ts +1 -0
- package/dist/cjs/version.js +25 -0
- package/dist/cjs/version.js.map +7 -0
- package/dist/esm/bcs.d.ts +132 -0
- package/dist/esm/bcs.js +47 -0
- package/dist/esm/bcs.js.map +7 -0
- package/dist/esm/client.d.ts +83 -0
- package/dist/esm/client.js +268 -0
- package/dist/esm/client.js.map +7 -0
- package/dist/esm/decrypt.d.ts +15 -0
- package/dist/esm/decrypt.js +73 -0
- package/dist/esm/decrypt.js.map +7 -0
- package/dist/esm/dem.d.ts +36 -0
- package/dist/esm/dem.js +153 -0
- package/dist/esm/dem.js.map +7 -0
- package/dist/esm/elgamal.js.map +2 -2
- package/dist/esm/encrypt.d.ts +14 -5
- package/dist/esm/encrypt.js +48 -18
- package/dist/esm/encrypt.js.map +3 -3
- package/dist/esm/error.d.ts +58 -0
- package/dist/esm/error.js +155 -0
- package/dist/esm/error.js.map +7 -0
- package/dist/esm/ibe.d.ts +10 -14
- package/dist/esm/ibe.js +23 -26
- package/dist/esm/ibe.js.map +2 -2
- package/dist/esm/index.d.ts +2 -5
- package/dist/esm/index.js +4 -12
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/kdf.d.ts +5 -0
- package/dist/esm/kdf.js +28 -1
- package/dist/esm/kdf.js.map +3 -3
- package/dist/esm/key-server.d.ts +5 -5
- package/dist/esm/key-server.js +29 -21
- package/dist/esm/key-server.js.map +2 -2
- package/dist/esm/keys.d.ts +17 -0
- package/dist/esm/keys.js +41 -0
- package/dist/esm/keys.js.map +7 -0
- package/dist/esm/session-key.d.ts +20 -14
- package/dist/esm/session-key.js +95 -24
- package/dist/esm/session-key.js.map +2 -2
- package/dist/esm/types.d.ts +1 -86
- package/dist/esm/types.js +0 -28
- package/dist/esm/types.js.map +3 -3
- package/dist/esm/utils.d.ts +2 -1
- package/dist/esm/utils.js +17 -5
- package/dist/esm/utils.js.map +2 -2
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +5 -0
- package/dist/esm/version.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/dist/cjs/aes.d.ts +0 -18
- package/dist/cjs/aes.js +0 -111
- package/dist/cjs/aes.js.map +0 -7
- package/dist/cjs/key-store.d.ts +0 -49
- package/dist/cjs/key-store.js +0 -203
- package/dist/cjs/key-store.js.map +0 -7
- package/dist/esm/aes.d.ts +0 -18
- package/dist/esm/aes.js +0 -91
- package/dist/esm/aes.js.map +0 -7
- package/dist/esm/key-store.d.ts +0 -49
- package/dist/esm/key-store.js +0 -183
- package/dist/esm/key-store.js.map +0 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/key-server.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { fromBase64, fromHex
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { fromBase64, fromHex } from '@mysten/bcs';\nimport type { SuiClient } from '@mysten/sui/client';\nimport { bls12_381 } from '@noble/curves/bls12-381';\n\nimport { KeyServerMove } from './bcs.js';\nimport {\n\tInvalidGetObjectError,\n\tSealAPIError,\n\tUnsupportedFeatureError,\n\tUnsupportedNetworkError,\n} from './error.js';\nimport { DST_POP } from './ibe.js';\nimport { PACKAGE_VERSION } from './version.js';\n\nexport type KeyServer = {\n\tobjectId: string;\n\tname: string;\n\turl: string;\n\tkeyType: KeyServerType;\n\tpk: Uint8Array;\n};\n\nexport enum KeyServerType {\n\tBonehFranklinBLS12381 = 0,\n}\n\n/**\n * Returns a static list of Seal key server object ids that the dapp can choose to use.\n * @param network - The network to use.\n * @returns The object id's of the key servers.\n */\nexport function getAllowlistedKeyServers(network: 'testnet' | 'mainnet'): string[] {\n\tif (network === 'testnet') {\n\t\treturn [\n\t\t\t'0xb35a7228d8cf224ad1e828c0217c95a5153bafc2906d6f9c178197dce26fbcf8',\n\t\t\t'0x2d6cde8a9d9a65bde3b0a346566945a63b4bfb70e9a06c41bdb70807e2502b06',\n\t\t];\n\t} else {\n\t\tthrow new UnsupportedNetworkError(`Unsupported network ${network}`);\n\t}\n}\n\n/**\n * Given a list of key server object IDs, returns a list of SealKeyServer\n * from onchain state containing name, objectId, URL and pk.\n *\n * @param objectIds - The key server object IDs.\n * @param client - The SuiClient to use.\n * @returns - An array of SealKeyServer.\n */\nexport async function retrieveKeyServers({\n\tobjectIds,\n\tclient,\n}: {\n\tobjectIds: string[];\n\tclient: SuiClient;\n}): Promise<KeyServer[]> {\n\t// todo: do not fetch the same object ID if this is fetched before.\n\treturn await Promise.all(\n\t\tobjectIds.map(async (objectId) => {\n\t\t\tconst res = await client.getObject({\n\t\t\t\tid: objectId,\n\t\t\t\toptions: {\n\t\t\t\t\tshowBcs: true,\n\t\t\t\t},\n\t\t\t});\n\t\t\tif (!res || res.error || !res.data) {\n\t\t\t\tthrow new InvalidGetObjectError(`KeyServer ${objectId} not found; ${res.error}`);\n\t\t\t}\n\n\t\t\tif (!res.data.bcs || !('bcsBytes' in res.data.bcs)) {\n\t\t\t\tthrow new InvalidGetObjectError(\n\t\t\t\t\t`Invalid KeyServer query: ${objectId}, expected object, got package`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tlet ks = KeyServerMove.parse(fromBase64(res.data.bcs!.bcsBytes));\n\t\t\tif (ks.keyType !== 0) {\n\t\t\t\tthrow new UnsupportedFeatureError(`Unsupported key type ${ks.keyType}`);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tobjectId,\n\t\t\t\tname: ks.name,\n\t\t\t\turl: ks.url,\n\t\t\t\tkeyType: KeyServerType.BonehFranklinBLS12381,\n\t\t\t\tpk: new Uint8Array(ks.pk),\n\t\t\t};\n\t\t}),\n\t);\n}\n\n/**\n * Given a KeyServer, fetch the proof of possession (PoP) from the URL and verify it\n * against the pubkey. This should be used only rarely when the dapp uses a dynamic\n * set of key servers.\n *\n * @param server - The KeyServer to verify.\n * @returns - True if the key server is valid, false otherwise.\n */\nexport async function verifyKeyServer(server: KeyServer, timeout: number): Promise<boolean> {\n\tconst requestId = crypto.randomUUID();\n\tconst response = await fetch(server.url! + '/v1/service', {\n\t\tmethod: 'GET',\n\t\theaders: {\n\t\t\t'Content-Type': 'application/json',\n\t\t\t'Request-Id': requestId,\n\t\t\t'Client-Sdk-Type': 'typescript',\n\t\t\t'Client-Sdk-Version': PACKAGE_VERSION,\n\t\t},\n\t\tsignal: AbortSignal.timeout(timeout),\n\t});\n\n\tawait SealAPIError.assertResponse(response, requestId);\n\tconst serviceResponse = await response.json();\n\n\tif (serviceResponse.service_id !== server.objectId) {\n\t\treturn false;\n\t}\n\tconst fullMsg = new Uint8Array([...DST_POP, ...server.pk, ...fromHex(server.objectId)]);\n\treturn bls12_381.verifyShortSignature(fromBase64(serviceResponse.pop), fullMsg, server.pk);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAoC;AAEpC,uBAA0B;AAE1B,IAAAA,cAA8B;AAC9B,mBAKO;AACP,iBAAwB;AACxB,qBAAgC;AAUzB,IAAK,gBAAL,kBAAKC,mBAAL;AACN,EAAAA,8BAAA,2BAAwB,KAAxB;AADW,SAAAA;AAAA,GAAA;AASL,SAAS,yBAAyB,SAA0C;AAClF,MAAI,YAAY,WAAW;AAC1B,WAAO;AAAA,MACN;AAAA,MACA;AAAA,IACD;AAAA,EACD,OAAO;AACN,UAAM,IAAI,qCAAwB,uBAAuB,OAAO,EAAE;AAAA,EACnE;AACD;AAUA,eAAsB,mBAAmB;AAAA,EACxC;AAAA,EACA;AACD,GAGyB;AAExB,SAAO,MAAM,QAAQ;AAAA,IACpB,UAAU,IAAI,OAAO,aAAa;AACjC,YAAM,MAAM,MAAM,OAAO,UAAU;AAAA,QAClC,IAAI;AAAA,QACJ,SAAS;AAAA,UACR,SAAS;AAAA,QACV;AAAA,MACD,CAAC;AACD,UAAI,CAAC,OAAO,IAAI,SAAS,CAAC,IAAI,MAAM;AACnC,cAAM,IAAI,mCAAsB,aAAa,QAAQ,eAAe,IAAI,KAAK,EAAE;AAAA,MAChF;AAEA,UAAI,CAAC,IAAI,KAAK,OAAO,EAAE,cAAc,IAAI,KAAK,MAAM;AACnD,cAAM,IAAI;AAAA,UACT,4BAA4B,QAAQ;AAAA,QACrC;AAAA,MACD;AAEA,UAAI,KAAK,0BAAc,UAAM,uBAAW,IAAI,KAAK,IAAK,QAAQ,CAAC;AAC/D,UAAI,GAAG,YAAY,GAAG;AACrB,cAAM,IAAI,qCAAwB,wBAAwB,GAAG,OAAO,EAAE;AAAA,MACvE;AAEA,aAAO;AAAA,QACN;AAAA,QACA,MAAM,GAAG;AAAA,QACT,KAAK,GAAG;AAAA,QACR,SAAS;AAAA,QACT,IAAI,IAAI,WAAW,GAAG,EAAE;AAAA,MACzB;AAAA,IACD,CAAC;AAAA,EACF;AACD;AAUA,eAAsB,gBAAgB,QAAmB,SAAmC;AAC3F,QAAM,YAAY,OAAO,WAAW;AACpC,QAAM,WAAW,MAAM,MAAM,OAAO,MAAO,eAAe;AAAA,IACzD,QAAQ;AAAA,IACR,SAAS;AAAA,MACR,gBAAgB;AAAA,MAChB,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB,sBAAsB;AAAA,IACvB;AAAA,IACA,QAAQ,YAAY,QAAQ,OAAO;AAAA,EACpC,CAAC;AAED,QAAM,0BAAa,eAAe,UAAU,SAAS;AACrD,QAAM,kBAAkB,MAAM,SAAS,KAAK;AAE5C,MAAI,gBAAgB,eAAe,OAAO,UAAU;AACnD,WAAO;AAAA,EACR;AACA,QAAM,UAAU,IAAI,WAAW,CAAC,GAAG,oBAAS,GAAG,OAAO,IAAI,OAAG,oBAAQ,OAAO,QAAQ,CAAC,CAAC;AACtF,SAAO,2BAAU,yBAAqB,uBAAW,gBAAgB,GAAG,GAAG,SAAS,OAAO,EAAE;AAC1F;",
|
|
6
6
|
"names": ["import_bcs", "KeyServerType"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Certificate } from './session-key.js';
|
|
2
|
+
/**
|
|
3
|
+
* Helper function to request all keys from URL with requestSig, txBytes, ephemeral pubkey.
|
|
4
|
+
* Then decrypt the Seal key with ephemeral secret key. Returns a list decryption keys with
|
|
5
|
+
* their full IDs.
|
|
6
|
+
*
|
|
7
|
+
* @param url - The URL of the key server.
|
|
8
|
+
* @param requestSig - The Base64 string of request signature.
|
|
9
|
+
* @param txBytes - The transaction bytes.
|
|
10
|
+
* @param encKey - The ephemeral secret key.
|
|
11
|
+
* @param certificate - The certificate.
|
|
12
|
+
* @returns - A list of full ID and the decrypted key.
|
|
13
|
+
*/
|
|
14
|
+
export declare function fetchKeysForAllIds(url: string, requestSig: string, txBytes: Uint8Array, encKey: Uint8Array, certificate: Certificate, timeout: number, signal?: AbortSignal): Promise<{
|
|
15
|
+
fullId: string;
|
|
16
|
+
key: Uint8Array;
|
|
17
|
+
}[]>;
|
package/dist/cjs/keys.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var keys_exports = {};
|
|
20
|
+
__export(keys_exports, {
|
|
21
|
+
fetchKeysForAllIds: () => fetchKeysForAllIds
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(keys_exports);
|
|
24
|
+
var import_bcs = require("@mysten/bcs");
|
|
25
|
+
var import_elgamal = require("./elgamal.js");
|
|
26
|
+
var import_error = require("./error.js");
|
|
27
|
+
var import_version = require("./version.js");
|
|
28
|
+
async function fetchKeysForAllIds(url, requestSig, txBytes, encKey, certificate, timeout, signal) {
|
|
29
|
+
const encKeyPk = (0, import_elgamal.toPublicKey)(encKey);
|
|
30
|
+
const encVerificationKey = (0, import_elgamal.toVerificationKey)(encKey);
|
|
31
|
+
const body = {
|
|
32
|
+
ptb: (0, import_bcs.toBase64)(txBytes.slice(1)),
|
|
33
|
+
// removes the byte of the transaction type version
|
|
34
|
+
enc_key: (0, import_bcs.toBase64)(encKeyPk),
|
|
35
|
+
enc_verification_key: (0, import_bcs.toBase64)(encVerificationKey),
|
|
36
|
+
request_signature: requestSig,
|
|
37
|
+
// already b64
|
|
38
|
+
certificate
|
|
39
|
+
};
|
|
40
|
+
const timeoutSignal = AbortSignal.timeout(timeout);
|
|
41
|
+
const combinedSignal = signal ? AbortSignal.any([signal, timeoutSignal]) : timeoutSignal;
|
|
42
|
+
const requestId = crypto.randomUUID();
|
|
43
|
+
const response = await fetch(url + "/v1/fetch_key", {
|
|
44
|
+
method: "POST",
|
|
45
|
+
headers: {
|
|
46
|
+
"Content-Type": "application/json",
|
|
47
|
+
"Request-Id": requestId,
|
|
48
|
+
"Client-Sdk-Type": "typescript",
|
|
49
|
+
"Client-Sdk-Version": import_version.PACKAGE_VERSION
|
|
50
|
+
},
|
|
51
|
+
body: JSON.stringify(body),
|
|
52
|
+
signal: combinedSignal
|
|
53
|
+
});
|
|
54
|
+
await import_error.SealAPIError.assertResponse(response, requestId);
|
|
55
|
+
const resp = await response.json();
|
|
56
|
+
return resp.decryption_keys.map((dk) => ({
|
|
57
|
+
fullId: (0, import_bcs.toHex)(new Uint8Array(dk.id)),
|
|
58
|
+
key: (0, import_elgamal.elgamalDecrypt)(encKey, dk.encrypted_key.map(import_bcs.fromBase64))
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=keys.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/keys.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64, toHex } from '@mysten/bcs';\n\nimport { elgamalDecrypt, toPublicKey, toVerificationKey } from './elgamal.js';\nimport { SealAPIError } from './error.js';\nimport type { Certificate } from './session-key.js';\nimport { PACKAGE_VERSION } from './version.js';\n\n/**\n * Helper function to request all keys from URL with requestSig, txBytes, ephemeral pubkey.\n * Then decrypt the Seal key with ephemeral secret key. Returns a list decryption keys with\n * their full IDs.\n *\n * @param url - The URL of the key server.\n * @param requestSig - The Base64 string of request signature.\n * @param txBytes - The transaction bytes.\n * @param encKey - The ephemeral secret key.\n * @param certificate - The certificate.\n * @returns - A list of full ID and the decrypted key.\n */\nexport async function fetchKeysForAllIds(\n\turl: string,\n\trequestSig: string,\n\ttxBytes: Uint8Array,\n\tencKey: Uint8Array,\n\tcertificate: Certificate,\n\ttimeout: number,\n\tsignal?: AbortSignal,\n): Promise<{ fullId: string; key: Uint8Array }[]> {\n\tconst encKeyPk = toPublicKey(encKey);\n\tconst encVerificationKey = toVerificationKey(encKey);\n\tconst body = {\n\t\tptb: toBase64(txBytes.slice(1)), // removes the byte of the transaction type version\n\t\tenc_key: toBase64(encKeyPk),\n\t\tenc_verification_key: toBase64(encVerificationKey),\n\t\trequest_signature: requestSig, // already b64\n\t\tcertificate,\n\t};\n\n\tconst timeoutSignal = AbortSignal.timeout(timeout);\n\tconst combinedSignal = signal ? AbortSignal.any([signal, timeoutSignal]) : timeoutSignal;\n\n\tconst requestId = crypto.randomUUID();\n\tconst response = await fetch(url + '/v1/fetch_key', {\n\t\tmethod: 'POST',\n\t\theaders: {\n\t\t\t'Content-Type': 'application/json',\n\t\t\t'Request-Id': requestId,\n\t\t\t'Client-Sdk-Type': 'typescript',\n\t\t\t'Client-Sdk-Version': PACKAGE_VERSION,\n\t\t},\n\t\tbody: JSON.stringify(body),\n\t\tsignal: combinedSignal,\n\t});\n\tawait SealAPIError.assertResponse(response, requestId);\n\n\tconst resp = await response.json();\n\treturn resp.decryption_keys.map((dk: { id: Uint8Array; encrypted_key: [string, string] }) => ({\n\t\tfullId: toHex(new Uint8Array(dk.id)),\n\t\tkey: elgamalDecrypt(encKey, dk.encrypted_key.map(fromBase64) as [Uint8Array, Uint8Array]),\n\t}));\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA4C;AAE5C,qBAA+D;AAC/D,mBAA6B;AAE7B,qBAAgC;AAchC,eAAsB,mBACrB,KACA,YACA,SACA,QACA,aACA,SACA,QACiD;AACjD,QAAM,eAAW,4BAAY,MAAM;AACnC,QAAM,yBAAqB,kCAAkB,MAAM;AACnD,QAAM,OAAO;AAAA,IACZ,SAAK,qBAAS,QAAQ,MAAM,CAAC,CAAC;AAAA;AAAA,IAC9B,aAAS,qBAAS,QAAQ;AAAA,IAC1B,0BAAsB,qBAAS,kBAAkB;AAAA,IACjD,mBAAmB;AAAA;AAAA,IACnB;AAAA,EACD;AAEA,QAAM,gBAAgB,YAAY,QAAQ,OAAO;AACjD,QAAM,iBAAiB,SAAS,YAAY,IAAI,CAAC,QAAQ,aAAa,CAAC,IAAI;AAE3E,QAAM,YAAY,OAAO,WAAW;AACpC,QAAM,WAAW,MAAM,MAAM,MAAM,iBAAiB;AAAA,IACnD,QAAQ;AAAA,IACR,SAAS;AAAA,MACR,gBAAgB;AAAA,MAChB,cAAc;AAAA,MACd,mBAAmB;AAAA,MACnB,sBAAsB;AAAA,IACvB;AAAA,IACA,MAAM,KAAK,UAAU,IAAI;AAAA,IACzB,QAAQ;AAAA,EACT,CAAC;AACD,QAAM,0BAAa,eAAe,UAAU,SAAS;AAErD,QAAM,OAAO,MAAM,SAAS,KAAK;AACjC,SAAO,KAAK,gBAAgB,IAAI,CAAC,QAA6D;AAAA,IAC7F,YAAQ,kBAAM,IAAI,WAAW,GAAG,EAAE,CAAC;AAAA,IACnC,SAAK,+BAAe,QAAQ,GAAG,cAAc,IAAI,qBAAU,CAA6B;AAAA,EACzF,EAAE;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,36 +1,42 @@
|
|
|
1
|
+
import type { Signer } from '@mysten/sui/cryptography';
|
|
1
2
|
export declare const RequestFormat: import("@mysten/bcs").BcsType<{
|
|
2
3
|
ptb: number[];
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
encKey: number[];
|
|
5
|
+
encVerificationKey: number[];
|
|
5
6
|
}, {
|
|
6
7
|
ptb: Iterable<number> & {
|
|
7
8
|
length: number;
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
+
encKey: Iterable<number> & {
|
|
10
11
|
length: number;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
+
encVerificationKey: Iterable<number> & {
|
|
13
14
|
length: number;
|
|
14
15
|
};
|
|
15
16
|
}>;
|
|
16
17
|
export type Certificate = {
|
|
18
|
+
user: string;
|
|
17
19
|
session_vk: string;
|
|
18
20
|
creation_time: number;
|
|
19
21
|
ttl_min: number;
|
|
20
22
|
signature: string;
|
|
21
23
|
};
|
|
22
24
|
export declare class SessionKey {
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
#private;
|
|
26
|
+
constructor({ address, packageId, ttlMin, signer, }: {
|
|
27
|
+
address: string;
|
|
28
|
+
packageId: string;
|
|
29
|
+
ttlMin: number;
|
|
30
|
+
signer?: Signer;
|
|
31
|
+
});
|
|
32
|
+
isExpired(): boolean;
|
|
33
|
+
getAddress(): string;
|
|
34
|
+
getPackageId(): string;
|
|
29
35
|
getPersonalMessage(): Uint8Array;
|
|
30
|
-
setPersonalMessageSignature(personalMessageSignature: string): void
|
|
31
|
-
getCertificate(): Certificate
|
|
36
|
+
setPersonalMessageSignature(personalMessageSignature: string): Promise<void>;
|
|
37
|
+
getCertificate(): Promise<Certificate>;
|
|
32
38
|
createRequestParams(txBytes: Uint8Array): Promise<{
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
decryptionKey: Uint8Array;
|
|
40
|
+
requestSignature: string;
|
|
35
41
|
}>;
|
|
36
42
|
}
|
package/dist/cjs/session-key.js
CHANGED
|
@@ -3,6 +3,9 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
6
9
|
var __export = (target, all) => {
|
|
7
10
|
for (var name in all)
|
|
8
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,6 +19,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
19
|
return to;
|
|
17
20
|
};
|
|
18
21
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
19
26
|
var session_key_exports = {};
|
|
20
27
|
__export(session_key_exports, {
|
|
21
28
|
RequestFormat: () => RequestFormat,
|
|
@@ -24,50 +31,110 @@ __export(session_key_exports, {
|
|
|
24
31
|
module.exports = __toCommonJS(session_key_exports);
|
|
25
32
|
var import_bcs = require("@mysten/bcs");
|
|
26
33
|
var import_bcs2 = require("@mysten/sui/bcs");
|
|
34
|
+
var import_graphql = require("@mysten/sui/graphql");
|
|
27
35
|
var import_ed25519 = require("@mysten/sui/keypairs/ed25519");
|
|
36
|
+
var import_utils = require("@mysten/sui/utils");
|
|
37
|
+
var import_verify = require("@mysten/sui/verify");
|
|
28
38
|
var import_elgamal = require("./elgamal.js");
|
|
39
|
+
var import_error = require("./error.js");
|
|
40
|
+
var _address, _packageId, _creationTimeMs, _ttlMin, _sessionKey, _personalMessageSignature, _signer;
|
|
29
41
|
const RequestFormat = import_bcs2.bcs.struct("RequestFormat", {
|
|
30
42
|
ptb: import_bcs2.bcs.vector(import_bcs2.bcs.U8),
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
encKey: import_bcs2.bcs.vector(import_bcs2.bcs.U8),
|
|
44
|
+
encVerificationKey: import_bcs2.bcs.vector(import_bcs2.bcs.U8)
|
|
33
45
|
});
|
|
34
46
|
class SessionKey {
|
|
35
|
-
constructor(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
constructor({
|
|
48
|
+
address,
|
|
49
|
+
packageId,
|
|
50
|
+
ttlMin,
|
|
51
|
+
signer
|
|
52
|
+
}) {
|
|
53
|
+
__privateAdd(this, _address);
|
|
54
|
+
__privateAdd(this, _packageId);
|
|
55
|
+
__privateAdd(this, _creationTimeMs);
|
|
56
|
+
__privateAdd(this, _ttlMin);
|
|
57
|
+
__privateAdd(this, _sessionKey);
|
|
58
|
+
__privateAdd(this, _personalMessageSignature);
|
|
59
|
+
__privateAdd(this, _signer);
|
|
60
|
+
if (!(0, import_utils.isValidSuiObjectId)(packageId) || !(0, import_utils.isValidSuiAddress)(address)) {
|
|
61
|
+
throw new import_error.UserError(`Invalid package ID ${packageId} or address ${address}`);
|
|
62
|
+
}
|
|
63
|
+
if (ttlMin > 10 || ttlMin < 1) {
|
|
64
|
+
throw new import_error.UserError(`Invalid TTL ${ttlMin}, must be between 1 and 10`);
|
|
65
|
+
}
|
|
66
|
+
__privateSet(this, _address, address);
|
|
67
|
+
__privateSet(this, _packageId, packageId);
|
|
68
|
+
__privateSet(this, _creationTimeMs, Date.now());
|
|
69
|
+
__privateSet(this, _ttlMin, ttlMin);
|
|
70
|
+
__privateSet(this, _sessionKey, import_ed25519.Ed25519Keypair.generate());
|
|
71
|
+
__privateSet(this, _signer, signer);
|
|
72
|
+
}
|
|
73
|
+
isExpired() {
|
|
74
|
+
return __privateGet(this, _creationTimeMs) + __privateGet(this, _ttlMin) * 60 * 1e3 - 1e4 < Date.now();
|
|
75
|
+
}
|
|
76
|
+
getAddress() {
|
|
77
|
+
return __privateGet(this, _address);
|
|
78
|
+
}
|
|
79
|
+
getPackageId() {
|
|
80
|
+
return __privateGet(this, _packageId);
|
|
41
81
|
}
|
|
42
82
|
getPersonalMessage() {
|
|
43
|
-
const
|
|
83
|
+
const creationTimeUtc = new Date(__privateGet(this, _creationTimeMs)).toISOString().slice(0, 19).replace("T", " ") + " UTC";
|
|
84
|
+
const message = `Accessing keys of package ${__privateGet(this, _packageId)} for ${__privateGet(this, _ttlMin)} mins from ${creationTimeUtc}, session key ${(0, import_bcs.toBase64)(__privateGet(this, _sessionKey).getPublicKey().toRawBytes())}`;
|
|
44
85
|
return new TextEncoder().encode(message);
|
|
45
86
|
}
|
|
46
|
-
setPersonalMessageSignature(personalMessageSignature) {
|
|
47
|
-
|
|
87
|
+
async setPersonalMessageSignature(personalMessageSignature) {
|
|
88
|
+
try {
|
|
89
|
+
await (0, import_verify.verifyPersonalMessageSignature)(this.getPersonalMessage(), personalMessageSignature, {
|
|
90
|
+
address: __privateGet(this, _address),
|
|
91
|
+
client: new import_graphql.SuiGraphQLClient({
|
|
92
|
+
url: "https://sui-testnet.mystenlabs.com/graphql"
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
__privateSet(this, _personalMessageSignature, personalMessageSignature);
|
|
96
|
+
} catch (e) {
|
|
97
|
+
throw new import_error.InvalidPersonalMessageSignatureError("Not valid");
|
|
98
|
+
}
|
|
48
99
|
}
|
|
49
|
-
getCertificate() {
|
|
50
|
-
if (this
|
|
51
|
-
|
|
100
|
+
async getCertificate() {
|
|
101
|
+
if (!__privateGet(this, _personalMessageSignature)) {
|
|
102
|
+
if (__privateGet(this, _signer)) {
|
|
103
|
+
const { signature } = await __privateGet(this, _signer).signPersonalMessage(this.getPersonalMessage());
|
|
104
|
+
__privateSet(this, _personalMessageSignature, signature);
|
|
105
|
+
} else {
|
|
106
|
+
throw new import_error.InvalidPersonalMessageSignatureError("Personal message signature is not set");
|
|
107
|
+
}
|
|
52
108
|
}
|
|
53
109
|
return {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
110
|
+
user: __privateGet(this, _address),
|
|
111
|
+
session_vk: (0, import_bcs.toBase64)(__privateGet(this, _sessionKey).getPublicKey().toRawBytes()),
|
|
112
|
+
creation_time: __privateGet(this, _creationTimeMs),
|
|
113
|
+
ttl_min: __privateGet(this, _ttlMin),
|
|
114
|
+
signature: __privateGet(this, _personalMessageSignature)
|
|
58
115
|
};
|
|
59
116
|
}
|
|
60
117
|
async createRequestParams(txBytes) {
|
|
61
|
-
|
|
118
|
+
if (this.isExpired()) {
|
|
119
|
+
throw new import_error.ExpiredSessionKeyError();
|
|
120
|
+
}
|
|
121
|
+
const egSk = (0, import_elgamal.generateSecretKey)();
|
|
62
122
|
const msgToSign = RequestFormat.serialize({
|
|
63
123
|
ptb: txBytes.slice(1),
|
|
64
|
-
|
|
65
|
-
|
|
124
|
+
encKey: (0, import_elgamal.toPublicKey)(egSk),
|
|
125
|
+
encVerificationKey: (0, import_elgamal.toVerificationKey)(egSk)
|
|
66
126
|
}).toBytes();
|
|
67
127
|
return {
|
|
68
|
-
|
|
69
|
-
|
|
128
|
+
decryptionKey: egSk,
|
|
129
|
+
requestSignature: (0, import_bcs.toBase64)(await __privateGet(this, _sessionKey).sign(msgToSign))
|
|
70
130
|
};
|
|
71
131
|
}
|
|
72
132
|
}
|
|
133
|
+
_address = new WeakMap();
|
|
134
|
+
_packageId = new WeakMap();
|
|
135
|
+
_creationTimeMs = new WeakMap();
|
|
136
|
+
_ttlMin = new WeakMap();
|
|
137
|
+
_sessionKey = new WeakMap();
|
|
138
|
+
_personalMessageSignature = new WeakMap();
|
|
139
|
+
_signer = new WeakMap();
|
|
73
140
|
//# sourceMappingURL=session-key.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/session-key.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toBase64
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toBase64 } from '@mysten/bcs';\nimport { bcs } from '@mysten/sui/bcs';\nimport type { Signer } from '@mysten/sui/cryptography';\nimport { SuiGraphQLClient } from '@mysten/sui/graphql';\nimport { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';\nimport { isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui/utils';\nimport { verifyPersonalMessageSignature } from '@mysten/sui/verify';\n\nimport { generateSecretKey, toPublicKey, toVerificationKey } from './elgamal.js';\nimport {\n\tExpiredSessionKeyError,\n\tInvalidPersonalMessageSignatureError,\n\tUserError,\n} from './error.js';\n\nexport const RequestFormat = bcs.struct('RequestFormat', {\n\tptb: bcs.vector(bcs.U8),\n\tencKey: bcs.vector(bcs.U8),\n\tencVerificationKey: bcs.vector(bcs.U8),\n});\n\nexport type Certificate = {\n\tuser: string;\n\tsession_vk: string;\n\tcreation_time: number;\n\tttl_min: number;\n\tsignature: string;\n};\n\nexport class SessionKey {\n\t#address: string;\n\t#packageId: string;\n\t#creationTimeMs: number;\n\t#ttlMin: number;\n\t#sessionKey: Ed25519Keypair;\n\t#personalMessageSignature?: string;\n\t#signer?: Signer;\n\n\tconstructor({\n\t\taddress,\n\t\tpackageId,\n\t\tttlMin,\n\t\tsigner,\n\t}: {\n\t\taddress: string;\n\t\tpackageId: string;\n\t\tttlMin: number;\n\t\tsigner?: Signer;\n\t}) {\n\t\tif (!isValidSuiObjectId(packageId) || !isValidSuiAddress(address)) {\n\t\t\tthrow new UserError(`Invalid package ID ${packageId} or address ${address}`);\n\t\t}\n\t\tif (ttlMin > 10 || ttlMin < 1) {\n\t\t\tthrow new UserError(`Invalid TTL ${ttlMin}, must be between 1 and 10`);\n\t\t}\n\n\t\tthis.#address = address;\n\t\tthis.#packageId = packageId;\n\t\tthis.#creationTimeMs = Date.now();\n\t\tthis.#ttlMin = ttlMin;\n\t\tthis.#sessionKey = Ed25519Keypair.generate();\n\t\tthis.#signer = signer;\n\t}\n\n\tisExpired(): boolean {\n\t\t// Allow 10 seconds for clock skew\n\t\treturn this.#creationTimeMs + this.#ttlMin * 60 * 1000 - 10_000 < Date.now();\n\t}\n\n\tgetAddress(): string {\n\t\treturn this.#address;\n\t}\n\n\tgetPackageId(): string {\n\t\treturn this.#packageId;\n\t}\n\n\tgetPersonalMessage(): Uint8Array {\n\t\tconst creationTimeUtc =\n\t\t\tnew Date(this.#creationTimeMs).toISOString().slice(0, 19).replace('T', ' ') + ' UTC';\n\t\tconst message = `Accessing keys of package ${this.#packageId} for ${this.#ttlMin} mins from ${creationTimeUtc}, session key ${toBase64(this.#sessionKey.getPublicKey().toRawBytes())}`;\n\t\treturn new TextEncoder().encode(message);\n\t}\n\n\tasync setPersonalMessageSignature(personalMessageSignature: string) {\n\t\ttry {\n\t\t\t// TODO: Fix this to work with any network\n\t\t\tawait verifyPersonalMessageSignature(this.getPersonalMessage(), personalMessageSignature, {\n\t\t\t\taddress: this.#address,\n\t\t\t\tclient: new SuiGraphQLClient({\n\t\t\t\t\turl: 'https://sui-testnet.mystenlabs.com/graphql',\n\t\t\t\t}),\n\t\t\t});\n\t\t\tthis.#personalMessageSignature = personalMessageSignature;\n\t\t} catch (e) {\n\t\t\tthrow new InvalidPersonalMessageSignatureError('Not valid');\n\t\t}\n\t}\n\n\tasync getCertificate(): Promise<Certificate> {\n\t\tif (!this.#personalMessageSignature) {\n\t\t\tif (this.#signer) {\n\t\t\t\tconst { signature } = await this.#signer.signPersonalMessage(this.getPersonalMessage());\n\t\t\t\tthis.#personalMessageSignature = signature;\n\t\t\t} else {\n\t\t\t\tthrow new InvalidPersonalMessageSignatureError('Personal message signature is not set');\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tuser: this.#address,\n\t\t\tsession_vk: toBase64(this.#sessionKey.getPublicKey().toRawBytes()),\n\t\t\tcreation_time: this.#creationTimeMs,\n\t\t\tttl_min: this.#ttlMin,\n\t\t\tsignature: this.#personalMessageSignature,\n\t\t};\n\t}\n\n\tasync createRequestParams(\n\t\ttxBytes: Uint8Array,\n\t): Promise<{ decryptionKey: Uint8Array; requestSignature: string }> {\n\t\tif (this.isExpired()) {\n\t\t\tthrow new ExpiredSessionKeyError();\n\t\t}\n\t\tconst egSk = generateSecretKey();\n\t\tconst msgToSign = RequestFormat.serialize({\n\t\t\tptb: txBytes.slice(1),\n\t\t\tencKey: toPublicKey(egSk),\n\t\t\tencVerificationKey: toVerificationKey(egSk),\n\t\t}).toBytes();\n\t\treturn {\n\t\t\tdecryptionKey: egSk,\n\t\t\trequestSignature: toBase64(await this.#sessionKey.sign(msgToSign)),\n\t\t};\n\t}\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": ["import_bcs"]
|
|
7
7
|
}
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,86 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
BonehFranklinBLS12381: {
|
|
3
|
-
encapsulation: Uint8Array<ArrayBufferLike>;
|
|
4
|
-
shares: Uint8Array<ArrayBufferLike>[];
|
|
5
|
-
};
|
|
6
|
-
$kind: "BonehFranklinBLS12381";
|
|
7
|
-
}, {
|
|
8
|
-
BonehFranklinBLS12381: {
|
|
9
|
-
encapsulation: Iterable<number>;
|
|
10
|
-
shares: Iterable<Iterable<number>> & {
|
|
11
|
-
length: number;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
}>;
|
|
15
|
-
export type IBEEncryptionsType = typeof IBEEncryptions.$inferType;
|
|
16
|
-
export declare const Ciphertext: import("@mysten/sui/bcs").BcsType<import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
17
|
-
Aes256Gcm: {
|
|
18
|
-
blob: number[];
|
|
19
|
-
aad: number[] | null;
|
|
20
|
-
};
|
|
21
|
-
Plain: {};
|
|
22
|
-
}, "Aes256Gcm" | "Plain">, import("@mysten/bcs").EnumInputShape<{
|
|
23
|
-
Aes256Gcm: {
|
|
24
|
-
blob: Iterable<number> & {
|
|
25
|
-
length: number;
|
|
26
|
-
};
|
|
27
|
-
aad: (Iterable<number> & {
|
|
28
|
-
length: number;
|
|
29
|
-
}) | null | undefined;
|
|
30
|
-
};
|
|
31
|
-
Plain: {};
|
|
32
|
-
}>>;
|
|
33
|
-
export type CiphertextType = typeof Ciphertext.$inferInput;
|
|
34
|
-
/**
|
|
35
|
-
* The encrypted object format. Should be aligned with the Rust implementation.
|
|
36
|
-
*/
|
|
37
|
-
export declare const EncryptedObject: import("@mysten/sui/bcs").BcsType<{
|
|
38
|
-
version: number;
|
|
39
|
-
package_id: Uint8Array<ArrayBufferLike>;
|
|
40
|
-
id: number[];
|
|
41
|
-
services: [Uint8Array<ArrayBufferLike>, number][];
|
|
42
|
-
threshold: number;
|
|
43
|
-
encrypted_shares: {
|
|
44
|
-
BonehFranklinBLS12381: {
|
|
45
|
-
encapsulation: Uint8Array<ArrayBufferLike>;
|
|
46
|
-
shares: Uint8Array<ArrayBufferLike>[];
|
|
47
|
-
};
|
|
48
|
-
$kind: "BonehFranklinBLS12381";
|
|
49
|
-
};
|
|
50
|
-
ciphertext: import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
51
|
-
Aes256Gcm: {
|
|
52
|
-
blob: number[];
|
|
53
|
-
aad: number[] | null;
|
|
54
|
-
};
|
|
55
|
-
Plain: {};
|
|
56
|
-
}, "Aes256Gcm" | "Plain">;
|
|
57
|
-
}, {
|
|
58
|
-
version: number;
|
|
59
|
-
package_id: Iterable<number>;
|
|
60
|
-
id: Iterable<number> & {
|
|
61
|
-
length: number;
|
|
62
|
-
};
|
|
63
|
-
services: Iterable<readonly [Iterable<number>, number]> & {
|
|
64
|
-
length: number;
|
|
65
|
-
};
|
|
66
|
-
threshold: number;
|
|
67
|
-
encrypted_shares: {
|
|
68
|
-
BonehFranklinBLS12381: {
|
|
69
|
-
encapsulation: Iterable<number>;
|
|
70
|
-
shares: Iterable<Iterable<number>> & {
|
|
71
|
-
length: number;
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
ciphertext: import("@mysten/bcs").EnumInputShape<{
|
|
76
|
-
Aes256Gcm: {
|
|
77
|
-
blob: Iterable<number> & {
|
|
78
|
-
length: number;
|
|
79
|
-
};
|
|
80
|
-
aad: (Iterable<number> & {
|
|
81
|
-
length: number;
|
|
82
|
-
}) | null | undefined;
|
|
83
|
-
};
|
|
84
|
-
Plain: {};
|
|
85
|
-
}>;
|
|
86
|
-
}>;
|
|
1
|
+
export type KeyCacheKey = `${string}:${string}`;
|
package/dist/cjs/types.js
CHANGED
|
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
6
|
var __copyProps = (to, from, except, desc) => {
|
|
11
7
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
8
|
for (let key of __getOwnPropNames(from))
|
|
@@ -17,33 +13,5 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
13
|
};
|
|
18
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
15
|
var types_exports = {};
|
|
20
|
-
__export(types_exports, {
|
|
21
|
-
Ciphertext: () => Ciphertext,
|
|
22
|
-
EncryptedObject: () => EncryptedObject,
|
|
23
|
-
IBEEncryptions: () => IBEEncryptions
|
|
24
|
-
});
|
|
25
16
|
module.exports = __toCommonJS(types_exports);
|
|
26
|
-
var import_bcs = require("@mysten/sui/bcs");
|
|
27
|
-
const IBEEncryptions = import_bcs.bcs.enum("IBEEncryptions", {
|
|
28
|
-
BonehFranklinBLS12381: import_bcs.bcs.struct("BonehFranklinBLS12381", {
|
|
29
|
-
encapsulation: import_bcs.bcs.bytes(96),
|
|
30
|
-
shares: import_bcs.bcs.vector(import_bcs.bcs.bytes(32))
|
|
31
|
-
})
|
|
32
|
-
});
|
|
33
|
-
const Ciphertext = import_bcs.bcs.enum("Ciphertext", {
|
|
34
|
-
Aes256Gcm: import_bcs.bcs.struct("Aes256Gcm", {
|
|
35
|
-
blob: import_bcs.bcs.vector(import_bcs.bcs.U8),
|
|
36
|
-
aad: import_bcs.bcs.option(import_bcs.bcs.vector(import_bcs.bcs.U8))
|
|
37
|
-
}),
|
|
38
|
-
Plain: import_bcs.bcs.struct("Plain", {})
|
|
39
|
-
});
|
|
40
|
-
const EncryptedObject = import_bcs.bcs.struct("EncryptedObject", {
|
|
41
|
-
version: import_bcs.bcs.U8,
|
|
42
|
-
package_id: import_bcs.bcs.bytes(32),
|
|
43
|
-
id: import_bcs.bcs.vector(import_bcs.bcs.U8),
|
|
44
|
-
services: import_bcs.bcs.vector(import_bcs.bcs.tuple([import_bcs.bcs.bytes(32), import_bcs.bcs.U8])),
|
|
45
|
-
threshold: import_bcs.bcs.U8,
|
|
46
|
-
encrypted_shares: IBEEncryptions,
|
|
47
|
-
ciphertext: Ciphertext
|
|
48
|
-
});
|
|
49
17
|
//# sourceMappingURL=types.js.map
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport type KeyCacheKey = `${string}:${string}`;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare function xor(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
2
|
+
export declare function xorUnchecked(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
2
3
|
/**
|
|
3
4
|
* Create a full ID concatenating DST || package ID || inner ID.
|
|
4
5
|
* @param dst - The domain separation tag.
|
|
@@ -6,4 +7,4 @@ export declare function xor(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
|
6
7
|
* @param innerId - The inner ID.
|
|
7
8
|
* @returns The full ID.
|
|
8
9
|
*/
|
|
9
|
-
export declare function createFullId(dst: Uint8Array, packageId:
|
|
10
|
+
export declare function createFullId(dst: Uint8Array, packageId: string, innerId: string): string;
|
package/dist/cjs/utils.js
CHANGED
|
@@ -19,21 +19,33 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
21
|
createFullId: () => createFullId,
|
|
22
|
-
xor: () => xor
|
|
22
|
+
xor: () => xor,
|
|
23
|
+
xorUnchecked: () => xorUnchecked
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(utils_exports);
|
|
26
|
+
var import_bcs = require("@mysten/bcs");
|
|
27
|
+
var import_utils = require("@mysten/sui/utils");
|
|
28
|
+
var import_error = require("./error.js");
|
|
25
29
|
function xor(a, b) {
|
|
26
30
|
if (a.length !== b.length) {
|
|
27
31
|
throw new Error("Invalid input");
|
|
28
32
|
}
|
|
33
|
+
return xorUnchecked(a, b);
|
|
34
|
+
}
|
|
35
|
+
function xorUnchecked(a, b) {
|
|
29
36
|
return a.map((ai, i) => ai ^ b[i]);
|
|
30
37
|
}
|
|
31
38
|
function createFullId(dst, packageId, innerId) {
|
|
32
|
-
|
|
39
|
+
if (!(0, import_utils.isValidSuiObjectId)(packageId)) {
|
|
40
|
+
throw new import_error.UserError(`Invalid package ID ${packageId}`);
|
|
41
|
+
}
|
|
42
|
+
const packageIdBytes = (0, import_bcs.fromHex)(packageId);
|
|
43
|
+
const innerIdBytes = (0, import_bcs.fromHex)(innerId);
|
|
44
|
+
const fullId = new Uint8Array(1 + dst.length + packageIdBytes.length + innerIdBytes.length);
|
|
33
45
|
fullId.set([dst.length], 0);
|
|
34
46
|
fullId.set(dst, 1);
|
|
35
|
-
fullId.set(
|
|
36
|
-
fullId.set(
|
|
37
|
-
return fullId;
|
|
47
|
+
fullId.set(packageIdBytes, 1 + dst.length);
|
|
48
|
+
fullId.set(innerIdBytes, 1 + dst.length + packageIdBytes.length);
|
|
49
|
+
return (0, import_bcs.toHex)(fullId);
|
|
38
50
|
}
|
|
39
51
|
//# sourceMappingURL=utils.js.map
|
package/dist/cjs/utils.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport function xor(a: Uint8Array, b: Uint8Array): Uint8Array {\n\tif (a.length !== b.length) {\n\t\tthrow new Error('Invalid input');\n\t}\n\treturn a.map((ai, i) => ai ^ b[i]);\n}\n\n/**\n * Create a full ID concatenating DST || package ID || inner ID.\n * @param dst - The domain separation tag.\n * @param packageId - The package ID.\n * @param innerId - The inner ID.\n * @returns The full ID.\n */\nexport function createFullId(
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex, toHex } from '@mysten/bcs';\nimport { isValidSuiObjectId } from '@mysten/sui/utils';\n\nimport { UserError } from './error.js';\n\nexport function xor(a: Uint8Array, b: Uint8Array): Uint8Array {\n\tif (a.length !== b.length) {\n\t\tthrow new Error('Invalid input');\n\t}\n\treturn xorUnchecked(a, b);\n}\n\nexport function xorUnchecked(a: Uint8Array, b: Uint8Array): Uint8Array {\n\treturn a.map((ai, i) => ai ^ b[i]);\n}\n\n/**\n * Create a full ID concatenating DST || package ID || inner ID.\n * @param dst - The domain separation tag.\n * @param packageId - The package ID.\n * @param innerId - The inner ID.\n * @returns The full ID.\n */\nexport function createFullId(dst: Uint8Array, packageId: string, innerId: string): string {\n\tif (!isValidSuiObjectId(packageId)) {\n\t\tthrow new UserError(`Invalid package ID ${packageId}`);\n\t}\n\tconst packageIdBytes = fromHex(packageId);\n\tconst innerIdBytes = fromHex(innerId);\n\tconst fullId = new Uint8Array(1 + dst.length + packageIdBytes.length + innerIdBytes.length);\n\tfullId.set([dst.length], 0);\n\tfullId.set(dst, 1);\n\tfullId.set(packageIdBytes, 1 + dst.length);\n\tfullId.set(innerIdBytes, 1 + dst.length + packageIdBytes.length);\n\treturn toHex(fullId);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA+B;AAC/B,mBAAmC;AAEnC,mBAA0B;AAEnB,SAAS,IAAI,GAAe,GAA2B;AAC7D,MAAI,EAAE,WAAW,EAAE,QAAQ;AAC1B,UAAM,IAAI,MAAM,eAAe;AAAA,EAChC;AACA,SAAO,aAAa,GAAG,CAAC;AACzB;AAEO,SAAS,aAAa,GAAe,GAA2B;AACtE,SAAO,EAAE,IAAI,CAAC,IAAI,MAAM,KAAK,EAAE,CAAC,CAAC;AAClC;AASO,SAAS,aAAa,KAAiB,WAAmB,SAAyB;AACzF,MAAI,KAAC,iCAAmB,SAAS,GAAG;AACnC,UAAM,IAAI,uBAAU,sBAAsB,SAAS,EAAE;AAAA,EACtD;AACA,QAAM,qBAAiB,oBAAQ,SAAS;AACxC,QAAM,mBAAe,oBAAQ,OAAO;AACpC,QAAM,SAAS,IAAI,WAAW,IAAI,IAAI,SAAS,eAAe,SAAS,aAAa,MAAM;AAC1F,SAAO,IAAI,CAAC,IAAI,MAAM,GAAG,CAAC;AAC1B,SAAO,IAAI,KAAK,CAAC;AACjB,SAAO,IAAI,gBAAgB,IAAI,IAAI,MAAM;AACzC,SAAO,IAAI,cAAc,IAAI,IAAI,SAAS,eAAe,MAAM;AAC/D,aAAO,kBAAM,MAAM;AACpB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PACKAGE_VERSION = "0.3.0";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var version_exports = {};
|
|
20
|
+
__export(version_exports, {
|
|
21
|
+
PACKAGE_VERSION: () => PACKAGE_VERSION
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(version_exports);
|
|
24
|
+
const PACKAGE_VERSION = "0.3.0";
|
|
25
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/version.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '0.3.0';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,MAAM,kBAAkB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|