@zhoujun_aptos/octopus-ts-sdk-min 0.22.7 → 0.22.8
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/dist/common/index.d.ts +55 -45
- package/dist/common/index.js +169 -88
- package/dist/common/index.js.map +1 -1
- package/dist/esm/index.d.mts +55 -45
- package/dist/esm/index.mjs +168 -88
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.d.mts
CHANGED
|
@@ -150,12 +150,46 @@ declare function keygen$3(schemeId?: number): DecryptionKey$1;
|
|
|
150
150
|
declare function deriveEncryptionKey(dk: DecryptionKey$1): EncryptionKey$1;
|
|
151
151
|
declare function encrypt$3(ek: EncryptionKey$1, msg: Uint8Array): Ciphertext$5;
|
|
152
152
|
declare function encryptWithRandomness$2(ek: EncryptionKey$1, msg: Uint8Array, randomness: Uint8Array): Ciphertext$5;
|
|
153
|
-
declare function decrypt$
|
|
153
|
+
declare function decrypt$2(dk: DecryptionKey$1, ciphertext: Ciphertext$5): Uint8Array | undefined;
|
|
154
154
|
|
|
155
155
|
declare const index$5_SCHEME_SIMPLE_ELGAMAL_RISTRETTO255: typeof SCHEME_SIMPLE_ELGAMAL_RISTRETTO255;
|
|
156
156
|
declare const index$5_deriveEncryptionKey: typeof deriveEncryptionKey;
|
|
157
157
|
declare namespace index$5 {
|
|
158
|
-
export { Ciphertext$5 as Ciphertext, DecryptionKey$1 as DecryptionKey, EncryptionKey$1 as EncryptionKey, index$5_SCHEME_SIMPLE_ELGAMAL_RISTRETTO255 as SCHEME_SIMPLE_ELGAMAL_RISTRETTO255, decrypt$
|
|
158
|
+
export { Ciphertext$5 as Ciphertext, DecryptionKey$1 as DecryptionKey, EncryptionKey$1 as EncryptionKey, index$5_SCHEME_SIMPLE_ELGAMAL_RISTRETTO255 as SCHEME_SIMPLE_ELGAMAL_RISTRETTO255, decrypt$2 as decrypt, index$5_deriveEncryptionKey as deriveEncryptionKey, encrypt$3 as encrypt, encryptWithRandomness$2 as encryptWithRandomness, keygen$3 as keygen };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
declare class Result<T> {
|
|
162
|
+
isOk: boolean;
|
|
163
|
+
okValue?: T;
|
|
164
|
+
errValue?: any;
|
|
165
|
+
extra?: any;
|
|
166
|
+
private constructor();
|
|
167
|
+
static Ok<T>(args: {
|
|
168
|
+
value: T;
|
|
169
|
+
extra?: any;
|
|
170
|
+
}): Result<T>;
|
|
171
|
+
static Err<T>(args: {
|
|
172
|
+
error: any;
|
|
173
|
+
extra?: any;
|
|
174
|
+
}): Result<T>;
|
|
175
|
+
/**
|
|
176
|
+
* You write a closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
177
|
+
* Your closure is also given an `extra` dictionary to record additional context.
|
|
178
|
+
*/
|
|
179
|
+
static capture<T>({ task, recordsExecutionTimeMs }: {
|
|
180
|
+
task: (extra: Record<string, any>) => T;
|
|
181
|
+
recordsExecutionTimeMs: boolean;
|
|
182
|
+
}): Result<T>;
|
|
183
|
+
/**
|
|
184
|
+
* You write an async closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
185
|
+
* Your closure is also given an `extra` dictionary to record additional context.
|
|
186
|
+
*/
|
|
187
|
+
static captureAsync<T>({ task, recordsExecutionTimeMs }: {
|
|
188
|
+
task: (extra: Record<string, any>) => Promise<T>;
|
|
189
|
+
recordsExecutionTimeMs: boolean;
|
|
190
|
+
}): Promise<Result<T>>;
|
|
191
|
+
unwrapOrThrow(tothrow: any): T;
|
|
192
|
+
unwrapErrOrThrow(tothrow: any): any | undefined;
|
|
159
193
|
}
|
|
160
194
|
|
|
161
195
|
declare const SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK = 0;
|
|
@@ -208,8 +242,12 @@ declare function derivePublicKey(privateKey: MasterPrivateKey): MasterPublicKey;
|
|
|
208
242
|
declare function encrypt$2(publicKey: MasterPublicKey, id: Uint8Array, plaintext: Uint8Array): Ciphertext$4;
|
|
209
243
|
/** Do NOT use this, unless you are a maintainer. Use `encrypt` instead. */
|
|
210
244
|
declare function encryptWithRandomness$1(publicKey: MasterPublicKey, id: Uint8Array, plaintext: Uint8Array, randomness: Uint8Array): Ciphertext$4;
|
|
245
|
+
/** @deprecated Use tryExtract instead */
|
|
211
246
|
declare function extract(privateKey: MasterPrivateKey, id: Uint8Array): IdentityPrivateKey;
|
|
212
|
-
declare function
|
|
247
|
+
declare function tryExtract$1(privateKey: MasterPrivateKey, id: Uint8Array): Result<IdentityPrivateKey>;
|
|
248
|
+
/** @deprecated Use tryDecrypt instead */
|
|
249
|
+
declare function decrypt$1(identityKey: IdentityPrivateKey, ciphertext: Ciphertext$4): Uint8Array | undefined;
|
|
250
|
+
declare function tryDecrypt$2(identityKey: IdentityPrivateKey, ciphertext: Ciphertext$4): Result<Uint8Array>;
|
|
213
251
|
|
|
214
252
|
type index$4_IdentityPrivateKey = IdentityPrivateKey;
|
|
215
253
|
declare const index$4_IdentityPrivateKey: typeof IdentityPrivateKey;
|
|
@@ -221,7 +259,7 @@ declare const index$4_SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK: typeof S
|
|
|
221
259
|
declare const index$4_derivePublicKey: typeof derivePublicKey;
|
|
222
260
|
declare const index$4_extract: typeof extract;
|
|
223
261
|
declare namespace index$4 {
|
|
224
|
-
export { Ciphertext$4 as Ciphertext, index$4_IdentityPrivateKey as IdentityPrivateKey, index$4_MasterPrivateKey as MasterPrivateKey, index$4_MasterPublicKey as MasterPublicKey, index$4_SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK as SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK, decrypt$
|
|
262
|
+
export { Ciphertext$4 as Ciphertext, index$4_IdentityPrivateKey as IdentityPrivateKey, index$4_MasterPrivateKey as MasterPrivateKey, index$4_MasterPublicKey as MasterPublicKey, index$4_SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK as SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK, decrypt$1 as decrypt, index$4_derivePublicKey as derivePublicKey, encrypt$2 as encrypt, encryptWithRandomness$1 as encryptWithRandomness, index$4_extract as extract, keygen$2 as keygen, tryDecrypt$2 as tryDecrypt, tryExtract$1 as tryExtract };
|
|
225
263
|
}
|
|
226
264
|
|
|
227
265
|
declare class SchnorrRistretto255SigningKey {
|
|
@@ -325,46 +363,17 @@ declare class Ciphertext$3 {
|
|
|
325
363
|
declare function keygen(scheme?: number): Key;
|
|
326
364
|
declare function encrypt$1(key: Key, plaintext: Uint8Array): Ciphertext$3;
|
|
327
365
|
declare function encryptWithRandomness(key: Key, plaintext: Uint8Array, randomness: Uint8Array): Ciphertext$3;
|
|
328
|
-
|
|
366
|
+
/** @deprecated Use tryDecrypt instead */
|
|
367
|
+
declare function decrypt(key: Key, ciphertext: Ciphertext$3): Uint8Array | undefined;
|
|
368
|
+
declare function tryDecrypt$1(key: Key, ciphertext: Ciphertext$3): Result<Uint8Array>;
|
|
329
369
|
|
|
330
370
|
type index$2_Key = Key;
|
|
331
371
|
declare const index$2_Key: typeof Key;
|
|
372
|
+
declare const index$2_decrypt: typeof decrypt;
|
|
332
373
|
declare const index$2_encryptWithRandomness: typeof encryptWithRandomness;
|
|
333
374
|
declare const index$2_keygen: typeof keygen;
|
|
334
375
|
declare namespace index$2 {
|
|
335
|
-
export { Ciphertext$3 as Ciphertext, index$2_Key as Key,
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
declare class Result<T> {
|
|
339
|
-
isOk: boolean;
|
|
340
|
-
okValue?: T;
|
|
341
|
-
errValue?: any;
|
|
342
|
-
extra?: any;
|
|
343
|
-
private constructor();
|
|
344
|
-
static Ok<T>(args: {
|
|
345
|
-
value: T;
|
|
346
|
-
extra?: any;
|
|
347
|
-
}): Result<T>;
|
|
348
|
-
static Err<T>(args: {
|
|
349
|
-
error: any;
|
|
350
|
-
extra?: any;
|
|
351
|
-
}): Result<T>;
|
|
352
|
-
/**
|
|
353
|
-
* You write a closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
354
|
-
* Your closure is also given an `extra` dictionary to record additional context.
|
|
355
|
-
*/
|
|
356
|
-
static capture<T>({ task, recordsExecutionTimeMs }: {
|
|
357
|
-
task: (extra: Record<string, any>) => T;
|
|
358
|
-
recordsExecutionTimeMs: boolean;
|
|
359
|
-
}): Result<T>;
|
|
360
|
-
/**
|
|
361
|
-
* You write an async closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
362
|
-
* Your closure is also given an `extra` dictionary to record additional context.
|
|
363
|
-
*/
|
|
364
|
-
static captureAsync<T>({ task, recordsExecutionTimeMs }: {
|
|
365
|
-
task: (extra: Record<string, any>) => Promise<T>;
|
|
366
|
-
recordsExecutionTimeMs: boolean;
|
|
367
|
-
}): Promise<Result<T>>;
|
|
376
|
+
export { Ciphertext$3 as Ciphertext, index$2_Key as Key, index$2_decrypt as decrypt, encrypt$1 as encrypt, index$2_encryptWithRandomness as encryptWithRandomness, index$2_keygen as keygen, tryDecrypt$1 as tryDecrypt };
|
|
368
377
|
}
|
|
369
378
|
|
|
370
379
|
declare class WorkerConfig {
|
|
@@ -384,6 +393,7 @@ declare class WorkerConfig {
|
|
|
384
393
|
toPrettyJson(): string;
|
|
385
394
|
}
|
|
386
395
|
declare function view(aptos: Aptos, worker: AccountAddress): Promise<WorkerConfig>;
|
|
396
|
+
/** @deprecated Use getAsync instead */
|
|
387
397
|
declare function get(workerEndpoint: string): Promise<WorkerConfig>;
|
|
388
398
|
declare function getAsync(workerEndpoint: string): Promise<Result<WorkerConfig>>;
|
|
389
399
|
declare function randWorker(): {
|
|
@@ -914,11 +924,11 @@ declare function encrypt({ committee, encryptionKey, contractId, domain, plainte
|
|
|
914
924
|
fullDecryptionDomain: FullDecryptionDomain;
|
|
915
925
|
ciphertext: Ciphertext;
|
|
916
926
|
};
|
|
917
|
-
declare function
|
|
927
|
+
declare function tryDecrypt({ decryptionKey, ciphertext }: {
|
|
918
928
|
decryptionKey: DecryptionKey;
|
|
919
929
|
ciphertext: Ciphertext;
|
|
920
|
-
}): Uint8Array
|
|
921
|
-
declare function
|
|
930
|
+
}): Result<Uint8Array>;
|
|
931
|
+
declare function tryExtract({ ibeMsk, committee, contractId, domain, proof }: {
|
|
922
932
|
ibeMsk: MasterPrivateKey;
|
|
923
933
|
committee: Committee;
|
|
924
934
|
contractId: ContractID;
|
|
@@ -940,11 +950,11 @@ type index_FullDecryptionDomain = FullDecryptionDomain;
|
|
|
940
950
|
declare const index_FullDecryptionDomain: typeof FullDecryptionDomain;
|
|
941
951
|
type index_ProofOfPermission = ProofOfPermission;
|
|
942
952
|
declare const index_ProofOfPermission: typeof ProofOfPermission;
|
|
943
|
-
declare const index_decrypt: typeof decrypt;
|
|
944
953
|
declare const index_encrypt: typeof encrypt;
|
|
945
|
-
declare const
|
|
954
|
+
declare const index_tryDecrypt: typeof tryDecrypt;
|
|
955
|
+
declare const index_tryExtract: typeof tryExtract;
|
|
946
956
|
declare namespace index {
|
|
947
|
-
export { index_Ciphertext as Ciphertext, index_Committee as Committee, index_ContractID as ContractID, index_DecryptionKey as DecryptionKey, index_EncryptionKey as EncryptionKey, index_FullDecryptionDomain as FullDecryptionDomain, index_ProofOfPermission as ProofOfPermission,
|
|
957
|
+
export { index_Ciphertext as Ciphertext, index_Committee as Committee, index_ContractID as ContractID, index_DecryptionKey as DecryptionKey, index_EncryptionKey as EncryptionKey, index_FullDecryptionDomain as FullDecryptionDomain, index_ProofOfPermission as ProofOfPermission, index_encrypt as encrypt, index_tryDecrypt as tryDecrypt, index_tryExtract as tryExtract };
|
|
948
958
|
}
|
|
949
959
|
|
|
950
960
|
declare const CONTRACT_ADDRESS_HEX: string;
|
|
@@ -998,4 +1008,4 @@ declare class WorkerTask {
|
|
|
998
1008
|
};
|
|
999
1009
|
}
|
|
1000
1010
|
|
|
1001
|
-
export { elgamal as ElGamal, index$5 as Enc, group as Group, index$4 as IBE, index$3 as Sig, silent_setup_encryption as SilentSetupEncryption, index$1 as SilentSetupEncryptionXChain, index$2 as Sym, index as ThresholdIbe, utils as Utils, worker_config as WorkerConfig, WorkerTask };
|
|
1011
|
+
export { elgamal as ElGamal, index$5 as Enc, group as Group, index$4 as IBE, Result, index$3 as Sig, silent_setup_encryption as SilentSetupEncryption, index$1 as SilentSetupEncryptionXChain, index$2 as Sym, index as ThresholdIbe, utils as Utils, worker_config as WorkerConfig, WorkerTask };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -711,7 +711,9 @@ __export(ibe_exports, {
|
|
|
711
711
|
encrypt: () => encrypt4,
|
|
712
712
|
encryptWithRandomness: () => encryptWithRandomness4,
|
|
713
713
|
extract: () => extract2,
|
|
714
|
-
keygen: () => keygen4
|
|
714
|
+
keygen: () => keygen4,
|
|
715
|
+
tryDecrypt: () => tryDecrypt2,
|
|
716
|
+
tryExtract: () => tryExtract
|
|
715
717
|
});
|
|
716
718
|
import { Deserializer as Deserializer5, Serializer as Serializer6 } from "@aptos-labs/ts-sdk";
|
|
717
719
|
import { bytesToHex as bytesToHex5, hexToBytes as hexToBytes2 } from "@noble/curves/abstract/utils";
|
|
@@ -720,6 +722,84 @@ import { bytesToHex as bytesToHex5, hexToBytes as hexToBytes2 } from "@noble/cur
|
|
|
720
722
|
import { bls12_381 } from "@noble/curves/bls12-381";
|
|
721
723
|
import { bytesToNumberBE, bytesToNumberLE as bytesToNumberLE2, numberToBytesLE as numberToBytesLE2 } from "@noble/curves/utils";
|
|
722
724
|
import { bytesToHex as bytesToHex4, randomBytes } from "@noble/hashes/utils";
|
|
725
|
+
|
|
726
|
+
// src/result.ts
|
|
727
|
+
var Result = class _Result {
|
|
728
|
+
isOk;
|
|
729
|
+
okValue;
|
|
730
|
+
errValue;
|
|
731
|
+
extra;
|
|
732
|
+
constructor({ isOk, okValue, errValue, extra }) {
|
|
733
|
+
this.isOk = isOk;
|
|
734
|
+
this.okValue = okValue;
|
|
735
|
+
this.errValue = errValue;
|
|
736
|
+
this.extra = extra;
|
|
737
|
+
}
|
|
738
|
+
static Ok(args) {
|
|
739
|
+
return new _Result({ isOk: true, okValue: args.value, extra: args.extra });
|
|
740
|
+
}
|
|
741
|
+
static Err(args) {
|
|
742
|
+
return new _Result({ isOk: false, errValue: args.error, extra: args.extra });
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* You write a closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
746
|
+
* Your closure is also given an `extra` dictionary to record additional context.
|
|
747
|
+
*/
|
|
748
|
+
static capture({ task, recordsExecutionTimeMs = false }) {
|
|
749
|
+
const start = performance.now();
|
|
750
|
+
var extra = {};
|
|
751
|
+
var error;
|
|
752
|
+
var okValue;
|
|
753
|
+
try {
|
|
754
|
+
okValue = task(extra);
|
|
755
|
+
} catch (caught) {
|
|
756
|
+
error = caught;
|
|
757
|
+
} finally {
|
|
758
|
+
if (recordsExecutionTimeMs) {
|
|
759
|
+
extra["_sdk_execution_time_ms"] = performance.now() - start;
|
|
760
|
+
}
|
|
761
|
+
if (error !== void 0) {
|
|
762
|
+
return _Result.Err({ error, extra });
|
|
763
|
+
} else {
|
|
764
|
+
return _Result.Ok({ value: okValue, extra });
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* You write an async closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
770
|
+
* Your closure is also given an `extra` dictionary to record additional context.
|
|
771
|
+
*/
|
|
772
|
+
static async captureAsync({ task, recordsExecutionTimeMs = false }) {
|
|
773
|
+
var extra = {};
|
|
774
|
+
const start = performance.now();
|
|
775
|
+
var error;
|
|
776
|
+
var okValue;
|
|
777
|
+
try {
|
|
778
|
+
okValue = await task(extra);
|
|
779
|
+
} catch (caught) {
|
|
780
|
+
error = caught;
|
|
781
|
+
} finally {
|
|
782
|
+
if (recordsExecutionTimeMs) {
|
|
783
|
+
extra["_sdk_execution_time_ms"] = performance.now() - start;
|
|
784
|
+
}
|
|
785
|
+
if (error !== void 0) {
|
|
786
|
+
return _Result.Err({ error, extra });
|
|
787
|
+
} else {
|
|
788
|
+
return _Result.Ok({ value: okValue, extra });
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
unwrapOrThrow(tothrow) {
|
|
793
|
+
if (!this.isOk) throw tothrow;
|
|
794
|
+
return this.okValue;
|
|
795
|
+
}
|
|
796
|
+
unwrapErrOrThrow(tothrow) {
|
|
797
|
+
if (this.isOk) throw tothrow;
|
|
798
|
+
return this.errValue;
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
// src/ibe/otp_hmac_boneh_franklin_bls12381_short_pk.ts
|
|
723
803
|
var DST_OTP = new TextEncoder().encode("BONEH_FRANKLIN_BLS12381_SHORT_PK/OTP");
|
|
724
804
|
var DST_ID_HASH = new TextEncoder().encode("BONEH_FRANKLIN_BLS12381_SHORT_PK/HASH_ID_TO_CURVE");
|
|
725
805
|
var DST_MAC = new TextEncoder().encode("BONEH_FRANKLIN_BLS12381_SHORT_PK/MAC");
|
|
@@ -853,6 +933,21 @@ function decrypt3(identityKey, ciphertext) {
|
|
|
853
933
|
const plaintext = xorBytes(otp, ciphertext.symmetricCiph);
|
|
854
934
|
return plaintext;
|
|
855
935
|
}
|
|
936
|
+
function tryDecrypt(identityKey, ciphertext) {
|
|
937
|
+
const task = (_extra) => {
|
|
938
|
+
const seedElementGt = bls12_381.pairing(ciphertext.c0, identityKey.privatePointG2);
|
|
939
|
+
const seed = bls12381GtReprNobleToAptos(bls12_381.fields.Fp12.toBytes(seedElementGt));
|
|
940
|
+
const macKey = kdf(seed, DST_MAC, 32);
|
|
941
|
+
const macAnother = hmac_sha3_256(macKey, ciphertext.symmetricCiph);
|
|
942
|
+
if (bytesToHex4(ciphertext.mac) !== bytesToHex4(macAnother)) {
|
|
943
|
+
throw "decryption failed";
|
|
944
|
+
}
|
|
945
|
+
const otp = kdf(seed, DST_OTP, ciphertext.symmetricCiph.length);
|
|
946
|
+
const plaintext = xorBytes(otp, ciphertext.symmetricCiph);
|
|
947
|
+
return plaintext;
|
|
948
|
+
};
|
|
949
|
+
return Result.capture({ task, recordsExecutionTimeMs: true });
|
|
950
|
+
}
|
|
856
951
|
|
|
857
952
|
// src/ibe/index.ts
|
|
858
953
|
var SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK = 0;
|
|
@@ -1083,12 +1178,36 @@ function extract2(privateKey, id) {
|
|
|
1083
1178
|
}
|
|
1084
1179
|
throw new Error(`Unknown scheme: ${privateKey.scheme}`);
|
|
1085
1180
|
}
|
|
1181
|
+
function tryExtract(privateKey, id) {
|
|
1182
|
+
const task = (extra) => {
|
|
1183
|
+
extra["scheme"] = privateKey.scheme;
|
|
1184
|
+
if (privateKey.scheme == SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK) {
|
|
1185
|
+
return new IdentityPrivateKey2(
|
|
1186
|
+
SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK,
|
|
1187
|
+
extract(privateKey.inner, id)
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
throw `unknown scheme`;
|
|
1191
|
+
};
|
|
1192
|
+
return Result.capture({ task, recordsExecutionTimeMs: true });
|
|
1193
|
+
}
|
|
1086
1194
|
function decrypt4(identityKey, ciphertext) {
|
|
1087
1195
|
if (identityKey.scheme == SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK) {
|
|
1088
1196
|
return decrypt3(identityKey.inner, ciphertext.inner);
|
|
1089
1197
|
}
|
|
1090
1198
|
throw new Error(`Unknown scheme: ${identityKey.scheme}`);
|
|
1091
1199
|
}
|
|
1200
|
+
function tryDecrypt2(identityKey, ciphertext) {
|
|
1201
|
+
const task = (extra) => {
|
|
1202
|
+
extra["scheme"] = identityKey.scheme;
|
|
1203
|
+
if (identityKey.scheme == SCHEME_OTP_HAMC_BONEH_FRANKLIN_BLS12381_SHORT_PK) {
|
|
1204
|
+
const innerResult = tryDecrypt(identityKey.inner, ciphertext.inner);
|
|
1205
|
+
return innerResult.unwrapOrThrow("OtpHmacBonehFranklinBls12381ShortPK.tryDecrypt failed");
|
|
1206
|
+
}
|
|
1207
|
+
throw `unknown scheme`;
|
|
1208
|
+
};
|
|
1209
|
+
return Result.capture({ task, recordsExecutionTimeMs: true });
|
|
1210
|
+
}
|
|
1092
1211
|
|
|
1093
1212
|
// src/sig/index.ts
|
|
1094
1213
|
var sig_exports = {};
|
|
@@ -2155,7 +2274,8 @@ __export(sym_exports, {
|
|
|
2155
2274
|
decrypt: () => decrypt6,
|
|
2156
2275
|
encrypt: () => encrypt6,
|
|
2157
2276
|
encryptWithRandomness: () => encryptWithRandomness6,
|
|
2158
|
-
keygen: () => keygen8
|
|
2277
|
+
keygen: () => keygen8,
|
|
2278
|
+
tryDecrypt: () => tryDecrypt4
|
|
2159
2279
|
});
|
|
2160
2280
|
import { Deserializer as Deserializer9, Serializer as Serializer10 } from "@aptos-labs/ts-sdk";
|
|
2161
2281
|
import { bytesToHex as bytesToHex9 } from "@noble/curves/utils";
|
|
@@ -2256,6 +2376,16 @@ function decrypt5(key, ciphertext) {
|
|
|
2256
2376
|
return void 0;
|
|
2257
2377
|
}
|
|
2258
2378
|
}
|
|
2379
|
+
function tryDecrypt3(key, ciphertext) {
|
|
2380
|
+
const task = (_extra) => {
|
|
2381
|
+
const gcmInstance = gcm(key.inner, ciphertext.iv);
|
|
2382
|
+
const encryptedData = new Uint8Array(ciphertext.ct.length + ciphertext.tag.length);
|
|
2383
|
+
encryptedData.set(ciphertext.ct, 0);
|
|
2384
|
+
encryptedData.set(ciphertext.tag, ciphertext.ct.length);
|
|
2385
|
+
return gcmInstance.decrypt(encryptedData);
|
|
2386
|
+
};
|
|
2387
|
+
return Result.capture({ task, recordsExecutionTimeMs: true });
|
|
2388
|
+
}
|
|
2259
2389
|
|
|
2260
2390
|
// src/sym/index.ts
|
|
2261
2391
|
var SCHEME_AES256GCM = 0;
|
|
@@ -2365,6 +2495,17 @@ function decrypt6(key, ciphertext) {
|
|
|
2365
2495
|
}
|
|
2366
2496
|
throw new Error("Invalid scheme");
|
|
2367
2497
|
}
|
|
2498
|
+
function tryDecrypt4(key, ciphertext) {
|
|
2499
|
+
const task = (extra) => {
|
|
2500
|
+
extra["scheme"] = key.scheme;
|
|
2501
|
+
if (key.scheme === SCHEME_AES256GCM) {
|
|
2502
|
+
const innerResult = tryDecrypt3(key.inner, ciphertext.inner);
|
|
2503
|
+
return innerResult.unwrapOrThrow("AES256GCM decryption failed");
|
|
2504
|
+
}
|
|
2505
|
+
throw `unknown scheme`;
|
|
2506
|
+
};
|
|
2507
|
+
return Result.capture({ task, recordsExecutionTimeMs: true });
|
|
2508
|
+
}
|
|
2368
2509
|
|
|
2369
2510
|
// src/worker_config.ts
|
|
2370
2511
|
var worker_config_exports = {};
|
|
@@ -2377,76 +2518,6 @@ __export(worker_config_exports, {
|
|
|
2377
2518
|
});
|
|
2378
2519
|
import { AccountAddress, Deserializer as Deserializer10, Network as Network2, Serializer as Serializer11 } from "@aptos-labs/ts-sdk";
|
|
2379
2520
|
import { bytesToHex as bytesToHex10, hexToBytes as hexToBytes5 } from "@noble/curves/utils";
|
|
2380
|
-
|
|
2381
|
-
// src/result.ts
|
|
2382
|
-
var Result = class _Result {
|
|
2383
|
-
isOk;
|
|
2384
|
-
okValue;
|
|
2385
|
-
errValue;
|
|
2386
|
-
extra;
|
|
2387
|
-
constructor({ isOk, okValue, errValue, extra }) {
|
|
2388
|
-
this.isOk = isOk;
|
|
2389
|
-
this.okValue = okValue;
|
|
2390
|
-
this.errValue = errValue;
|
|
2391
|
-
this.extra = extra;
|
|
2392
|
-
}
|
|
2393
|
-
static Ok(args) {
|
|
2394
|
-
return new _Result({ isOk: true, okValue: args.value, extra: args.extra });
|
|
2395
|
-
}
|
|
2396
|
-
static Err(args) {
|
|
2397
|
-
return new _Result({ isOk: false, errValue: args.error, extra: args.extra });
|
|
2398
|
-
}
|
|
2399
|
-
/**
|
|
2400
|
-
* You write a closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
2401
|
-
* Your closure is also given an `extra` dictionary to record additional context.
|
|
2402
|
-
*/
|
|
2403
|
-
static capture({ task, recordsExecutionTimeMs = false }) {
|
|
2404
|
-
const start = performance.now();
|
|
2405
|
-
var extra = {};
|
|
2406
|
-
var error;
|
|
2407
|
-
var okValue;
|
|
2408
|
-
try {
|
|
2409
|
-
okValue = task(extra);
|
|
2410
|
-
} catch (caught) {
|
|
2411
|
-
error = caught;
|
|
2412
|
-
} finally {
|
|
2413
|
-
if (recordsExecutionTimeMs) {
|
|
2414
|
-
extra["_sdk_execution_time_ms"] = performance.now() - start;
|
|
2415
|
-
}
|
|
2416
|
-
if (error !== void 0) {
|
|
2417
|
-
return _Result.Err({ error, extra });
|
|
2418
|
-
} else {
|
|
2419
|
-
return _Result.Ok({ value: okValue, extra });
|
|
2420
|
-
}
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
/**
|
|
2424
|
-
* You write an async closure that either returns a T or throws, and we wrap it to return a Result<T>.
|
|
2425
|
-
* Your closure is also given an `extra` dictionary to record additional context.
|
|
2426
|
-
*/
|
|
2427
|
-
static async captureAsync({ task, recordsExecutionTimeMs = false }) {
|
|
2428
|
-
var extra = {};
|
|
2429
|
-
const start = performance.now();
|
|
2430
|
-
var error;
|
|
2431
|
-
var okValue;
|
|
2432
|
-
try {
|
|
2433
|
-
okValue = await task(extra);
|
|
2434
|
-
} catch (caught) {
|
|
2435
|
-
error = caught;
|
|
2436
|
-
} finally {
|
|
2437
|
-
if (recordsExecutionTimeMs) {
|
|
2438
|
-
extra["_sdk_execution_time_ms"] = performance.now() - start;
|
|
2439
|
-
}
|
|
2440
|
-
if (error !== void 0) {
|
|
2441
|
-
return _Result.Err({ error, extra });
|
|
2442
|
-
} else {
|
|
2443
|
-
return _Result.Ok({ value: okValue, extra });
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
}
|
|
2447
|
-
};
|
|
2448
|
-
|
|
2449
|
-
// src/worker_config.ts
|
|
2450
2521
|
var WorkerConfig = class _WorkerConfig {
|
|
2451
2522
|
expiryTimeMicrosecs;
|
|
2452
2523
|
endpoint;
|
|
@@ -2574,9 +2645,9 @@ __export(threshold_ibe_exports, {
|
|
|
2574
2645
|
EncryptionKey: () => EncryptionKey2,
|
|
2575
2646
|
FullDecryptionDomain: () => FullDecryptionDomain,
|
|
2576
2647
|
ProofOfPermission: () => ProofOfPermission3,
|
|
2577
|
-
decrypt: () => decrypt7,
|
|
2578
2648
|
encrypt: () => encrypt7,
|
|
2579
|
-
|
|
2649
|
+
tryDecrypt: () => tryDecrypt5,
|
|
2650
|
+
tryExtract: () => tryExtract2
|
|
2580
2651
|
});
|
|
2581
2652
|
import { Deserializer as Deserializer13, Serializer as Serializer14 } from "@aptos-labs/ts-sdk";
|
|
2582
2653
|
import { bytesToHex as bytesToHex13, hexToBytes as hexToBytes8 } from "@noble/hashes/utils";
|
|
@@ -3427,21 +3498,29 @@ function encrypt7({ committee, encryptionKey, contractId, domain, plaintext }) {
|
|
|
3427
3498
|
const ibeCiphs = symmKeyShares.map((share, idx) => encrypt4(encryptionKey.ibeMpks[idx], fullDecryptionDomain.toBytes(), share.payload));
|
|
3428
3499
|
return { fullDecryptionDomain, ciphertext: new Ciphertext7(symmCiph, ibeCiphs) };
|
|
3429
3500
|
}
|
|
3430
|
-
function
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3501
|
+
function tryDecrypt5({ decryptionKey, ciphertext }) {
|
|
3502
|
+
const task = (extra) => {
|
|
3503
|
+
extra["numIbeDecryptionKeys"] = decryptionKey.ibeDecryptionKeys.length;
|
|
3504
|
+
extra["numIbeCiphs"] = ciphertext.ibeCiphs.length;
|
|
3505
|
+
if (decryptionKey.ibeDecryptionKeys.length !== ciphertext.ibeCiphs.length) {
|
|
3506
|
+
throw "decryption key share count does not match ciphertext share count";
|
|
3507
|
+
}
|
|
3508
|
+
const unfilteredSymmKeyShares = ciphertext.ibeCiphs.map((ibeCiph, idx) => {
|
|
3509
|
+
if (decryptionKey.ibeDecryptionKeys[idx] == null) return null;
|
|
3510
|
+
const maybeSharePayload = tryDecrypt2(decryptionKey.ibeDecryptionKeys[idx], ibeCiph);
|
|
3511
|
+
if (!maybeSharePayload.isOk) return null;
|
|
3512
|
+
return new Share(idx + 1, maybeSharePayload.okValue);
|
|
3513
|
+
});
|
|
3514
|
+
extra["symmKeySharePresences"] = unfilteredSymmKeyShares.map((share) => share != null);
|
|
3515
|
+
const symmKeyShares = unfilteredSymmKeyShares.filter((share) => share != null);
|
|
3516
|
+
const symmKeyBytes = combine(symmKeyShares);
|
|
3517
|
+
const symmKey = Key2.fromBytes(symmKeyBytes);
|
|
3518
|
+
const symDecResult = tryDecrypt4(symmKey, ciphertext.aesCiph);
|
|
3519
|
+
return symDecResult.unwrapOrThrow("symmetric decryption failed");
|
|
3520
|
+
};
|
|
3521
|
+
return Result.capture({ task, recordsExecutionTimeMs: true });
|
|
3443
3522
|
}
|
|
3444
|
-
async function
|
|
3523
|
+
async function tryExtract2({ ibeMsk, committee, contractId, domain, proof }) {
|
|
3445
3524
|
const task = async (extra) => {
|
|
3446
3525
|
extra["contractIdScheme"] = contractId.scheme;
|
|
3447
3526
|
extra["proofScheme"] = proof.scheme;
|
|
@@ -4561,6 +4640,7 @@ export {
|
|
|
4561
4640
|
enc_exports as Enc,
|
|
4562
4641
|
group_exports as Group,
|
|
4563
4642
|
ibe_exports as IBE,
|
|
4643
|
+
Result,
|
|
4564
4644
|
sig_exports as Sig,
|
|
4565
4645
|
silent_setup_encryption_exports as SilentSetupEncryption,
|
|
4566
4646
|
silent_setup_encryption_xchain_exports as SilentSetupEncryptionXChain,
|