@haneullabs/seal 0.1.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 +459 -0
- package/README.md +4 -0
- package/dist/cjs/bcs.d.ts +71 -0
- package/dist/cjs/bcs.js +74 -0
- package/dist/cjs/bcs.js.map +7 -0
- package/dist/cjs/bls12381.d.ts +44 -0
- package/dist/cjs/bls12381.js +151 -0
- package/dist/cjs/bls12381.js.map +7 -0
- package/dist/cjs/client.d.ts +84 -0
- package/dist/cjs/client.js +414 -0
- package/dist/cjs/client.js.map +7 -0
- package/dist/cjs/decrypt.d.ts +22 -0
- package/dist/cjs/decrypt.js +109 -0
- package/dist/cjs/decrypt.js.map +7 -0
- package/dist/cjs/dem.d.ts +38 -0
- package/dist/cjs/dem.js +185 -0
- package/dist/cjs/dem.js.map +7 -0
- package/dist/cjs/elgamal.d.ts +13 -0
- package/dist/cjs/elgamal.js +46 -0
- package/dist/cjs/elgamal.js.map +7 -0
- package/dist/cjs/encrypt.d.ts +32 -0
- package/dist/cjs/encrypt.js +104 -0
- package/dist/cjs/encrypt.js.map +7 -0
- package/dist/cjs/error.d.ts +86 -0
- package/dist/cjs/error.js +239 -0
- package/dist/cjs/error.js.map +7 -0
- package/dist/cjs/ibe.d.ts +98 -0
- package/dist/cjs/ibe.js +167 -0
- package/dist/cjs/ibe.js.map +7 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +33 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/kdf.d.ts +30 -0
- package/dist/cjs/kdf.js +97 -0
- package/dist/cjs/kdf.js.map +7 -0
- package/dist/cjs/key-server.d.ts +98 -0
- package/dist/cjs/key-server.js +171 -0
- package/dist/cjs/key-server.js.map +7 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/session-key.d.ts +74 -0
- package/dist/cjs/session-key.js +245 -0
- package/dist/cjs/session-key.js.map +7 -0
- package/dist/cjs/shamir.d.ts +91 -0
- package/dist/cjs/shamir.js +770 -0
- package/dist/cjs/shamir.js.map +7 -0
- package/dist/cjs/types.d.ts +83 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/cjs/utils.d.ts +47 -0
- package/dist/cjs/utils.js +106 -0
- package/dist/cjs/utils.js.map +7 -0
- 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 +71 -0
- package/dist/esm/bcs.js +54 -0
- package/dist/esm/bcs.js.map +7 -0
- package/dist/esm/bls12381.d.ts +44 -0
- package/dist/esm/bls12381.js +131 -0
- package/dist/esm/bls12381.js.map +7 -0
- package/dist/esm/client.d.ts +84 -0
- package/dist/esm/client.js +407 -0
- package/dist/esm/client.js.map +7 -0
- package/dist/esm/decrypt.d.ts +22 -0
- package/dist/esm/decrypt.js +94 -0
- package/dist/esm/decrypt.js.map +7 -0
- package/dist/esm/dem.d.ts +38 -0
- package/dist/esm/dem.js +165 -0
- package/dist/esm/dem.js.map +7 -0
- package/dist/esm/elgamal.d.ts +13 -0
- package/dist/esm/elgamal.js +26 -0
- package/dist/esm/elgamal.js.map +7 -0
- package/dist/esm/encrypt.d.ts +32 -0
- package/dist/esm/encrypt.js +84 -0
- package/dist/esm/encrypt.js.map +7 -0
- package/dist/esm/error.d.ts +86 -0
- package/dist/esm/error.js +219 -0
- package/dist/esm/error.js.map +7 -0
- package/dist/esm/ibe.d.ts +98 -0
- package/dist/esm/ibe.js +147 -0
- package/dist/esm/ibe.js.map +7 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/kdf.d.ts +30 -0
- package/dist/esm/kdf.js +83 -0
- package/dist/esm/kdf.js.map +7 -0
- package/dist/esm/key-server.d.ts +98 -0
- package/dist/esm/key-server.js +151 -0
- package/dist/esm/key-server.js.map +7 -0
- package/dist/esm/package.json +5 -0
- package/dist/esm/session-key.d.ts +74 -0
- package/dist/esm/session-key.js +230 -0
- package/dist/esm/session-key.js.map +7 -0
- package/dist/esm/shamir.d.ts +91 -0
- package/dist/esm/shamir.js +750 -0
- package/dist/esm/shamir.js.map +7 -0
- package/dist/esm/types.d.ts +83 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/esm/utils.d.ts +47 -0
- package/dist/esm/utils.js +86 -0
- package/dist/esm/utils.js.map +7 -0
- 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 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +58 -0
package/dist/esm/kdf.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { fromHex } from "@haneullabs/bcs";
|
|
2
|
+
import { sha3_256 } from "@noble/hashes/sha3";
|
|
3
|
+
import { G1Element } from "./bls12381.js";
|
|
4
|
+
import {
|
|
5
|
+
ENCRYPTED_SHARE_LENGTH,
|
|
6
|
+
flatten,
|
|
7
|
+
KEY_LENGTH,
|
|
8
|
+
MAX_U8,
|
|
9
|
+
HANEUL_ADDRESS_LENGTH
|
|
10
|
+
} from "./utils.js";
|
|
11
|
+
const DST = new TextEncoder().encode("SUI-SEAL-IBE-BLS12381-00");
|
|
12
|
+
const KDF_DST = new TextEncoder().encode("SUI-SEAL-IBE-BLS12381-H2-00");
|
|
13
|
+
const DERIVE_KEY_DST = new TextEncoder().encode("SUI-SEAL-IBE-BLS12381-H3-00");
|
|
14
|
+
function hashToG1(id) {
|
|
15
|
+
return G1Element.hashToCurve(flatten([DST, id]));
|
|
16
|
+
}
|
|
17
|
+
function kdf(element, nonce, id, objectId, index) {
|
|
18
|
+
if (!Number.isInteger(index) || index < 0 || index > MAX_U8) {
|
|
19
|
+
throw new Error(`Invalid index ${index}`);
|
|
20
|
+
}
|
|
21
|
+
const objectIdBytes = fromHex(objectId);
|
|
22
|
+
if (objectIdBytes.length !== HANEUL_ADDRESS_LENGTH) {
|
|
23
|
+
throw new Error(`Invalid object id ${objectId}`);
|
|
24
|
+
}
|
|
25
|
+
const hash = sha3_256.create();
|
|
26
|
+
hash.update(KDF_DST);
|
|
27
|
+
hash.update(element.toBytes());
|
|
28
|
+
hash.update(nonce.toBytes());
|
|
29
|
+
hash.update(hashToG1(id).toBytes());
|
|
30
|
+
hash.update(objectIdBytes);
|
|
31
|
+
hash.update(new Uint8Array([index]));
|
|
32
|
+
return hash.digest();
|
|
33
|
+
}
|
|
34
|
+
var KeyPurpose = /* @__PURE__ */ ((KeyPurpose2) => {
|
|
35
|
+
KeyPurpose2[KeyPurpose2["EncryptedRandomness"] = 0] = "EncryptedRandomness";
|
|
36
|
+
KeyPurpose2[KeyPurpose2["DEM"] = 1] = "DEM";
|
|
37
|
+
return KeyPurpose2;
|
|
38
|
+
})(KeyPurpose || {});
|
|
39
|
+
function tag(purpose) {
|
|
40
|
+
switch (purpose) {
|
|
41
|
+
case 0 /* EncryptedRandomness */:
|
|
42
|
+
return new Uint8Array([0]);
|
|
43
|
+
case 1 /* DEM */:
|
|
44
|
+
return new Uint8Array([1]);
|
|
45
|
+
default:
|
|
46
|
+
throw new Error(`Invalid key purpose ${purpose}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function deriveKey(purpose, baseKey, encryptedShares, threshold, keyServers) {
|
|
50
|
+
if (!Number.isInteger(threshold) || threshold <= 0 || threshold > MAX_U8) {
|
|
51
|
+
throw new Error(`Invalid threshold ${threshold}`);
|
|
52
|
+
}
|
|
53
|
+
if (encryptedShares.length !== keyServers.length) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Mismatched shares ${encryptedShares.length} and key servers ${keyServers.length}`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const keyServerBytes = keyServers.map((keyServer) => fromHex(keyServer));
|
|
59
|
+
if (keyServerBytes.some((keyServer) => keyServer.length !== HANEUL_ADDRESS_LENGTH)) {
|
|
60
|
+
throw new Error(`Invalid key servers ${keyServers}`);
|
|
61
|
+
}
|
|
62
|
+
if (encryptedShares.some((share) => share.length !== ENCRYPTED_SHARE_LENGTH)) {
|
|
63
|
+
throw new Error(`Invalid encrypted shares ${encryptedShares}`);
|
|
64
|
+
}
|
|
65
|
+
if (baseKey.length !== KEY_LENGTH) {
|
|
66
|
+
throw new Error(`Invalid base key ${baseKey}`);
|
|
67
|
+
}
|
|
68
|
+
const hash = sha3_256.create();
|
|
69
|
+
hash.update(DERIVE_KEY_DST);
|
|
70
|
+
hash.update(baseKey);
|
|
71
|
+
hash.update(tag(purpose));
|
|
72
|
+
hash.update(new Uint8Array([threshold]));
|
|
73
|
+
encryptedShares.forEach((share) => hash.update(share));
|
|
74
|
+
keyServerBytes.forEach((keyServer) => hash.update(keyServer));
|
|
75
|
+
return hash.digest();
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
KeyPurpose,
|
|
79
|
+
deriveKey,
|
|
80
|
+
hashToG1,
|
|
81
|
+
kdf
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=kdf.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/kdf.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex } from '@haneullabs/bcs';\nimport { sha3_256 } from '@noble/hashes/sha3';\n\nimport { G1Element } from './bls12381.js';\nimport type { G2Element, GTElement } from './bls12381.js';\nimport {\n\tENCRYPTED_SHARE_LENGTH,\n\tflatten,\n\tKEY_LENGTH,\n\tMAX_U8,\n\tHANEUL_ADDRESS_LENGTH,\n} from './utils.js';\n\n/**\n * The domain separation tag for the hash-to-group function.\n */\nconst DST: Uint8Array = new TextEncoder().encode('SUI-SEAL-IBE-BLS12381-00');\nconst KDF_DST = new TextEncoder().encode('SUI-SEAL-IBE-BLS12381-H2-00');\nconst DERIVE_KEY_DST = new TextEncoder().encode('SUI-SEAL-IBE-BLS12381-H3-00');\n\n/**\n * Hash an id to a G1Element.\n *\n * @param id The id to hash.\n * @returns The G1Element.\n */\nexport function hashToG1(id: Uint8Array): G1Element {\n\treturn G1Element.hashToCurve(flatten([DST, id]));\n}\n\n/**\n * The default key derivation function.\n *\n * @returns The derived key.\n */\nexport function kdf(\n\telement: GTElement,\n\tnonce: G2Element,\n\tid: Uint8Array,\n\tobjectId: string,\n\tindex: number,\n): Uint8Array {\n\tif (!Number.isInteger(index) || index < 0 || index > MAX_U8) {\n\t\tthrow new Error(`Invalid index ${index}`);\n\t}\n\tconst objectIdBytes = fromHex(objectId);\n\tif (objectIdBytes.length !== HANEUL_ADDRESS_LENGTH) {\n\t\tthrow new Error(`Invalid object id ${objectId}`);\n\t}\n\tconst hash = sha3_256.create();\n\thash.update(KDF_DST);\n\thash.update(element.toBytes());\n\thash.update(nonce.toBytes());\n\thash.update(hashToG1(id).toBytes());\n\thash.update(objectIdBytes);\n\thash.update(new Uint8Array([index])); // this is safe because index < 256.\n\treturn hash.digest();\n}\n\nexport enum KeyPurpose {\n\tEncryptedRandomness,\n\tDEM,\n}\n\nfunction tag(purpose: KeyPurpose): Uint8Array {\n\tswitch (purpose) {\n\t\tcase KeyPurpose.EncryptedRandomness:\n\t\t\treturn new Uint8Array([0]);\n\t\tcase KeyPurpose.DEM:\n\t\t\treturn new Uint8Array([1]);\n\t\tdefault:\n\t\t\tthrow new Error(`Invalid key purpose ${purpose}`);\n\t}\n}\n\n/**\n * Derive a key from a base key and a list of encrypted shares.\n *\n * @param purpose The purpose of the key.\n * @param baseKey The base key.\n * @param encryptedShares The encrypted shares.\n * @param threshold The threshold.\n * @param keyServers The object ids of the key servers.\n * @returns The derived key.\n */\nexport function deriveKey(\n\tpurpose: KeyPurpose,\n\tbaseKey: Uint8Array,\n\tencryptedShares: Uint8Array[],\n\tthreshold: number,\n\tkeyServers: string[],\n): Uint8Array {\n\tif (!Number.isInteger(threshold) || threshold <= 0 || threshold > MAX_U8) {\n\t\tthrow new Error(`Invalid threshold ${threshold}`);\n\t}\n\n\tif (encryptedShares.length !== keyServers.length) {\n\t\tthrow new Error(\n\t\t\t`Mismatched shares ${encryptedShares.length} and key servers ${keyServers.length}`,\n\t\t);\n\t}\n\tconst keyServerBytes = keyServers.map((keyServer) => fromHex(keyServer));\n\tif (keyServerBytes.some((keyServer) => keyServer.length !== HANEUL_ADDRESS_LENGTH)) {\n\t\tthrow new Error(`Invalid key servers ${keyServers}`);\n\t}\n\tif (encryptedShares.some((share) => share.length !== ENCRYPTED_SHARE_LENGTH)) {\n\t\tthrow new Error(`Invalid encrypted shares ${encryptedShares}`);\n\t}\n\n\tif (baseKey.length !== KEY_LENGTH) {\n\t\tthrow new Error(`Invalid base key ${baseKey}`);\n\t}\n\n\tconst hash = sha3_256.create();\n\thash.update(DERIVE_KEY_DST);\n\thash.update(baseKey);\n\thash.update(tag(purpose));\n\thash.update(new Uint8Array([threshold]));\n\tencryptedShares.forEach((share) => hash.update(share));\n\tkeyServerBytes.forEach((keyServer) => hash.update(keyServer));\n\treturn hash.digest();\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AAEzB,SAAS,iBAAiB;AAE1B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,MAAM,MAAkB,IAAI,YAAY,EAAE,OAAO,0BAA0B;AAC3E,MAAM,UAAU,IAAI,YAAY,EAAE,OAAO,6BAA6B;AACtE,MAAM,iBAAiB,IAAI,YAAY,EAAE,OAAO,6BAA6B;AAQtE,SAAS,SAAS,IAA2B;AACnD,SAAO,UAAU,YAAY,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;AAChD;AAOO,SAAS,IACf,SACA,OACA,IACA,UACA,OACa;AACb,MAAI,CAAC,OAAO,UAAU,KAAK,KA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C,cAAc,UAAU,WAAW,qBAAqB,GAAG;AACnF,UAAM,IAAI,MAAM,uBAAuB,UAAU,EAAE;AAAA,EACpD;AACA,MAAI,gBAAgB,KAAK,CAAC,UAAU,MAAM,WAAW,sBAAsB,GAAG;AAC7E,UAAM,IAAI,MAAM,4BAA4B,eAAe,EAAE;AAAA,EAC9D;AAEA,MAAI,QAAQ,WAAW,YAAY;AAClC,UAAM,IAAI,MAAM,oBAAoB,OAAO,EAAE;AAAA,EAC9C;AAEA,QAAM,OAAO,SAAS,OAAO;AAC7B,OAAK,OAAO,cAAc;AAC1B,OAAK,OAAO,OAAO;AACnB,OAAK,OAAO,IAAI,OAAO,CAAC;AACxB,OAAK,OAAO,IAAI,WAAW,CAAC,SAAS,CAAC,CAAC;AACvC,kBAAgB,QAAQ,CAAC,UAAU,KAAK,OAAO,KAAK,CAAC;AACrD,iBAAe,QAAQ,CAAC,cAAc,KAAK,OAAO,SAAS,CAAC;AAC5D,SAAO,KAAK,OAAO;AACpB;",
|
|
6
|
+
"names": ["KeyPurpose"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { SealCompatibleClient } from './types.js';
|
|
2
|
+
import type { G1Element } from './bls12381.js';
|
|
3
|
+
import { Version } from './utils.js';
|
|
4
|
+
import type { Certificate } from './session-key.js';
|
|
5
|
+
export type KeyServer = {
|
|
6
|
+
objectId: string;
|
|
7
|
+
name: string;
|
|
8
|
+
url: string;
|
|
9
|
+
keyType: KeyServerType;
|
|
10
|
+
pk: Uint8Array<ArrayBuffer>;
|
|
11
|
+
};
|
|
12
|
+
export declare enum KeyServerType {
|
|
13
|
+
BonehFranklinBLS12381 = 0
|
|
14
|
+
}
|
|
15
|
+
export declare const SERVER_VERSION_REQUIREMENT: Version;
|
|
16
|
+
/**
|
|
17
|
+
* Given a list of key server object IDs, returns a list of SealKeyServer
|
|
18
|
+
* from onchain state containing name, objectId, URL and pk.
|
|
19
|
+
*
|
|
20
|
+
* @param objectIds - The key server object IDs.
|
|
21
|
+
* @param client - The HaneulClient to use.
|
|
22
|
+
* @returns - An array of SealKeyServer.
|
|
23
|
+
*/
|
|
24
|
+
export declare function retrieveKeyServers({ objectIds, client, }: {
|
|
25
|
+
objectIds: string[];
|
|
26
|
+
client: SealCompatibleClient;
|
|
27
|
+
}): Promise<KeyServer[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Given a KeyServer, fetch the proof of possession (PoP) from the URL and verify it
|
|
30
|
+
* against the pubkey. This should be used only rarely when the dapp uses a dynamic
|
|
31
|
+
* set of key servers.
|
|
32
|
+
*
|
|
33
|
+
* @param server - The KeyServer to verify.
|
|
34
|
+
* @returns - True if the key server is valid, false otherwise.
|
|
35
|
+
*/
|
|
36
|
+
export declare function verifyKeyServer(server: KeyServer, timeout: number, apiKeyName?: string, apiKey?: string): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Verify the key server version. Throws an `InvalidKeyServerError` if the version is not supported.
|
|
39
|
+
*
|
|
40
|
+
* @param response - The response from the key server.
|
|
41
|
+
*/
|
|
42
|
+
export declare function verifyKeyServerVersion(response: Response): void;
|
|
43
|
+
export interface DerivedKey {
|
|
44
|
+
toString(): string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A user secret key for the Boneh-Franklin BLS12381 scheme.
|
|
48
|
+
* This is a wrapper around the G1Element type.
|
|
49
|
+
*/
|
|
50
|
+
export declare class BonehFranklinBLS12381DerivedKey implements DerivedKey {
|
|
51
|
+
key: G1Element;
|
|
52
|
+
representation: string;
|
|
53
|
+
constructor(key: G1Element);
|
|
54
|
+
toString(): string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Options for fetching keys from the key server.
|
|
58
|
+
*/
|
|
59
|
+
export interface FetchKeysOptions {
|
|
60
|
+
/** The URL of the key server. */
|
|
61
|
+
url: string;
|
|
62
|
+
/** The Base64 string of request signature. */
|
|
63
|
+
requestSignature: string;
|
|
64
|
+
/** The transaction bytes. */
|
|
65
|
+
transactionBytes: Uint8Array;
|
|
66
|
+
/** The ephemeral secret key. */
|
|
67
|
+
encKey: Uint8Array<ArrayBuffer>;
|
|
68
|
+
/** The ephemeral public key. */
|
|
69
|
+
encKeyPk: Uint8Array<ArrayBuffer>;
|
|
70
|
+
/** The ephemeral verification key. */
|
|
71
|
+
encVerificationKey: Uint8Array;
|
|
72
|
+
/** The certificate. */
|
|
73
|
+
certificate: Certificate;
|
|
74
|
+
/** Request timeout in milliseconds. */
|
|
75
|
+
timeout: number;
|
|
76
|
+
/** Optional API key name. */
|
|
77
|
+
apiKeyName?: string;
|
|
78
|
+
/** Optional API key. */
|
|
79
|
+
apiKey?: string;
|
|
80
|
+
/** Optional abort signal for cancellation. */
|
|
81
|
+
signal?: AbortSignal;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Helper function to request all keys from URL with requestSig, txBytes, ephemeral pubkey.
|
|
85
|
+
* Then decrypt the Seal key with ephemeral secret key. Returns a list decryption keys with
|
|
86
|
+
* their full IDs.
|
|
87
|
+
*
|
|
88
|
+
* @param url - The URL of the key server.
|
|
89
|
+
* @param requestSig - The Base64 string of request signature.
|
|
90
|
+
* @param txBytes - The transaction bytes.
|
|
91
|
+
* @param encKey - The ephemeral secret key.
|
|
92
|
+
* @param certificate - The certificate.
|
|
93
|
+
* @returns - A list of full ID and the decrypted key.
|
|
94
|
+
*/
|
|
95
|
+
export declare function fetchKeysForAllIds({ url, requestSignature, transactionBytes, encKey, encKeyPk, encVerificationKey, certificate, timeout, apiKeyName, apiKey, signal, }: FetchKeysOptions): Promise<{
|
|
96
|
+
fullId: string;
|
|
97
|
+
key: Uint8Array<ArrayBuffer>;
|
|
98
|
+
}[]>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { bcs, fromBase64, fromHex, toBase64, toHex } from "@haneullabs/bcs";
|
|
2
|
+
import { bls12_381 } from "@noble/curves/bls12-381";
|
|
3
|
+
import { KeyServerMove, KeyServerMoveV1 } from "./bcs.js";
|
|
4
|
+
import { InvalidKeyServerError, InvalidKeyServerVersionError, SealAPIError } from "./error.js";
|
|
5
|
+
import { DST_POP } from "./ibe.js";
|
|
6
|
+
import { PACKAGE_VERSION } from "./version.js";
|
|
7
|
+
import { flatten, Version } from "./utils.js";
|
|
8
|
+
import { elgamalDecrypt } from "./elgamal.js";
|
|
9
|
+
const EXPECTED_SERVER_VERSION = 1;
|
|
10
|
+
var KeyServerType = /* @__PURE__ */ ((KeyServerType2) => {
|
|
11
|
+
KeyServerType2[KeyServerType2["BonehFranklinBLS12381"] = 0] = "BonehFranklinBLS12381";
|
|
12
|
+
return KeyServerType2;
|
|
13
|
+
})(KeyServerType || {});
|
|
14
|
+
const SERVER_VERSION_REQUIREMENT = new Version("0.4.1");
|
|
15
|
+
async function retrieveKeyServers({
|
|
16
|
+
objectIds,
|
|
17
|
+
client
|
|
18
|
+
}) {
|
|
19
|
+
return await Promise.all(
|
|
20
|
+
objectIds.map(async (objectId) => {
|
|
21
|
+
const res = await client.core.getObject({
|
|
22
|
+
objectId
|
|
23
|
+
});
|
|
24
|
+
const ks = KeyServerMove.parse(await res.object.content);
|
|
25
|
+
if (EXPECTED_SERVER_VERSION < Number(ks.firstVersion) || EXPECTED_SERVER_VERSION > Number(ks.lastVersion)) {
|
|
26
|
+
throw new InvalidKeyServerVersionError(
|
|
27
|
+
`Key server ${objectId} supports versions between ${ks.firstVersion} and ${ks.lastVersion} (inclusive), but SDK expects version ${EXPECTED_SERVER_VERSION}`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
const resVersionedKs = await client.core.getDynamicField({
|
|
31
|
+
parentId: objectId,
|
|
32
|
+
name: {
|
|
33
|
+
type: "u64",
|
|
34
|
+
bcs: bcs.u64().serialize(EXPECTED_SERVER_VERSION).toBytes()
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const ksVersioned = KeyServerMoveV1.parse(resVersionedKs.dynamicField.value.bcs);
|
|
38
|
+
if (ksVersioned.keyType !== 0 /* BonehFranklinBLS12381 */) {
|
|
39
|
+
throw new InvalidKeyServerError(
|
|
40
|
+
`Server ${objectId} has invalid key type: ${ksVersioned.keyType}`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
objectId,
|
|
45
|
+
name: ksVersioned.name,
|
|
46
|
+
url: ksVersioned.url,
|
|
47
|
+
keyType: ksVersioned.keyType,
|
|
48
|
+
pk: new Uint8Array(ksVersioned.pk)
|
|
49
|
+
};
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
async function verifyKeyServer(server, timeout, apiKeyName, apiKey) {
|
|
54
|
+
const requestId = crypto.randomUUID();
|
|
55
|
+
const response = await fetch(server.url + "/v1/service?service_id=" + server.objectId, {
|
|
56
|
+
method: "GET",
|
|
57
|
+
headers: {
|
|
58
|
+
"Content-Type": "application/json",
|
|
59
|
+
"Request-Id": requestId,
|
|
60
|
+
"Client-Sdk-Type": "typescript",
|
|
61
|
+
"Client-Sdk-Version": PACKAGE_VERSION,
|
|
62
|
+
...apiKeyName && apiKey ? { [apiKeyName]: apiKey } : {}
|
|
63
|
+
},
|
|
64
|
+
signal: AbortSignal.timeout(timeout)
|
|
65
|
+
});
|
|
66
|
+
await SealAPIError.assertResponse(response, requestId);
|
|
67
|
+
verifyKeyServerVersion(response);
|
|
68
|
+
const serviceResponse = await response.json();
|
|
69
|
+
if (serviceResponse.service_id !== server.objectId) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const fullMsg = flatten([DST_POP, server.pk, fromHex(server.objectId)]);
|
|
73
|
+
return bls12_381.verifyShortSignature(fromBase64(serviceResponse.pop), fullMsg, server.pk);
|
|
74
|
+
}
|
|
75
|
+
function verifyKeyServerVersion(response) {
|
|
76
|
+
const keyServerVersion = response.headers.get("X-KeyServer-Version");
|
|
77
|
+
if (keyServerVersion == null) {
|
|
78
|
+
throw new InvalidKeyServerVersionError("Key server version not found");
|
|
79
|
+
}
|
|
80
|
+
if (new Version(keyServerVersion).older_than(SERVER_VERSION_REQUIREMENT)) {
|
|
81
|
+
throw new InvalidKeyServerVersionError(
|
|
82
|
+
`Key server version ${keyServerVersion} is not supported`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
class BonehFranklinBLS12381DerivedKey {
|
|
87
|
+
constructor(key) {
|
|
88
|
+
this.key = key;
|
|
89
|
+
this.representation = toHex(key.toBytes());
|
|
90
|
+
}
|
|
91
|
+
toString() {
|
|
92
|
+
return this.representation;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function fetchKeysForAllIds({
|
|
96
|
+
url,
|
|
97
|
+
requestSignature,
|
|
98
|
+
transactionBytes,
|
|
99
|
+
encKey,
|
|
100
|
+
encKeyPk,
|
|
101
|
+
encVerificationKey,
|
|
102
|
+
certificate,
|
|
103
|
+
timeout,
|
|
104
|
+
apiKeyName,
|
|
105
|
+
apiKey,
|
|
106
|
+
signal
|
|
107
|
+
}) {
|
|
108
|
+
const body = {
|
|
109
|
+
ptb: toBase64(transactionBytes.slice(1)),
|
|
110
|
+
// removes the byte of the transaction type version
|
|
111
|
+
enc_key: toBase64(encKeyPk),
|
|
112
|
+
enc_verification_key: toBase64(encVerificationKey),
|
|
113
|
+
request_signature: requestSignature,
|
|
114
|
+
// already b64
|
|
115
|
+
certificate
|
|
116
|
+
};
|
|
117
|
+
const timeoutSignal = AbortSignal.timeout(timeout);
|
|
118
|
+
const combinedSignal = signal ? AbortSignal.any([signal, timeoutSignal]) : timeoutSignal;
|
|
119
|
+
const requestId = crypto.randomUUID();
|
|
120
|
+
const response = await fetch(url + "/v1/fetch_key", {
|
|
121
|
+
method: "POST",
|
|
122
|
+
headers: {
|
|
123
|
+
"Content-Type": "application/json",
|
|
124
|
+
"Request-Id": requestId,
|
|
125
|
+
"Client-Sdk-Type": "typescript",
|
|
126
|
+
"Client-Sdk-Version": PACKAGE_VERSION,
|
|
127
|
+
...apiKeyName && apiKey ? { [apiKeyName]: apiKey } : {}
|
|
128
|
+
},
|
|
129
|
+
body: JSON.stringify(body),
|
|
130
|
+
signal: combinedSignal
|
|
131
|
+
});
|
|
132
|
+
await SealAPIError.assertResponse(response, requestId);
|
|
133
|
+
const resp = await response.json();
|
|
134
|
+
verifyKeyServerVersion(response);
|
|
135
|
+
return resp.decryption_keys.map(
|
|
136
|
+
(dk) => ({
|
|
137
|
+
fullId: toHex(dk.id),
|
|
138
|
+
key: elgamalDecrypt(encKey, dk.encrypted_key.map(fromBase64))
|
|
139
|
+
})
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
export {
|
|
143
|
+
BonehFranklinBLS12381DerivedKey,
|
|
144
|
+
KeyServerType,
|
|
145
|
+
SERVER_VERSION_REQUIREMENT,
|
|
146
|
+
fetchKeysForAllIds,
|
|
147
|
+
retrieveKeyServers,
|
|
148
|
+
verifyKeyServer,
|
|
149
|
+
verifyKeyServerVersion
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=key-server.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/key-server.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { bcs, fromBase64, fromHex, toBase64, toHex } from '@haneullabs/bcs';\nimport { bls12_381 } from '@noble/curves/bls12-381';\n\nimport { KeyServerMove, KeyServerMoveV1 } from './bcs.js';\nimport { InvalidKeyServerError, InvalidKeyServerVersionError, SealAPIError } from './error.js';\nimport { DST_POP } from './ibe.js';\nimport { PACKAGE_VERSION } from './version.js';\nimport type { SealCompatibleClient } from './types.js';\nimport type { G1Element } from './bls12381.js';\nimport { flatten, Version } from './utils.js';\nimport { elgamalDecrypt } from './elgamal.js';\nimport type { Certificate } from './session-key.js';\n\nconst EXPECTED_SERVER_VERSION = 1;\n\nexport type KeyServer = {\n\tobjectId: string;\n\tname: string;\n\turl: string;\n\tkeyType: KeyServerType;\n\tpk: Uint8Array<ArrayBuffer>;\n};\n\nexport enum KeyServerType {\n\tBonehFranklinBLS12381 = 0,\n}\n\nexport const SERVER_VERSION_REQUIREMENT = new Version('0.4.1');\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 HaneulClient to use.\n * @returns - An array of SealKeyServer.\n */\nexport async function retrieveKeyServers({\n\tobjectIds,\n\tclient,\n}: {\n\tobjectIds: string[];\n\tclient: SealCompatibleClient;\n}): Promise<KeyServer[]> {\n\treturn await Promise.all(\n\t\tobjectIds.map(async (objectId) => {\n\t\t\t// First get the KeyServer object and validate it.\n\t\t\tconst res = await client.core.getObject({\n\t\t\t\tobjectId,\n\t\t\t});\n\t\t\tconst ks = KeyServerMove.parse(await res.object.content);\n\t\t\tif (\n\t\t\t\tEXPECTED_SERVER_VERSION < Number(ks.firstVersion) ||\n\t\t\t\tEXPECTED_SERVER_VERSION > Number(ks.lastVersion)\n\t\t\t) {\n\t\t\t\tthrow new InvalidKeyServerVersionError(\n\t\t\t\t\t`Key server ${objectId} supports versions between ${ks.firstVersion} and ${ks.lastVersion} (inclusive), but SDK expects version ${EXPECTED_SERVER_VERSION}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Then fetch the expected versioned object and parse it.\n\t\t\tconst resVersionedKs = await client.core.getDynamicField({\n\t\t\t\tparentId: objectId,\n\t\t\t\tname: {\n\t\t\t\t\ttype: 'u64',\n\t\t\t\t\tbcs: bcs.u64().serialize(EXPECTED_SERVER_VERSION).toBytes(),\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst ksVersioned = KeyServerMoveV1.parse(resVersionedKs.dynamicField.value.bcs);\n\n\t\t\tif (ksVersioned.keyType !== KeyServerType.BonehFranklinBLS12381) {\n\t\t\t\tthrow new InvalidKeyServerError(\n\t\t\t\t\t`Server ${objectId} has invalid key type: ${ksVersioned.keyType}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tobjectId,\n\t\t\t\tname: ksVersioned.name,\n\t\t\t\turl: ksVersioned.url,\n\t\t\t\tkeyType: ksVersioned.keyType,\n\t\t\t\tpk: new Uint8Array(ksVersioned.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(\n\tserver: KeyServer,\n\ttimeout: number,\n\tapiKeyName?: string,\n\tapiKey?: string,\n): Promise<boolean> {\n\tconst requestId = crypto.randomUUID();\n\tconst response = await fetch(server.url! + '/v1/service?service_id=' + server.objectId, {\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\t...(apiKeyName && apiKey ? { [apiKeyName]: apiKey } : {}),\n\t\t},\n\t\tsignal: AbortSignal.timeout(timeout),\n\t});\n\n\tawait SealAPIError.assertResponse(response, requestId);\n\tverifyKeyServerVersion(response);\n\tconst serviceResponse = await response.json();\n\n\tif (serviceResponse.service_id !== server.objectId) {\n\t\treturn false;\n\t}\n\tconst fullMsg = flatten([DST_POP, server.pk, fromHex(server.objectId)]);\n\treturn bls12_381.verifyShortSignature(fromBase64(serviceResponse.pop), fullMsg, server.pk);\n}\n\n/**\n * Verify the key server version. Throws an `InvalidKeyServerError` if the version is not supported.\n *\n * @param response - The response from the key server.\n */\nexport function verifyKeyServerVersion(response: Response) {\n\tconst keyServerVersion = response.headers.get('X-KeyServer-Version');\n\tif (keyServerVersion == null) {\n\t\tthrow new InvalidKeyServerVersionError('Key server version not found');\n\t}\n\tif (new Version(keyServerVersion).older_than(SERVER_VERSION_REQUIREMENT)) {\n\t\tthrow new InvalidKeyServerVersionError(\n\t\t\t`Key server version ${keyServerVersion} is not supported`,\n\t\t);\n\t}\n}\n\nexport interface DerivedKey {\n\ttoString(): string;\n}\n\n/**\n * A user secret key for the Boneh-Franklin BLS12381 scheme.\n * This is a wrapper around the G1Element type.\n */\nexport class BonehFranklinBLS12381DerivedKey implements DerivedKey {\n\trepresentation: string;\n\n\tconstructor(public key: G1Element) {\n\t\tthis.representation = toHex(key.toBytes());\n\t}\n\n\ttoString(): string {\n\t\treturn this.representation;\n\t}\n}\n\n/**\n * Options for fetching keys from the key server.\n */\nexport interface FetchKeysOptions {\n\t/** The URL of the key server. */\n\turl: string;\n\t/** The Base64 string of request signature. */\n\trequestSignature: string;\n\t/** The transaction bytes. */\n\ttransactionBytes: Uint8Array;\n\t/** The ephemeral secret key. */\n\tencKey: Uint8Array<ArrayBuffer>;\n\t/** The ephemeral public key. */\n\tencKeyPk: Uint8Array<ArrayBuffer>;\n\t/** The ephemeral verification key. */\n\tencVerificationKey: Uint8Array;\n\t/** The certificate. */\n\tcertificate: Certificate;\n\t/** Request timeout in milliseconds. */\n\ttimeout: number;\n\t/** Optional API key name. */\n\tapiKeyName?: string;\n\t/** Optional API key. */\n\tapiKey?: string;\n\t/** Optional abort signal for cancellation. */\n\tsignal?: AbortSignal;\n}\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,\n\trequestSignature,\n\ttransactionBytes,\n\tencKey,\n\tencKeyPk,\n\tencVerificationKey,\n\tcertificate,\n\ttimeout,\n\tapiKeyName,\n\tapiKey,\n\tsignal,\n}: FetchKeysOptions): Promise<{ fullId: string; key: Uint8Array<ArrayBuffer> }[]> {\n\tconst body = {\n\t\tptb: toBase64(transactionBytes.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: requestSignature, // 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\t...(apiKeyName && apiKey ? { [apiKeyName]: apiKey } : {}),\n\t\t},\n\t\tbody: JSON.stringify(body),\n\t\tsignal: combinedSignal,\n\t});\n\tawait SealAPIError.assertResponse(response, requestId);\n\tconst resp = await response.json();\n\tverifyKeyServerVersion(response);\n\n\treturn resp.decryption_keys.map(\n\t\t(dk: { id: Uint8Array<ArrayBuffer>; encrypted_key: [string, string] }) => ({\n\t\t\tfullId: toHex(dk.id),\n\t\t\tkey: elgamalDecrypt(encKey, dk.encrypted_key.map(fromBase64) as [Uint8Array, Uint8Array]),\n\t\t}),\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,KAAK,YAAY,SAAS,UAAU,aAAa;AAC1D,SAAS,iBAAiB;AAE1B,SAAS,eAAe,uBAAuB;AAC/C,SAAS,uBAAuB,8BAA8B,oBAAoB;AAClF,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAGhC,SAAS,SAAS,eAAe;AACjC,SAAS,sBAAsB;AAG/B,MAAM,0BAA0B;AAUzB,IAAK,gBAAL,kBAAKA,mBAAL;AACN,EAAAA,8BAAA,2BA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AS,SAAS,QAAQ;AAAA,IAC1B,sBAAsB,SAAS,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,MACtB,GAAI,cAAc,SAAS,EAAE,CAAC,UAAU,GAAG,OAAO,IAAI,CAAC;AAAA,IACxD;AAAA,IACA,MAAM,KAAK,UAAU,IAAI;AAAA,IACzB,QAAQ;AAAA,EACT,CAAC;AACD,QAAM,aAAa,eAAe,UAAU,SAAS;AACrD,QAAM,OAAO,MAAM,SAAS,KAAK;AACjC,yBAAuB,QAAQ;AAE/B,SAAO,KAAK,gBAAgB;AAAA,IAC3B,CAAC,QAA0E;AAAA,MAC1E,QAAQ,MAAM,GAAG,EAAE;AAAA,MACnB,KAAK,eAAe,QAAQ,GAAG,cAAc,IAAI,UAAU,CAA6B;AAAA,IACzF;AAAA,EACD;AACD;",
|
|
6
|
+
"names": ["KeyServerType"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Signer } from '@haneullabs/haneul/cryptography';
|
|
2
|
+
import type { SealCompatibleClient } from './types.js';
|
|
3
|
+
export declare const RequestFormat: import("@haneullabs/bcs").BcsStruct<{
|
|
4
|
+
ptb: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
|
|
5
|
+
encKey: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
|
|
6
|
+
encVerificationKey: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
|
|
7
|
+
}, string>;
|
|
8
|
+
export type Certificate = {
|
|
9
|
+
user: string;
|
|
10
|
+
session_vk: string;
|
|
11
|
+
creation_time: number;
|
|
12
|
+
ttl_min: number;
|
|
13
|
+
signature: string;
|
|
14
|
+
mvr_name?: string;
|
|
15
|
+
};
|
|
16
|
+
export type ExportedSessionKey = {
|
|
17
|
+
address: string;
|
|
18
|
+
packageId: string;
|
|
19
|
+
mvrName?: string;
|
|
20
|
+
creationTimeMs: number;
|
|
21
|
+
ttlMin: number;
|
|
22
|
+
personalMessageSignature?: string;
|
|
23
|
+
sessionKey: string;
|
|
24
|
+
};
|
|
25
|
+
export declare class SessionKey {
|
|
26
|
+
#private;
|
|
27
|
+
private constructor();
|
|
28
|
+
/**
|
|
29
|
+
* Create a new SessionKey instance.
|
|
30
|
+
* @param address - The address of the user.
|
|
31
|
+
* @param packageId - The ID of the package.
|
|
32
|
+
* @param mvrName - Optional. The name of the MVR, if there is one.
|
|
33
|
+
* @param ttlMin - The TTL in minutes.
|
|
34
|
+
* @param signer - Optional. The signer instance, e.g. EnokiSigner.
|
|
35
|
+
* @param haneulClient - The Haneul client.
|
|
36
|
+
* @returns A new SessionKey instance.
|
|
37
|
+
*/
|
|
38
|
+
static create({ address, packageId, mvrName, ttlMin, signer, haneulClient, }: {
|
|
39
|
+
address: string;
|
|
40
|
+
packageId: string;
|
|
41
|
+
mvrName?: string;
|
|
42
|
+
ttlMin: number;
|
|
43
|
+
signer?: Signer;
|
|
44
|
+
haneulClient: SealCompatibleClient;
|
|
45
|
+
}): Promise<SessionKey>;
|
|
46
|
+
isExpired(): boolean;
|
|
47
|
+
getAddress(): string;
|
|
48
|
+
getPackageName(): string;
|
|
49
|
+
getPackageId(): string;
|
|
50
|
+
getPersonalMessage(): Uint8Array;
|
|
51
|
+
setPersonalMessageSignature(personalMessageSignature: string): Promise<void>;
|
|
52
|
+
getCertificate(): Promise<Certificate>;
|
|
53
|
+
/**
|
|
54
|
+
* Create request params for the given transaction bytes.
|
|
55
|
+
* @param txBytes - The transaction bytes.
|
|
56
|
+
* @returns The request params containing the ephemeral secret key,
|
|
57
|
+
* its public key and its verification key.
|
|
58
|
+
*/
|
|
59
|
+
createRequestParams(txBytes: Uint8Array): Promise<{
|
|
60
|
+
encKey: Uint8Array<ArrayBuffer>;
|
|
61
|
+
encKeyPk: Uint8Array<ArrayBuffer>;
|
|
62
|
+
encVerificationKey: Uint8Array<ArrayBuffer>;
|
|
63
|
+
requestSignature: string;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Export the Session Key object from the instance. Store the object in IndexedDB to persist.
|
|
67
|
+
*/
|
|
68
|
+
export(): ExportedSessionKey;
|
|
69
|
+
/**
|
|
70
|
+
* Restore a SessionKey instance for the given object.
|
|
71
|
+
* @returns A new SessionKey instance with restored state
|
|
72
|
+
*/
|
|
73
|
+
static import(data: ExportedSessionKey, haneulClient: SealCompatibleClient, signer?: Signer): SessionKey;
|
|
74
|
+
}
|