@arcium-hq/client 0.9.2 → 0.9.4
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/build/index.cjs +166 -11
- package/build/index.mjs +166 -12
- package/build/types/arcis/arcisModule.d.ts +26 -0
- package/build/types/arcis/arcisModule.d.ts.map +1 -0
- package/build/types/arcis/arcisType.d.ts +76 -0
- package/build/types/arcis/arcisType.d.ts.map +1 -0
- package/build/types/arcis/packer.d.ts +63 -0
- package/build/types/arcis/packer.d.ts.map +1 -0
- package/build/types/arcis/packing.d.ts +33 -0
- package/build/types/arcis/packing.d.ts.map +1 -0
- package/build/types/callback.d.ts +21 -0
- package/build/types/callback.d.ts.map +1 -0
- package/build/types/constants.d.ts +101 -0
- package/build/types/constants.d.ts.map +1 -0
- package/build/types/cryptography/aes128Cipher.d.ts +14 -0
- package/build/types/cryptography/aes128Cipher.d.ts.map +1 -0
- package/build/types/cryptography/aes192Cipher.d.ts +14 -0
- package/build/types/cryptography/aes192Cipher.d.ts.map +1 -0
- package/build/types/cryptography/aes256Cipher.d.ts +14 -0
- package/build/types/cryptography/aes256Cipher.d.ts.map +1 -0
- package/build/types/cryptography/aesCtrCipher.d.ts +36 -0
- package/build/types/cryptography/aesCtrCipher.d.ts.map +1 -0
- package/build/types/cryptography/arcisEd25519.d.ts +8 -0
- package/build/types/cryptography/arcisEd25519.d.ts.map +1 -0
- package/build/types/cryptography/cSplRescueCipher.d.ts +29 -0
- package/build/types/cryptography/cSplRescueCipher.d.ts.map +1 -0
- package/build/types/cryptography/cryptography.d.ts +38 -0
- package/build/types/cryptography/cryptography.d.ts.map +1 -0
- package/build/types/cryptography/hkdf.d.ts +37 -0
- package/build/types/cryptography/hkdf.d.ts.map +1 -0
- package/build/types/cryptography/hmac.d.ts +22 -0
- package/build/types/cryptography/hmac.d.ts.map +1 -0
- package/build/types/cryptography/rescueCipher.d.ts +29 -0
- package/build/types/cryptography/rescueCipher.d.ts.map +1 -0
- package/build/types/cryptography/rescueCipherCommon.d.ts +45 -0
- package/build/types/cryptography/rescueCipherCommon.d.ts.map +1 -0
- package/build/types/cryptography/rescueDesc.d.ts +80 -0
- package/build/types/cryptography/rescueDesc.d.ts.map +1 -0
- package/build/types/cryptography/rescuePrimeHash.d.ts +23 -0
- package/build/types/cryptography/rescuePrimeHash.d.ts.map +1 -0
- package/build/types/ctUtils.d.ts +50 -0
- package/build/types/ctUtils.d.ts.map +1 -0
- package/build/{index.d.ts → types/idl/arcium.d.ts} +156 -909
- package/build/types/idl/arcium.d.ts.map +1 -0
- package/build/types/idl/arcium_staking.d.ts +4589 -0
- package/build/types/idl/arcium_staking.d.ts.map +1 -0
- package/build/types/idl/index.d.ts +15 -0
- package/build/types/idl/index.d.ts.map +1 -0
- package/build/types/index.d.ts +33 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/localEnv.d.ts +15 -0
- package/build/types/localEnv.d.ts.map +1 -0
- package/build/types/matrix.d.ts +39 -0
- package/build/types/matrix.d.ts.map +1 -0
- package/build/types/onchain.d.ts +223 -0
- package/build/types/onchain.d.ts.map +1 -0
- package/build/types/pda.d.ts +89 -0
- package/build/types/pda.d.ts.map +1 -0
- package/build/types/utils.d.ts +65 -0
- package/build/types/utils.d.ts.map +1 -0
- package/package.json +6 -6
- package/src/arcis/arcisModule.ts +39 -0
- package/src/arcis/arcisType.ts +303 -0
- package/src/arcis/packer.ts +152 -0
- package/src/arcis/packing.ts +115 -0
- package/src/callback.ts +101 -0
- package/src/constants.ts +104 -0
- package/src/cryptography/aes128Cipher.ts +16 -0
- package/src/cryptography/aes192Cipher.ts +16 -0
- package/src/cryptography/aes256Cipher.ts +16 -0
- package/src/cryptography/aesCtrCipher.ts +84 -0
- package/src/cryptography/arcisEd25519.ts +96 -0
- package/src/cryptography/cSplRescueCipher.ts +41 -0
- package/src/cryptography/cryptography.ts +82 -0
- package/src/cryptography/hkdf.ts +58 -0
- package/src/cryptography/hmac.ts +66 -0
- package/src/cryptography/rescueCipher.ts +41 -0
- package/src/cryptography/rescueCipherCommon.ts +211 -0
- package/src/cryptography/rescueDesc.ts +492 -0
- package/src/cryptography/rescuePrimeHash.ts +72 -0
- package/src/ctUtils.ts +124 -0
- package/src/idl/arcium.json +12424 -0
- package/src/idl/arcium.ts +12430 -0
- package/src/idl/arcium_staking.json +4582 -0
- package/src/idl/arcium_staking.ts +4588 -0
- package/src/idl/index.ts +20 -0
- package/src/index.ts +32 -0
- package/src/localEnv.ts +39 -0
- package/src/matrix.ts +215 -0
- package/src/onchain.ts +1020 -0
- package/src/pda.ts +203 -0
- package/src/utils.ts +126 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PublicKey, Finality } from '@solana/web3.js';
|
|
2
|
+
import { AnchorProvider, BN } from '@coral-xyz/anchor';
|
|
3
|
+
/**
|
|
4
|
+
* Wait for a computation to finalize by polling the computation account
|
|
5
|
+
* status via HTTP RPC. Does not use WebSocket subscriptions.
|
|
6
|
+
*
|
|
7
|
+
* Polls every 500ms (same as Agave's send_and_confirm_transaction_with_config).
|
|
8
|
+
* Return the most recent transaction signature on the computation account
|
|
9
|
+
* once finalization is detected.
|
|
10
|
+
*
|
|
11
|
+
* @param provider - Anchor provider.
|
|
12
|
+
* @param computationOffset - Computation offset to wait for.
|
|
13
|
+
* @param mxeProgramId - MXE program public key.
|
|
14
|
+
* @param commitment - Commitment level for RPC calls (default: 'confirmed').
|
|
15
|
+
* @param timeoutMs - Maximum wait time in milliseconds (default: 120000).
|
|
16
|
+
* @returns Transaction signature from the finalization.
|
|
17
|
+
* @throws Error if the MXE account has no cluster assigned.
|
|
18
|
+
* @throws Error if the computation does not finalize within timeoutMs.
|
|
19
|
+
*/
|
|
20
|
+
export declare function awaitComputationFinalization(provider: AnchorProvider, computationOffset: BN, mxeProgramId: PublicKey, commitment?: Finality, timeoutMs?: number): Promise<string>;
|
|
21
|
+
//# sourceMappingURL=callback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["../../src/callback.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EACT,QAAQ,EACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACH,cAAc,EAAE,EAAE,EACrB,MAAM,mBAAmB,CAAC;AAM3B;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,4BAA4B,CAC9C,QAAQ,EAAE,cAAc,EACxB,iBAAiB,EAAE,EAAE,EACrB,YAAY,EAAE,SAAS,EACvB,UAAU,GAAE,QAAsB,EAClC,SAAS,GAAE,MAAgB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAiEjB"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seed for ClockAccount PDA.
|
|
3
|
+
* @constant {string}
|
|
4
|
+
*/
|
|
5
|
+
export declare const CLOCK_ACC_SEED = "ClockAccount";
|
|
6
|
+
/**
|
|
7
|
+
* Seed for FeePool PDA.
|
|
8
|
+
* @constant {string}
|
|
9
|
+
*/
|
|
10
|
+
export declare const POOL_ACC_SEED = "FeePool";
|
|
11
|
+
/**
|
|
12
|
+
* Seed for ComputationAccount PDA.
|
|
13
|
+
* @constant {string}
|
|
14
|
+
*/
|
|
15
|
+
export declare const COMPUTATION_ACC_SEED = "ComputationAccount";
|
|
16
|
+
/**
|
|
17
|
+
* Seed for Mempool PDA.
|
|
18
|
+
* @constant {string}
|
|
19
|
+
*/
|
|
20
|
+
export declare const MEMPOOL_ACC_SEED = "Mempool";
|
|
21
|
+
/**
|
|
22
|
+
* Seed for ExecutingPoolAccount PDA.
|
|
23
|
+
* @constant {string}
|
|
24
|
+
*/
|
|
25
|
+
export declare const EXEC_POOL_ACC_SEED = "Execpool";
|
|
26
|
+
/**
|
|
27
|
+
* Seed for ClusterAccount PDA.
|
|
28
|
+
* @constant {string}
|
|
29
|
+
*/
|
|
30
|
+
export declare const CLUSTER_ACC_SEED = "Cluster";
|
|
31
|
+
/**
|
|
32
|
+
* Seed for ArxNodeAccount PDA.
|
|
33
|
+
* @constant {string}
|
|
34
|
+
*/
|
|
35
|
+
export declare const ARX_NODE_ACC_SEED = "ArxNode";
|
|
36
|
+
/**
|
|
37
|
+
* Seed for MXE Account PDA.
|
|
38
|
+
* @constant {string}
|
|
39
|
+
*/
|
|
40
|
+
export declare const MXE_ACCOUNT_SEED = "MXEAccount";
|
|
41
|
+
/**
|
|
42
|
+
* Seed for CompDefAccount PDA.
|
|
43
|
+
* @constant {string}
|
|
44
|
+
*/
|
|
45
|
+
export declare const COMP_DEF_ACC_SEED = "ComputationDefinitionAccount";
|
|
46
|
+
/**
|
|
47
|
+
* Seed for RecoveryClusterAccount PDA.
|
|
48
|
+
* @constant {string}
|
|
49
|
+
*/
|
|
50
|
+
export declare const RECOVERY_CLUSTER_ACC_SEED = "RecoveryClusterAccount";
|
|
51
|
+
/**
|
|
52
|
+
* Seed for MxeRecoveryAccount PDA.
|
|
53
|
+
* @constant {string}
|
|
54
|
+
*/
|
|
55
|
+
export declare const MXE_RECOVERY_ACC_SEED = "MxeRecoveryAccount";
|
|
56
|
+
/**
|
|
57
|
+
* Seed for ComputationDefinitionRaw PDA.
|
|
58
|
+
* @constant {string}
|
|
59
|
+
*/
|
|
60
|
+
export declare const RAW_CIRCUIT_ACC_SEED = "ComputationDefinitionRaw";
|
|
61
|
+
/**
|
|
62
|
+
* Maximum number of bytes that can be reallocated per instruction.
|
|
63
|
+
* @constant {number}
|
|
64
|
+
*/
|
|
65
|
+
export declare const MAX_REALLOC_PER_IX = 10240;
|
|
66
|
+
/**
|
|
67
|
+
* Maximum number of bytes that can be uploaded in a single transaction with the upload instruction.
|
|
68
|
+
* @constant {number}
|
|
69
|
+
*/
|
|
70
|
+
export declare const MAX_UPLOAD_PER_TX_BYTES = 814;
|
|
71
|
+
/**
|
|
72
|
+
* Maximum size of an account in bytes (10MB = 10 * 1024 * 1024).
|
|
73
|
+
* @constant {number}
|
|
74
|
+
*/
|
|
75
|
+
export declare const MAX_ACCOUNT_SIZE = 10485760;
|
|
76
|
+
/**
|
|
77
|
+
* Maximum number of Arcium embiggen instructions allowed in a single transaction (due to compute unit limits).
|
|
78
|
+
* @constant {number}
|
|
79
|
+
*/
|
|
80
|
+
export declare const MAX_EMBIGGEN_IX_PER_TX = 18;
|
|
81
|
+
/**
|
|
82
|
+
* Size of account discriminator in bytes.
|
|
83
|
+
* @constant {number}
|
|
84
|
+
*/
|
|
85
|
+
export declare const DISCRIMINATOR_SIZE = 8;
|
|
86
|
+
/**
|
|
87
|
+
* Size of offset buffer in bytes (u32).
|
|
88
|
+
* @constant {number}
|
|
89
|
+
*/
|
|
90
|
+
export declare const OFFSET_BUFFER_SIZE = 4;
|
|
91
|
+
/**
|
|
92
|
+
* Size of computation definition offset slice in bytes.
|
|
93
|
+
* @constant {number}
|
|
94
|
+
*/
|
|
95
|
+
export declare const COMP_DEF_OFFSET_SIZE = 4;
|
|
96
|
+
/**
|
|
97
|
+
* Size of a uint128 in bytes.
|
|
98
|
+
* @constant {number}
|
|
99
|
+
*/
|
|
100
|
+
export declare const UINT128_BYTE_SIZE = 16;
|
|
101
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,cAAc,iBAAiB,CAAC;AAC7C;;;GAGG;AACH,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC;;;GAGG;AACH,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AACzD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAC1C;;;GAGG;AACH,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAC7C;;;GAGG;AACH,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAC1C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAC3C;;;GAGG;AACH,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAC7C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,iCAAiC,CAAC;AAChE;;;GAGG;AACH,eAAO,MAAM,yBAAyB,2BAA2B,CAAC;AAClE;;;GAGG;AACH,eAAO,MAAM,qBAAqB,uBAAuB,CAAC;AAC1D;;;GAGG;AACH,eAAO,MAAM,oBAAoB,6BAA6B,CAAC;AAC/D;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AACxC;;;GAGG;AACH,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAC3C;;;GAGG;AACH,eAAO,MAAM,gBAAgB,WAAW,CAAC;AACzC;;;GAGG;AACH,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC;;;GAGG;AACH,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC;;;GAGG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAEtC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,KAAK,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AesCtrCipher } from './aesCtrCipher.js';
|
|
2
|
+
/**
|
|
3
|
+
* AES-128 cipher in Counter (CTR) mode, using SHA3-256 to derive the key from a shared secret.
|
|
4
|
+
* See: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf (Section 6.5) for details on CTR mode.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Aes128Cipher extends AesCtrCipher {
|
|
7
|
+
/**
|
|
8
|
+
* Construct an AES-128 cipher instance using a shared secret.
|
|
9
|
+
* The key is derived using SHA3-256.
|
|
10
|
+
* @param sharedSecret - Shared secret to derive the AES key from.
|
|
11
|
+
*/
|
|
12
|
+
constructor(sharedSecret: Uint8Array);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=aes128Cipher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes128Cipher.d.ts","sourceRoot":"","sources":["../../../src/cryptography/aes128Cipher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;GAGG;AACH,qBAAa,YAAa,SAAQ,YAAY;IAC1C;;;;OAIG;gBACS,YAAY,EAAE,UAAU;CAGvC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AesCtrCipher } from './aesCtrCipher.js';
|
|
2
|
+
/**
|
|
3
|
+
* AES-192 cipher in Counter (CTR) mode, using SHA3-256 to derive the key from a shared secret.
|
|
4
|
+
* See: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf (Section 6.5) for details on CTR mode.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Aes192Cipher extends AesCtrCipher {
|
|
7
|
+
/**
|
|
8
|
+
* Construct an AES-192 cipher instance using a shared secret.
|
|
9
|
+
* The key is derived using SHA3-256.
|
|
10
|
+
* @param sharedSecret - Shared secret to derive the AES key from.
|
|
11
|
+
*/
|
|
12
|
+
constructor(sharedSecret: Uint8Array);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=aes192Cipher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes192Cipher.d.ts","sourceRoot":"","sources":["../../../src/cryptography/aes192Cipher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;GAGG;AACH,qBAAa,YAAa,SAAQ,YAAY;IAC1C;;;;OAIG;gBACS,YAAY,EAAE,UAAU;CAGvC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AesCtrCipher } from './aesCtrCipher.js';
|
|
2
|
+
/**
|
|
3
|
+
* AES-256 cipher in Counter (CTR) mode, using SHA3-256 to derive the key from a shared secret.
|
|
4
|
+
* See: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf (Section 6.5) for details on CTR mode.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Aes256Cipher extends AesCtrCipher {
|
|
7
|
+
/**
|
|
8
|
+
* Construct an AES-256 cipher instance using a shared secret.
|
|
9
|
+
* The key is derived using SHA3-256.
|
|
10
|
+
* @param sharedSecret - Shared secret to derive the AES key from.
|
|
11
|
+
*/
|
|
12
|
+
constructor(sharedSecret: Uint8Array);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=aes256Cipher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes256Cipher.d.ts","sourceRoot":"","sources":["../../../src/cryptography/aes256Cipher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;GAGG;AACH,qBAAa,YAAa,SAAQ,YAAY;IAC1C;;;;OAIG;gBACS,YAAY,EAAE,UAAU;CAGvC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported AES key sizes in bits.
|
|
3
|
+
*/
|
|
4
|
+
export type AesKeyBits = 128 | 192 | 256;
|
|
5
|
+
/**
|
|
6
|
+
* Generic AES cipher in Counter (CTR) mode, using SHA3-256 to derive the key from a shared secret.
|
|
7
|
+
* See: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf (Section 6.5) for details on CTR mode.
|
|
8
|
+
*/
|
|
9
|
+
export declare class AesCtrCipher {
|
|
10
|
+
protected key: Uint8Array;
|
|
11
|
+
private readonly keyBits;
|
|
12
|
+
/**
|
|
13
|
+
* Construct an AES cipher instance using a shared secret.
|
|
14
|
+
* The key is derived using SHA3-256.
|
|
15
|
+
* @param sharedSecret - Shared secret to derive the AES key from.
|
|
16
|
+
* @param keyBits - AES key size in bits (128, 192, or 256).
|
|
17
|
+
*/
|
|
18
|
+
constructor(sharedSecret: Uint8Array, keyBits: AesKeyBits);
|
|
19
|
+
/**
|
|
20
|
+
* Encrypt the plaintext array in Counter (CTR) mode.
|
|
21
|
+
* @param plaintext - Data to encrypt.
|
|
22
|
+
* @param nonce - 8-byte nonce for CTR mode.
|
|
23
|
+
* @returns Encrypted ciphertext as a Uint8Array.
|
|
24
|
+
* @throws Error if the nonce is not 8 bytes long.
|
|
25
|
+
*/
|
|
26
|
+
encrypt(plaintext: Uint8Array, nonce: Uint8Array): Uint8Array;
|
|
27
|
+
/**
|
|
28
|
+
* Decrypt the ciphertext array in Counter (CTR) mode.
|
|
29
|
+
* @param ciphertext - Data to decrypt.
|
|
30
|
+
* @param nonce - 8-byte nonce for CTR mode.
|
|
31
|
+
* @returns Decrypted plaintext as a Uint8Array.
|
|
32
|
+
* @throws Error if the nonce is not 8 bytes long.
|
|
33
|
+
*/
|
|
34
|
+
decrypt(ciphertext: Uint8Array, nonce: Uint8Array): Uint8Array;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=aesCtrCipher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aesCtrCipher.d.ts","sourceRoot":"","sources":["../../../src/cryptography/aesCtrCipher.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAOzC;;;GAGG;AACH,qBAAa,YAAY;IACrB,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IAErC;;;;;OAKG;gBACS,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU;IAwBzD;;;;;;OAMG;IACH,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,UAAU;IAU7D;;;;;;OAMG;IACH,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,UAAU;CASjE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CurveFn } from '@noble/curves/abstract/edwards';
|
|
2
|
+
/**
|
|
3
|
+
* Ed25519 curve instance using SHA3-512 for hashing, suitable for MPC (ArcisEd25519 signature scheme).
|
|
4
|
+
* This is essentially Ed25519 but with SHA3-512 instead of SHA-512 for lower multiplicative depth.
|
|
5
|
+
* See: https://datatracker.ietf.org/doc/html/rfc8032#section-5.1
|
|
6
|
+
*/
|
|
7
|
+
export declare const arcisEd25519: CurveFn;
|
|
8
|
+
//# sourceMappingURL=arcisEd25519.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arcisEd25519.d.ts","sourceRoot":"","sources":["../../../src/cryptography/arcisEd25519.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAkB,MAAM,gCAAgC,CAAC;AAyBzE;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,OAAwD,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { RescueCipherCommon } from './rescueCipherCommon.js';
|
|
2
|
+
/**
|
|
3
|
+
* The Rescue cipher over Curve25519's scalar field in Counter (CTR) mode, with a fixed block size m = 5.
|
|
4
|
+
* See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
|
|
5
|
+
*/
|
|
6
|
+
export declare class CSplRescueCipher {
|
|
7
|
+
cipher: RescueCipherCommon;
|
|
8
|
+
/**
|
|
9
|
+
* Construct a CSplRescueCipher instance using a shared secret.
|
|
10
|
+
* The key is derived using RescuePrimeHash and used to initialize the RescueDesc.
|
|
11
|
+
* @param sharedSecret - Shared secret to derive the cipher key from.
|
|
12
|
+
*/
|
|
13
|
+
constructor(sharedSecret: Uint8Array);
|
|
14
|
+
/**
|
|
15
|
+
* Encrypt the plaintext vector in Counter (CTR) mode and serialize each block.
|
|
16
|
+
* @param plaintext - Array of plaintext bigints to encrypt.
|
|
17
|
+
* @param nonce - 16-byte nonce for CTR mode.
|
|
18
|
+
* @returns Ciphertext as an array of arrays of numbers (each 32 bytes).
|
|
19
|
+
*/
|
|
20
|
+
encrypt(plaintext: bigint[], nonce: Uint8Array): number[][];
|
|
21
|
+
/**
|
|
22
|
+
* Deserialize and decrypt the ciphertext vector in Counter (CTR) mode.
|
|
23
|
+
* @param ciphertext - Array of arrays of numbers (each 32 bytes) to decrypt.
|
|
24
|
+
* @param nonce - 16-byte nonce for CTR mode.
|
|
25
|
+
* @returns Decrypted plaintext as an array of bigints.
|
|
26
|
+
*/
|
|
27
|
+
decrypt(ciphertext: number[][], nonce: Uint8Array): bigint[];
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=cSplRescueCipher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cSplRescueCipher.d.ts","sourceRoot":"","sources":["../../../src/cryptography/cSplRescueCipher.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;GAGG;AACH,qBAAa,gBAAgB;IACzB,MAAM,EAAE,kBAAkB,CAAC;IAE3B;;;;OAIG;gBACS,YAAY,EAAE,UAAU;IAIpC;;;;;OAKG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,EAAE;IAI3D;;;;;OAKG;IACH,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE;CAG/D"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scalar field prime modulus for Curve25519: 2^252 + 27742317777372353535851937790883648493
|
|
3
|
+
*/
|
|
4
|
+
export declare const CURVE25519_SCALAR_FIELD_MODULUS: bigint;
|
|
5
|
+
/**
|
|
6
|
+
* Generate a random value within the field bound by q.
|
|
7
|
+
* @param q - Upper bound (exclusive) for the random value.
|
|
8
|
+
* @returns Random bigint value between 0 and q-1.
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateRandomFieldElem(q: bigint): bigint;
|
|
11
|
+
/**
|
|
12
|
+
* Compute the positive modulo of a over m.
|
|
13
|
+
* @param a - Dividend.
|
|
14
|
+
* @param m - Modulus.
|
|
15
|
+
* @returns Positive remainder of a mod m.
|
|
16
|
+
*/
|
|
17
|
+
export declare function positiveModulo(a: bigint, m: bigint): bigint;
|
|
18
|
+
/**
|
|
19
|
+
* Serialize a bigint to a little-endian Uint8Array of the specified length.
|
|
20
|
+
* @param val - Bigint value to serialize.
|
|
21
|
+
* @param lengthInBytes - Desired length of the output array.
|
|
22
|
+
* @returns Serialized value as a Uint8Array.
|
|
23
|
+
* @throws Error if the value is too large for the specified length.
|
|
24
|
+
*/
|
|
25
|
+
export declare function serializeLE(val: bigint, lengthInBytes: number): Uint8Array;
|
|
26
|
+
/**
|
|
27
|
+
* Deserialize a little-endian Uint8Array to a bigint.
|
|
28
|
+
* @param bytes - Uint8Array to deserialize.
|
|
29
|
+
* @returns Deserialized bigint value.
|
|
30
|
+
*/
|
|
31
|
+
export declare function deserializeLE(bytes: Uint8Array): bigint;
|
|
32
|
+
/**
|
|
33
|
+
* Compute the SHA-256 hash of an array of Uint8Arrays.
|
|
34
|
+
* @param byteArrays - Arrays to hash.
|
|
35
|
+
* @returns SHA-256 hash as a Buffer.
|
|
36
|
+
*/
|
|
37
|
+
export declare function sha256(byteArrays: Uint8Array[]): Buffer;
|
|
38
|
+
//# sourceMappingURL=cryptography.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cryptography.d.ts","sourceRoot":"","sources":["../../../src/cryptography/cryptography.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,+BAA+B,QAAkB,CAAC;AAE/D;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAQzD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,UAAU,CAc1E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMvD;AAGD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,MAAM,CAMvD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { HMACRescuePrime } from './hmac.js';
|
|
2
|
+
import { FpField } from './rescueDesc.js';
|
|
3
|
+
/**
|
|
4
|
+
* HKDF (HMAC-based Extract-and-Expand Key Derivation Function) using the Rescue-Prime hash function.
|
|
5
|
+
* Follows RFC 5869. Only supports L = HashLen.
|
|
6
|
+
*/
|
|
7
|
+
export declare class HKDFRescuePrime {
|
|
8
|
+
hmac: HMACRescuePrime;
|
|
9
|
+
/**
|
|
10
|
+
* Construct a new HKDFRescuePrime instance.
|
|
11
|
+
*/
|
|
12
|
+
constructor(field: FpField);
|
|
13
|
+
/**
|
|
14
|
+
* HKDF-Extract step: derive a pseudorandom key (PRK) from the input keying material (IKM) and salt.
|
|
15
|
+
* @param salt - Salt value as an array of bigints.
|
|
16
|
+
* @param ikm - Input keying material as an array of bigints.
|
|
17
|
+
* @returns Pseudorandom key (PRK) as an array of bigints.
|
|
18
|
+
*/
|
|
19
|
+
extract(salt: bigint[], ikm: bigint[]): bigint[];
|
|
20
|
+
/**
|
|
21
|
+
* HKDF-Expand step: expand the pseudorandom key (PRK) with info to produce output keying material (OKM).
|
|
22
|
+
* Only supports L = HashLen = 5, i.e. N = 1.
|
|
23
|
+
* @param prk - Pseudorandom key as an array of bigints.
|
|
24
|
+
* @param info - Context and application specific information as an array of bigints.
|
|
25
|
+
* @returns Output keying material (OKM) as an array of bigints.
|
|
26
|
+
*/
|
|
27
|
+
expand(prk: bigint[], info: bigint[]): bigint[];
|
|
28
|
+
/**
|
|
29
|
+
* Perform the full HKDF (extract and expand) to derive output keying material (OKM).
|
|
30
|
+
* @param salt - Salt value as an array of bigints.
|
|
31
|
+
* @param ikm - Input keying material as an array of bigints.
|
|
32
|
+
* @param info - Context and application specific information as an array of bigints.
|
|
33
|
+
* @returns Output keying material (OKM) as an array of bigints.
|
|
34
|
+
*/
|
|
35
|
+
okm(salt: bigint[], ikm: bigint[], info: bigint[]): bigint[];
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=hkdf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hkdf.d.ts","sourceRoot":"","sources":["../../../src/cryptography/hkdf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C;;;GAGG;AACH,qBAAa,eAAe;IACxB,IAAI,EAAE,eAAe,CAAC;IAEtB;;OAEG;gBACS,KAAK,EAAE,OAAO;IAI1B;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAQhD;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAQ/C;;;;;;OAMG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;CAI/D"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FpField } from './rescueDesc.js';
|
|
2
|
+
import { RescuePrimeHash } from './rescuePrimeHash.js';
|
|
3
|
+
/**
|
|
4
|
+
* HMACRescuePrime provides a message authentication code (MAC) using the Rescue-Prime hash function.
|
|
5
|
+
* We refer to https://datatracker.ietf.org/doc/html/rfc2104 for more details.
|
|
6
|
+
*/
|
|
7
|
+
export declare class HMACRescuePrime {
|
|
8
|
+
hasher: RescuePrimeHash;
|
|
9
|
+
/**
|
|
10
|
+
* Construct a new HMACRescuePrime instance.
|
|
11
|
+
*/
|
|
12
|
+
constructor(field: FpField);
|
|
13
|
+
/**
|
|
14
|
+
* Compute the HMAC digest of a message with a given key using Rescue-Prime.
|
|
15
|
+
* @param key - Key as an array of bigints.
|
|
16
|
+
* @param message - Message as an array of bigints.
|
|
17
|
+
* @returns HMAC digest as an array of bigints.
|
|
18
|
+
* @throws Error if the key is shorter than the hash function's digest length or longer than the hash function's rate.
|
|
19
|
+
*/
|
|
20
|
+
digest(key: bigint[], message: bigint[]): bigint[];
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=hmac.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../../../src/cryptography/hmac.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAgBvD;;;GAGG;AACH,qBAAa,eAAe;IACxB,MAAM,EAAE,eAAe,CAAC;IAExB;;OAEG;gBACS,KAAK,EAAE,OAAO;IAI1B;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;CA0BrD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { RescueCipherCommon } from './rescueCipherCommon.js';
|
|
2
|
+
/**
|
|
3
|
+
* The Rescue cipher over Curve25519's base field in Counter (CTR) mode, with a fixed block size m = 5.
|
|
4
|
+
* See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
|
|
5
|
+
*/
|
|
6
|
+
export declare class RescueCipher {
|
|
7
|
+
cipher: RescueCipherCommon;
|
|
8
|
+
/**
|
|
9
|
+
* Construct a RescueCipher instance using a shared secret.
|
|
10
|
+
* The key is derived using RescuePrimeHash and used to initialize the RescueDesc.
|
|
11
|
+
* @param sharedSecret - Shared secret to derive the cipher key from.
|
|
12
|
+
*/
|
|
13
|
+
constructor(sharedSecret: Uint8Array);
|
|
14
|
+
/**
|
|
15
|
+
* Encrypt the plaintext vector in Counter (CTR) mode and serialize each block.
|
|
16
|
+
* @param plaintext - Array of plaintext bigints to encrypt.
|
|
17
|
+
* @param nonce - 16-byte nonce for CTR mode.
|
|
18
|
+
* @returns Ciphertext as an array of arrays of numbers (each 32 bytes).
|
|
19
|
+
*/
|
|
20
|
+
encrypt(plaintext: bigint[], nonce: Uint8Array): number[][];
|
|
21
|
+
/**
|
|
22
|
+
* Deserialize and decrypt the ciphertext vector in Counter (CTR) mode.
|
|
23
|
+
* @param ciphertext - Array of arrays of numbers (each 32 bytes) to decrypt.
|
|
24
|
+
* @param nonce - 16-byte nonce for CTR mode.
|
|
25
|
+
* @returns Decrypted plaintext as an array of bigints.
|
|
26
|
+
*/
|
|
27
|
+
decrypt(ciphertext: number[][], nonce: Uint8Array): bigint[];
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=rescueCipher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rescueCipher.d.ts","sourceRoot":"","sources":["../../../src/cryptography/rescueCipher.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;GAGG;AACH,qBAAa,YAAY;IACrB,MAAM,EAAE,kBAAkB,CAAC;IAE3B;;;;OAIG;gBACS,YAAY,EAAE,UAAU;IAIpC;;;;;OAKG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,EAAE;IAI3D;;;;;OAKG;IACH,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE;CAG/D"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { RescueDesc, FpField } from './rescueDesc.js';
|
|
2
|
+
/**
|
|
3
|
+
* The Rescue cipher in Counter (CTR) mode, with a fixed block size m = 5.
|
|
4
|
+
* See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
|
|
5
|
+
*/
|
|
6
|
+
export declare class RescueCipherCommon {
|
|
7
|
+
desc: RescueDesc;
|
|
8
|
+
/**
|
|
9
|
+
* Construct a RescueCipherCommon instance using a shared secret.
|
|
10
|
+
* The key is derived using RescuePrimeHash and used to initialize the RescueDesc.
|
|
11
|
+
* @param sharedSecret - Shared secret to derive the cipher key from.
|
|
12
|
+
*/
|
|
13
|
+
constructor(sharedSecret: Uint8Array, field: FpField);
|
|
14
|
+
/**
|
|
15
|
+
* Encrypt the plaintext vector in Counter (CTR) mode (raw, returns bigints).
|
|
16
|
+
* @param plaintext - Array of plaintext bigints to encrypt.
|
|
17
|
+
* @param nonce - 16-byte nonce for CTR mode.
|
|
18
|
+
* @returns Ciphertext as an array of bigints.
|
|
19
|
+
* @throws Error if the nonce is not 16 bytes long.
|
|
20
|
+
*/
|
|
21
|
+
encrypt_raw(plaintext: bigint[], nonce: Uint8Array): bigint[];
|
|
22
|
+
/**
|
|
23
|
+
* Encrypt the plaintext vector in Counter (CTR) mode and serialize each block.
|
|
24
|
+
* @param plaintext - Array of plaintext bigints to encrypt.
|
|
25
|
+
* @param nonce - 16-byte nonce for CTR mode.
|
|
26
|
+
* @returns Ciphertext as an array of arrays of numbers (each 32 bytes).
|
|
27
|
+
*/
|
|
28
|
+
encrypt(plaintext: bigint[], nonce: Uint8Array): number[][];
|
|
29
|
+
/**
|
|
30
|
+
* Decrypt the ciphertext vector in Counter (CTR) mode (raw, expects bigints).
|
|
31
|
+
* @param ciphertext - Array of ciphertext bigints to decrypt.
|
|
32
|
+
* @param nonce - 16-byte nonce for CTR mode.
|
|
33
|
+
* @returns Decrypted plaintext as an array of bigints.
|
|
34
|
+
* @throws Error if the nonce is not 16 bytes long.
|
|
35
|
+
*/
|
|
36
|
+
decrypt_raw(ciphertext: bigint[], nonce: Uint8Array): bigint[];
|
|
37
|
+
/**
|
|
38
|
+
* Deserialize and decrypt the ciphertext vector in Counter (CTR) mode.
|
|
39
|
+
* @param ciphertext - Array of arrays of numbers (each 32 bytes) to decrypt.
|
|
40
|
+
* @param nonce - 16-byte nonce for CTR mode.
|
|
41
|
+
* @returns Decrypted plaintext as an array of bigints.
|
|
42
|
+
*/
|
|
43
|
+
decrypt(ciphertext: number[][], nonce: Uint8Array): bigint[];
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=rescueCipherCommon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rescueCipherCommon.d.ts","sourceRoot":"","sources":["../../../src/cryptography/rescueCipherCommon.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EAEV,OAAO,EAEV,MAAM,iBAAiB,CAAC;AAoBzB;;;GAGG;AACH,qBAAa,kBAAkB;IAC3B,IAAI,EAAE,UAAU,CAAC;IAEjB;;;;OAIG;gBACS,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO;IAuCpD;;;;;;OAMG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE;IAwC7D;;;;;OAKG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,EAAE;IAI3D;;;;;;OAMG;IACH,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE;IAqC9D;;;;;OAKG;IACH,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE;CAQ/D"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { IField } from '@noble/curves/abstract/modular';
|
|
2
|
+
import { Matrix } from '../matrix.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents the operational mode for the Rescue cryptographic primitive.
|
|
5
|
+
* Can be either a block cipher mode with a key, or a hash function mode with parameters.
|
|
6
|
+
*/
|
|
7
|
+
type RescueMode = BlockCipher | HashFunction;
|
|
8
|
+
/**
|
|
9
|
+
* Block cipher mode configuration for Rescue.
|
|
10
|
+
* Use a key for encryption/decryption operations.
|
|
11
|
+
*/
|
|
12
|
+
type BlockCipher = {
|
|
13
|
+
kind: 'cipher';
|
|
14
|
+
key: bigint[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Hash function mode configuration for Rescue.
|
|
18
|
+
* @param m - Rate (number of field elements absorbed per round).
|
|
19
|
+
* @param capacity - Capacity (number of field elements in the state that are not directly accessible).
|
|
20
|
+
*/
|
|
21
|
+
type HashFunction = {
|
|
22
|
+
kind: 'hash';
|
|
23
|
+
m: number;
|
|
24
|
+
capacity: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Field type.
|
|
28
|
+
*/
|
|
29
|
+
export type FpField = IField<bigint>;
|
|
30
|
+
/**
|
|
31
|
+
* Curve25519 base field as an IField instance.
|
|
32
|
+
*/
|
|
33
|
+
export declare const CURVE25519_BASE_FIELD: FpField;
|
|
34
|
+
/**
|
|
35
|
+
* Curve25519 scalar field as an IField instance.
|
|
36
|
+
*/
|
|
37
|
+
export declare const CURVE25519_SCALAR_FIELD: FpField;
|
|
38
|
+
/**
|
|
39
|
+
* Description and parameters for the Rescue cipher or hash function, including round constants, MDS matrix, and key schedule.
|
|
40
|
+
* See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
|
|
41
|
+
*/
|
|
42
|
+
export declare class RescueDesc {
|
|
43
|
+
mode: RescueMode;
|
|
44
|
+
field: FpField;
|
|
45
|
+
alpha: bigint;
|
|
46
|
+
alphaInverse: bigint;
|
|
47
|
+
nRounds: number;
|
|
48
|
+
m: number;
|
|
49
|
+
mdsMat: Matrix;
|
|
50
|
+
mdsMatInverse: Matrix;
|
|
51
|
+
roundKeys: Matrix[];
|
|
52
|
+
/**
|
|
53
|
+
* Construct a RescueDesc for a given field and mode (cipher or hash).
|
|
54
|
+
* Initialize round constants, MDS matrix, and key schedule.
|
|
55
|
+
* @param field - Field to use (e.g., CURVE25519_BASE_FIELD).
|
|
56
|
+
* @param mode - Mode: block cipher or hash function.
|
|
57
|
+
*/
|
|
58
|
+
constructor(field: FpField, mode: RescueMode);
|
|
59
|
+
/**
|
|
60
|
+
* Sample round constants for the Rescue permutation, using SHAKE256.
|
|
61
|
+
* @param nRounds - Number of rounds.
|
|
62
|
+
* @returns Array of round constant matrices.
|
|
63
|
+
*/
|
|
64
|
+
sampleConstants(nRounds: number): Matrix[];
|
|
65
|
+
/**
|
|
66
|
+
* Apply the Rescue permutation to a state matrix.
|
|
67
|
+
* @param state - Input state matrix.
|
|
68
|
+
* @returns Permuted state matrix.
|
|
69
|
+
*/
|
|
70
|
+
permute(state: Matrix): Matrix;
|
|
71
|
+
/**
|
|
72
|
+
* Apply the inverse Rescue permutation to a state matrix.
|
|
73
|
+
* @param state - Input state matrix.
|
|
74
|
+
* @returns Inverse-permuted state matrix.
|
|
75
|
+
*/
|
|
76
|
+
permuteInverse(state: Matrix): Matrix;
|
|
77
|
+
}
|
|
78
|
+
export declare function toVec(data: bigint[]): bigint[][];
|
|
79
|
+
export {};
|
|
80
|
+
//# sourceMappingURL=rescueDesc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rescueDesc.d.ts","sourceRoot":"","sources":["../../../src/cryptography/rescueDesc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAU,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC;;;GAGG;AACH,KAAK,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC;AAE7C;;;GAGG;AACH,KAAK,WAAW,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAErD;;;;GAIG;AACH,KAAK,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAErC;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,OAA0B,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,OAA0B,CAAC;AASjE;;;GAGG;AACH,qBAAa,UAAU;IACnB,IAAI,EAAE,UAAU,CAAC;IAEjB,KAAK,EAAE,OAAO,CAAC;IAGf,KAAK,EAAE,MAAM,CAAC;IAGd,YAAY,EAAE,MAAM,CAAC;IAErB,OAAO,EAAE,MAAM,CAAC;IAEhB,CAAC,EAAE,MAAM,CAAC;IAGV,MAAM,EAAE,MAAM,CAAC;IAGf,aAAa,EAAE,MAAM,CAAC;IAGtB,SAAS,EAAE,MAAM,EAAE,CAAC;IAEpB;;;;;OAKG;gBACS,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU;IAuD5C;;;;OAIG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAoF1C;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAW9B;;;;OAIG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAUxC;AAqOD,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,CAMhD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RescueDesc, FpField } from './rescueDesc.js';
|
|
2
|
+
/**
|
|
3
|
+
* The Rescue-Prime hash function, as described in https://eprint.iacr.org/2020/1143.pdf, offering 256 bits
|
|
4
|
+
* of security against collision, preimage and second-preimage attacks for any field of size at least 102 bits.
|
|
5
|
+
* We use the sponge construction with fixed rate = 7 and capacity = 5 (i.e., m = 12), and truncate the
|
|
6
|
+
* output to 5 field elements.
|
|
7
|
+
*/
|
|
8
|
+
export declare class RescuePrimeHash {
|
|
9
|
+
desc: RescueDesc;
|
|
10
|
+
rate: number;
|
|
11
|
+
digestLength: number;
|
|
12
|
+
/**
|
|
13
|
+
* Construct a RescuePrimeHash instance with rate = 7 and capacity = 5.
|
|
14
|
+
*/
|
|
15
|
+
constructor(field: FpField);
|
|
16
|
+
/**
|
|
17
|
+
* Compute the Rescue-Prime hash of a message, with padding as described in Algorithm 2 of the paper.
|
|
18
|
+
* @param message - Input message as an array of bigints.
|
|
19
|
+
* @returns Hash output as an array of bigints (length = digestLength).
|
|
20
|
+
*/
|
|
21
|
+
digest(message: bigint[]): bigint[];
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=rescuePrimeHash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rescuePrimeHash.d.ts","sourceRoot":"","sources":["../../../src/cryptography/rescuePrimeHash.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,OAAO,EACV,MAAM,iBAAiB,CAAC;AAGzB;;;;;GAKG;AACH,qBAAa,eAAe;IACxB,IAAI,EAAE,UAAU,CAAC;IAEjB,IAAI,EAAE,MAAM,CAAC;IAEb,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;gBACS,KAAK,EAAE,OAAO;IAgB1B;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;CA4BtC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constant-time addition of two bigints, using 2's complement representation.
|
|
3
|
+
* @param x - First operand.
|
|
4
|
+
* @param y - Second operand.
|
|
5
|
+
* @param binSize - Number of bits to use in the operation.
|
|
6
|
+
* @returns Sum as a bigint.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ctAdd(x: bigint, y: bigint, binSize: bigint): bigint;
|
|
9
|
+
/**
|
|
10
|
+
* Constant-time subtraction of two bigints, using 2's complement representation.
|
|
11
|
+
* @param x - First operand.
|
|
12
|
+
* @param y - Second operand.
|
|
13
|
+
* @param binSize - Number of bits to use in the operation.
|
|
14
|
+
* @returns Difference as a bigint.
|
|
15
|
+
*/
|
|
16
|
+
export declare function ctSub(x: bigint, y: bigint, binSize: bigint): bigint;
|
|
17
|
+
/**
|
|
18
|
+
* Return the sign bit of a bigint in constant time.
|
|
19
|
+
* @param x - Bigint to check.
|
|
20
|
+
* @param binSize - Bit position to check (typically the highest bit).
|
|
21
|
+
* @returns True if the sign bit is set, false otherwise.
|
|
22
|
+
*/
|
|
23
|
+
export declare function ctSignBit(x: bigint, binSize: bigint): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Constant-time less-than comparison for two bigints.
|
|
26
|
+
* @param x - First operand.
|
|
27
|
+
* @param y - Second operand.
|
|
28
|
+
* @param binSize - Number of bits to use in the operation.
|
|
29
|
+
* @returns True if x < y, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
export declare function ctLt(x: bigint, y: bigint, binSize: bigint): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Constant-time select between two bigints based on a boolean condition.
|
|
34
|
+
* @param b - Condition; if true, select x, otherwise select y.
|
|
35
|
+
* @param x - Value to select if b is true.
|
|
36
|
+
* @param y - Value to select if b is false.
|
|
37
|
+
* @param binSize - Number of bits to use in the operation.
|
|
38
|
+
* @returns Selected bigint.
|
|
39
|
+
*/
|
|
40
|
+
export declare function ctSelect(b: boolean, x: bigint, y: bigint, binSize: bigint): bigint;
|
|
41
|
+
/**
|
|
42
|
+
* Check if a bigint fits in the range -2^binSize <= x < 2^binSize.
|
|
43
|
+
* Not constant-time for arbitrary x, but is constant-time for all inputs for which the function returns true.
|
|
44
|
+
* If you assert your inputs satisfy verifyBinSize(x, binSize), you need not care about the non constant-timeness of this function.
|
|
45
|
+
* @param x - Bigint to check.
|
|
46
|
+
* @param binSize - Number of bits to use in the check.
|
|
47
|
+
* @returns True if x fits in the range, false otherwise.
|
|
48
|
+
*/
|
|
49
|
+
export declare function verifyBinSize(x: bigint, binSize: bigint): boolean;
|
|
50
|
+
//# sourceMappingURL=ctUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ctUtils.d.ts","sourceRoot":"","sources":["../../src/ctUtils.ts"],"names":[],"mappings":"AAkDA;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAGnE;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAQnE;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEnE;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAElF;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAGjE"}
|