@umbra-privacy/sdk 1.0.0 → 2.0.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/README.md +104 -25
- package/dist/{addresses-Brzgurv_.d.ts → addresses-B7HybtbJ.d.ts} +2 -1
- package/dist/{addresses-D_0YAS6B.d.cts → addresses-CTVY1oi7.d.cts} +2 -1
- package/dist/arcium-BXXlryfe.d.cts +20 -0
- package/dist/arcium-BXXlryfe.d.ts +20 -0
- package/dist/chunk-4RHXVBNI.js +203 -0
- package/dist/chunk-4RHXVBNI.js.map +1 -0
- package/dist/chunk-4TZVXB5G.js +324 -0
- package/dist/chunk-4TZVXB5G.js.map +1 -0
- package/dist/chunk-5GUSMQ74.cjs +549 -0
- package/dist/chunk-5GUSMQ74.cjs.map +1 -0
- package/dist/chunk-5KPQXPQM.js +36 -0
- package/dist/chunk-5KPQXPQM.js.map +1 -0
- package/dist/chunk-AXD7LXYY.cjs +405 -0
- package/dist/chunk-AXD7LXYY.cjs.map +1 -0
- package/dist/{chunk-HOEXDXRC.cjs → chunk-BL6WXLPV.cjs} +32 -360
- package/dist/chunk-BL6WXLPV.cjs.map +1 -0
- package/dist/chunk-CFFLOE7D.cjs +598 -0
- package/dist/chunk-CFFLOE7D.cjs.map +1 -0
- package/dist/{chunk-BM7N6N7E.js → chunk-CFTW5WNG.js} +3 -325
- package/dist/chunk-CFTW5WNG.js.map +1 -0
- package/dist/chunk-DD2WCK4C.js +327 -0
- package/dist/chunk-DD2WCK4C.js.map +1 -0
- package/dist/chunk-DMPMQ74B.cjs +246 -0
- package/dist/chunk-DMPMQ74B.cjs.map +1 -0
- package/dist/{chunk-2Q75CQQJ.js → chunk-EEKF4553.js} +2 -2
- package/dist/chunk-EEKF4553.js.map +1 -0
- package/dist/chunk-ENVYYEM4.cjs +113 -0
- package/dist/chunk-ENVYYEM4.cjs.map +1 -0
- package/dist/chunk-FQX6ZYGJ.js +500 -0
- package/dist/chunk-FQX6ZYGJ.js.map +1 -0
- package/dist/chunk-FSK2ICMB.cjs +39 -0
- package/dist/chunk-FSK2ICMB.cjs.map +1 -0
- package/dist/chunk-FZYWLQAF.cjs +355 -0
- package/dist/chunk-FZYWLQAF.cjs.map +1 -0
- package/dist/chunk-GP26R377.js +436 -0
- package/dist/chunk-GP26R377.js.map +1 -0
- package/dist/chunk-HA5FLM63.js +393 -0
- package/dist/chunk-HA5FLM63.js.map +1 -0
- package/dist/chunk-INJ73LXQ.js +1107 -0
- package/dist/chunk-INJ73LXQ.js.map +1 -0
- package/dist/chunk-JPDF7BIT.cjs +10892 -0
- package/dist/chunk-JPDF7BIT.cjs.map +1 -0
- package/dist/{chunk-MDFSBU5W.cjs → chunk-LTCKPTZC.cjs} +2 -351
- package/dist/chunk-LTCKPTZC.cjs.map +1 -0
- package/dist/chunk-MKNCBUFA.js +564 -0
- package/dist/chunk-MKNCBUFA.js.map +1 -0
- package/dist/chunk-NKVMSABR.cjs +207 -0
- package/dist/chunk-NKVMSABR.cjs.map +1 -0
- package/dist/chunk-OFDWNWCL.js +70 -0
- package/dist/chunk-OFDWNWCL.js.map +1 -0
- package/dist/chunk-QJAUUYZU.cjs +331 -0
- package/dist/chunk-QJAUUYZU.cjs.map +1 -0
- package/dist/chunk-RVUYPKKD.js +10750 -0
- package/dist/chunk-RVUYPKKD.js.map +1 -0
- package/dist/chunk-TLR7A64G.js +103 -0
- package/dist/chunk-TLR7A64G.js.map +1 -0
- package/dist/{chunk-MVKTV3FT.cjs → chunk-TQQZGNOI.cjs} +2 -2
- package/dist/chunk-TQQZGNOI.cjs.map +1 -0
- package/dist/chunk-UOFYS6M3.js +219 -0
- package/dist/chunk-UOFYS6M3.js.map +1 -0
- package/dist/chunk-UXMQI6B7.js +2406 -0
- package/dist/chunk-UXMQI6B7.js.map +1 -0
- package/dist/chunk-WN75ORDT.js +571 -0
- package/dist/chunk-WN75ORDT.js.map +1 -0
- package/dist/chunk-Y55PYKXH.cjs +595 -0
- package/dist/chunk-Y55PYKXH.cjs.map +1 -0
- package/dist/chunk-YEZBTYCP.cjs +77 -0
- package/dist/chunk-YEZBTYCP.cjs.map +1 -0
- package/dist/chunk-ZQOIYCGA.cjs +1126 -0
- package/dist/chunk-ZQOIYCGA.cjs.map +1 -0
- package/dist/chunk-ZY3TSHMJ.cjs +2665 -0
- package/dist/chunk-ZY3TSHMJ.cjs.map +1 -0
- package/dist/client-DkVBHMWb.d.cts +2613 -0
- package/dist/client-V4AF6Bz9.d.ts +2613 -0
- package/dist/common/pda/index.cjs +145 -0
- package/dist/common/pda/index.cjs.map +1 -0
- package/dist/common/pda/index.d.cts +1250 -0
- package/dist/common/pda/index.d.ts +1250 -0
- package/dist/common/pda/index.js +8 -0
- package/dist/common/pda/index.js.map +1 -0
- package/dist/constants/index.cjs +38 -164
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +8 -425
- package/dist/constants/index.d.ts +8 -425
- package/dist/constants/index.js +15 -124
- package/dist/constants/index.js.map +1 -1
- package/dist/crypto/index.cjs +583 -0
- package/dist/crypto/index.cjs.map +1 -0
- package/dist/crypto/index.d.cts +6731 -0
- package/dist/crypto/index.d.ts +6731 -0
- package/dist/crypto/index.js +14 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/{cryptography-BTGC72u-.d.ts → cryptography-BFSJcvi6.d.ts} +3 -2465
- package/dist/{cryptography-BTGC72u-.d.cts → cryptography-D6tPDh-Y.d.cts} +3 -2465
- package/dist/errors/index.cjs +64 -54
- package/dist/errors/index.d.cts +7 -797
- package/dist/errors/index.d.ts +7 -797
- package/dist/errors/index.js +3 -1
- package/dist/errors-B9EoPeWV.d.cts +593 -0
- package/dist/errors-B9EoPeWV.d.ts +593 -0
- package/dist/errors-DAIrstEL.d.cts +300 -0
- package/dist/errors-DPNMfyh0.d.ts +300 -0
- package/dist/index-BG0yjL7C.d.cts +6006 -0
- package/dist/index-ByynoyBO.d.ts +6006 -0
- package/dist/index.cjs +5126 -16118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1031 -7685
- package/dist/index.d.ts +1031 -7685
- package/dist/index.js +3219 -14905
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.cts +14 -6
- package/dist/interfaces/index.d.ts +14 -6
- package/dist/interfaces-43cReBcS.d.cts +3346 -0
- package/dist/interfaces-B8xKNl_6.d.ts +997 -0
- package/dist/interfaces-D2NO6kDD.d.cts +997 -0
- package/dist/interfaces-z_xYJlgV.d.ts +3346 -0
- package/dist/math/index.cjs +115 -0
- package/dist/math/index.cjs.map +1 -0
- package/dist/math/index.d.cts +1327 -0
- package/dist/math/index.d.ts +1327 -0
- package/dist/math/index.js +10 -0
- package/dist/math/index.js.map +1 -0
- package/dist/networks-RMd3abPE.d.ts +44 -0
- package/dist/networks-yAoO8peQ.d.cts +44 -0
- package/dist/relayer-NRRMSMNB.js +4 -0
- package/dist/relayer-NRRMSMNB.js.map +1 -0
- package/dist/relayer-RJHEIXJG.cjs +21 -0
- package/dist/relayer-RJHEIXJG.cjs.map +1 -0
- package/dist/solana/index.cjs +56 -0
- package/dist/solana/index.cjs.map +1 -0
- package/dist/solana/index.d.cts +105 -0
- package/dist/solana/index.d.ts +105 -0
- package/dist/solana/index.js +7 -0
- package/dist/solana/index.js.map +1 -0
- package/dist/{index-CLj_zWSD.d.ts → temporal-BbRaEPoO.d.ts} +1 -1
- package/dist/{index-CX6_pIRS.d.cts → temporal-oUj7iCaq.d.cts} +1 -1
- package/dist/transaction-forwarder-5mAMTjw6.d.ts +1155 -0
- package/dist/transaction-forwarder-C6gMUG7a.d.cts +1155 -0
- package/dist/types/index.cjs +232 -231
- package/dist/types/index.d.cts +15 -1485
- package/dist/types/index.d.ts +15 -1485
- package/dist/types/index.js +2 -1
- package/dist/types-BohhvPth.d.cts +87 -0
- package/dist/types-CW0oTT0j.d.ts +87 -0
- package/dist/types-C_V_CaKK.d.cts +2468 -0
- package/dist/types-C_V_CaKK.d.ts +2468 -0
- package/dist/types-Ca7frykr.d.ts +793 -0
- package/dist/types-CuKeoI19.d.cts +1296 -0
- package/dist/types-CxfTIpN9.d.ts +1052 -0
- package/dist/{types-n-sHFcgr.d.ts → types-D1jDUjfN.d.ts} +2 -2
- package/dist/types-DKEDUlH9.d.ts +1296 -0
- package/dist/types-EKuIfxTz.d.cts +1052 -0
- package/dist/{types-BBuELtY8.d.cts → types-IMGYmlv-.d.cts} +2 -2
- package/dist/types-PwNLi_2k.d.cts +793 -0
- package/dist/utils/index.cjs +823 -525
- package/dist/utils/index.d.cts +1711 -4021
- package/dist/utils/index.d.ts +1711 -4021
- package/dist/utils/index.js +9 -3
- package/dist/{versions-D9PqsEvj.d.cts → versions-BRlR36EA.d.cts} +1 -0
- package/dist/{versions-D9PqsEvj.d.ts → versions-BRlR36EA.d.ts} +1 -0
- package/package.json +79 -18
- package/dist/chunk-2Q75CQQJ.js.map +0 -1
- package/dist/chunk-BM7N6N7E.js.map +0 -1
- package/dist/chunk-GXKSUB2U.cjs +0 -4416
- package/dist/chunk-GXKSUB2U.cjs.map +0 -1
- package/dist/chunk-HOEXDXRC.cjs.map +0 -1
- package/dist/chunk-MDFSBU5W.cjs.map +0 -1
- package/dist/chunk-MQY7HDIA.js +0 -600
- package/dist/chunk-MQY7HDIA.js.map +0 -1
- package/dist/chunk-MVKTV3FT.cjs.map +0 -1
- package/dist/chunk-PG2J6V6Y.js +0 -4094
- package/dist/chunk-PG2J6V6Y.js.map +0 -1
- package/dist/chunk-VEGLTTYQ.cjs +0 -621
- package/dist/chunk-VEGLTTYQ.cjs.map +0 -1
- package/dist/chunk-WVHQ46DD.js +0 -758
- package/dist/chunk-WVHQ46DD.js.map +0 -1
- package/dist/index-B9pDY73x.d.ts +0 -12933
- package/dist/index-D33yo0qB.d.cts +0 -12933
- package/dist/networks-C-orpSFW.d.ts +0 -65
- package/dist/networks-FxYERGD1.d.cts +0 -65
|
@@ -0,0 +1,1296 @@
|
|
|
1
|
+
import { S as SubSubBrandedType, b as SubBrandedType, B as Bytes, a as SubSubSubBrandedType, c as SubSubSubSubBrandedType, d as U512LeBytes, e as U256LeBytes } from './types-C_V_CaKK.js';
|
|
2
|
+
import { B as Bn254FieldElement } from './types-CW0oTT0j.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Key Derivation Types
|
|
6
|
+
*
|
|
7
|
+
* This module defines branded types for Curve25519 (Ed25519/X25519) key exchange,
|
|
8
|
+
* Keccak hashing, master seeds, and hierarchical viewing key derivation.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* All types in this module are "branded" nominal types built on top of primitive
|
|
12
|
+
* TypeScript types (`Uint8Array` or `bigint`). Branding prevents accidental
|
|
13
|
+
* cross-use of structurally identical values that have different semantic meanings
|
|
14
|
+
* (e.g., passing an X25519 public key where a private key is expected).
|
|
15
|
+
*
|
|
16
|
+
* ## Type Hierarchy Overview
|
|
17
|
+
*
|
|
18
|
+
* ```
|
|
19
|
+
* Bytes
|
|
20
|
+
* └── X25519Bytes (32 bytes, endianness-agnostic)
|
|
21
|
+
* ├── X25519PrivateKey — secret scalar; never share
|
|
22
|
+
* ├── X25519PublicKey — public curve point; safe to share
|
|
23
|
+
* └── SharedSecret — ECDH output; feed into a KDF before use
|
|
24
|
+
*
|
|
25
|
+
* LeBytes
|
|
26
|
+
* └── U256LeBytes
|
|
27
|
+
* └── Keccak256Hash — 32-byte Keccak-256 digest
|
|
28
|
+
* └── U512LeBytes
|
|
29
|
+
* └── Keccak512Hash — 64-byte Keccak-512 digest
|
|
30
|
+
* ├── MasterSeed — root of the key hierarchy; 64 bytes
|
|
31
|
+
* └── GenerationSeed — ephemeral seed input; 64 bytes
|
|
32
|
+
*
|
|
33
|
+
* bigint
|
|
34
|
+
* └── U256
|
|
35
|
+
* └── Bn254FieldElement
|
|
36
|
+
* ├── MasterViewingKey — < 2^252, views all txs
|
|
37
|
+
* ├── YearlyViewingKey — views one calendar year
|
|
38
|
+
* ├── MonthlyViewingKey — views one calendar month
|
|
39
|
+
* ├── DailyViewingKey — views one calendar day
|
|
40
|
+
* ├── HourlyViewingKey — views one calendar hour
|
|
41
|
+
* ├── MinuteViewingKey — views one calendar minute
|
|
42
|
+
* ├── SecondViewingKey — views one calendar second
|
|
43
|
+
* └── MintViewingKey — views one token (mint)
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* ## Security Model
|
|
47
|
+
*
|
|
48
|
+
* - The `MasterSeed` is the single secret from which all other keys are derived.
|
|
49
|
+
* Compromising it compromises the entire key hierarchy.
|
|
50
|
+
* - KMAC256 domain separation ensures that different derived keys are
|
|
51
|
+
* computationally independent: knowledge of one does not reveal another.
|
|
52
|
+
* - Viewing keys (MVK and sub-keys) grant read-only access to transaction
|
|
53
|
+
* history and can be selectively shared for compliance purposes.
|
|
54
|
+
* - X25519 private keys are used for ECDH with token senders to enable
|
|
55
|
+
* encrypted token account balance decryption.
|
|
56
|
+
*
|
|
57
|
+
* @packageDocumentation
|
|
58
|
+
* @public
|
|
59
|
+
*
|
|
60
|
+
* @module crypto/key-derivation/types
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Exact byte length of X25519 keys and shared secrets.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* X25519 operates on Curve25519 in Montgomery form. All values — private keys,
|
|
68
|
+
* public keys, and ECDH shared secrets — are exactly 32 bytes (256 bits).
|
|
69
|
+
* This constant is used as the canonical length assertion for all X25519 types.
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
declare const X25519_BYTE_LENGTH = 32;
|
|
74
|
+
/**
|
|
75
|
+
* Base branded byte-array type for X25519 key exchange operations.
|
|
76
|
+
*
|
|
77
|
+
* X25519 is an elliptic curve Diffie-Hellman (ECDH) protocol using Curve25519
|
|
78
|
+
* in Montgomery form. All X25519 values (public keys, private keys, shared
|
|
79
|
+
* secrets) are exactly 32 bytes.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* - Size: 32 bytes (256 bits)
|
|
83
|
+
* - Used as the parent brand for X25519PrivateKey, X25519PublicKey, and SharedSecret
|
|
84
|
+
* - Parallel to LeBytes/BeBytes as a sub-brand of Bytes
|
|
85
|
+
* - Endianness-agnostic: the X25519 spec defines a fixed byte ordering
|
|
86
|
+
*
|
|
87
|
+
* ## Type Hierarchy
|
|
88
|
+
* ```
|
|
89
|
+
* Bytes (base)
|
|
90
|
+
* └── X25519Bytes (sub-brand, 32 bytes)
|
|
91
|
+
* ├── X25519PrivateKey
|
|
92
|
+
* ├── X25519PublicKey
|
|
93
|
+
* └── SharedSecret
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @see {@link X25519PrivateKey}
|
|
97
|
+
* @see {@link X25519PublicKey}
|
|
98
|
+
* @see {@link SharedSecret}
|
|
99
|
+
* @see https://cr.yp.to/ecdh/curve25519-20060209.pdf
|
|
100
|
+
* @see https://tools.ietf.org/html/rfc7748
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
type X25519Bytes = SubBrandedType<Bytes, "X25519Bytes">;
|
|
104
|
+
/**
|
|
105
|
+
* X25519 private key for elliptic curve Diffie-Hellman key exchange.
|
|
106
|
+
*
|
|
107
|
+
* A private key is a 32-byte scalar derived from the master seed via KMAC256
|
|
108
|
+
* with domain separator `"UserAccountX25519Keypair"`. It is used together
|
|
109
|
+
* with a counterparty's public key to compute a shared secret.
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* - Size: 32 bytes (256 bits)
|
|
113
|
+
* - MUST be kept secret and never shared or logged
|
|
114
|
+
* - The X25519 algorithm applies RFC 8032 clamping to the scalar during use
|
|
115
|
+
* - In Umbra, private keys are derived deterministically from the master seed;
|
|
116
|
+
* they must never be generated independently with a random number generator
|
|
117
|
+
*
|
|
118
|
+
* ## Security Warning
|
|
119
|
+
*
|
|
120
|
+
* Exposure of this key allows the holder to decrypt all balances encrypted to
|
|
121
|
+
* the corresponding public key. Store it only in memory during use.
|
|
122
|
+
*
|
|
123
|
+
* ## Type Hierarchy
|
|
124
|
+
* ```
|
|
125
|
+
* Bytes (base)
|
|
126
|
+
* └── X25519Bytes (sub-brand, 32 bytes)
|
|
127
|
+
* └── X25519PrivateKey (sub-sub-brand)
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* // Generate a new private key
|
|
133
|
+
* const rawPrivateKey = crypto.getRandomValues(new Uint8Array(32));
|
|
134
|
+
* assertX25519PrivateKey(rawPrivateKey);
|
|
135
|
+
* // rawPrivateKey is now typed as X25519PrivateKey
|
|
136
|
+
*
|
|
137
|
+
* // Derive the public key
|
|
138
|
+
* const publicKey = x25519GetPublicKey(rawPrivateKey);
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @see {@link assertX25519PrivateKey}
|
|
142
|
+
* @see {@link X25519Keypair}
|
|
143
|
+
* @see https://tools.ietf.org/html/rfc7748#section-5
|
|
144
|
+
* @public
|
|
145
|
+
*/
|
|
146
|
+
type X25519PrivateKey = SubSubBrandedType<X25519Bytes, "X25519PrivateKey">;
|
|
147
|
+
/**
|
|
148
|
+
* X25519 public key for elliptic curve Diffie-Hellman key exchange.
|
|
149
|
+
*
|
|
150
|
+
* A public key is a 32-byte Montgomery curve point derived from a private key
|
|
151
|
+
* via scalar multiplication of the Curve25519 base point. It is stored on-chain
|
|
152
|
+
* in the encrypted token account and used by token senders to encrypt balances
|
|
153
|
+
* for the account holder.
|
|
154
|
+
*
|
|
155
|
+
* @remarks
|
|
156
|
+
* - Size: 32 bytes (256 bits)
|
|
157
|
+
* - Safe to transmit over insecure channels and store on-chain
|
|
158
|
+
* - Derived from the corresponding X25519PrivateKey
|
|
159
|
+
* - Used as input to X25519 ECDH: both parties independently compute the same shared secret
|
|
160
|
+
*
|
|
161
|
+
* ## Type Hierarchy
|
|
162
|
+
* ```
|
|
163
|
+
* Bytes (base)
|
|
164
|
+
* └── X25519Bytes (sub-brand, 32 bytes)
|
|
165
|
+
* └── X25519PublicKey (sub-sub-brand)
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* // Receive a public key from another party
|
|
171
|
+
* const theirPublicKey = receivePublicKey();
|
|
172
|
+
* assertX25519PublicKey(theirPublicKey);
|
|
173
|
+
* // theirPublicKey is now typed as X25519PublicKey
|
|
174
|
+
*
|
|
175
|
+
* // Compute shared secret
|
|
176
|
+
* const sharedSecret = x25519(myPrivateKey, theirPublicKey);
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @see {@link assertX25519PublicKey}
|
|
180
|
+
* @see {@link X25519Keypair}
|
|
181
|
+
* @see https://tools.ietf.org/html/rfc7748#section-5
|
|
182
|
+
* @public
|
|
183
|
+
*/
|
|
184
|
+
type X25519PublicKey = SubSubBrandedType<X25519Bytes, "X25519PublicKey">;
|
|
185
|
+
/**
|
|
186
|
+
* ECDH shared secret produced by an X25519 key exchange operation.
|
|
187
|
+
*
|
|
188
|
+
* This type represents the raw 32-byte output of `X25519(privateKey, publicKey)`.
|
|
189
|
+
* Both communicating parties independently compute the same shared secret by
|
|
190
|
+
* swapping the public key and private key roles.
|
|
191
|
+
*
|
|
192
|
+
* @remarks
|
|
193
|
+
* - Size: 32 bytes (256 bits)
|
|
194
|
+
* - MUST be processed by a Key Derivation Function (KDF) before use as an
|
|
195
|
+
* encryption key. Raw shared secrets have low-order bits that are not
|
|
196
|
+
* uniformly distributed.
|
|
197
|
+
* - Never transmit, log, or store the raw shared secret.
|
|
198
|
+
*
|
|
199
|
+
* ## Security Warning
|
|
200
|
+
*
|
|
201
|
+
* Do not use the raw shared secret directly as an AES or ChaCha20 key. Always
|
|
202
|
+
* derive a symmetric key using a proper KDF (e.g., HKDF or KMAC256).
|
|
203
|
+
*
|
|
204
|
+
* ## Type Hierarchy
|
|
205
|
+
* ```
|
|
206
|
+
* Bytes (base)
|
|
207
|
+
* └── X25519Bytes (sub-brand, 32 bytes)
|
|
208
|
+
* └── SharedSecret (sub-sub-brand)
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* // After performing X25519 key exchange
|
|
214
|
+
* const rawSharedSecret = x25519(myPrivateKey, theirPublicKey);
|
|
215
|
+
* assertSharedSecret(rawSharedSecret);
|
|
216
|
+
* // rawSharedSecret is now typed as SharedSecret
|
|
217
|
+
*
|
|
218
|
+
* // Derive an encryption key from the shared secret (required)
|
|
219
|
+
* const encryptionKey = kdf(rawSharedSecret);
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* @see {@link assertSharedSecret}
|
|
223
|
+
* @see https://tools.ietf.org/html/rfc7748#section-6
|
|
224
|
+
* @public
|
|
225
|
+
*/
|
|
226
|
+
type SharedSecret = SubSubBrandedType<X25519Bytes, "SharedSecret">;
|
|
227
|
+
/**
|
|
228
|
+
* An X25519 key pair consisting of a private key and its corresponding public key.
|
|
229
|
+
*
|
|
230
|
+
* X25519 is an elliptic curve Diffie-Hellman (ECDH) protocol using Curve25519
|
|
231
|
+
* in Montgomery form. In Umbra, this keypair is derived deterministically from
|
|
232
|
+
* the master seed and is used to establish shared secrets with token senders,
|
|
233
|
+
* enabling the account holder to decrypt their encrypted balance.
|
|
234
|
+
*
|
|
235
|
+
* @remarks
|
|
236
|
+
* ## Key Generation
|
|
237
|
+
* - Private key: 32 bytes derived via KMAC256 from the master seed
|
|
238
|
+
* - Public key: Scalar multiplication of the private key with the Curve25519 base point
|
|
239
|
+
*
|
|
240
|
+
* ## Security Properties
|
|
241
|
+
* - Private key MUST be kept secret; it enables decryption of all balances sent to this account
|
|
242
|
+
* - Public key can be freely shared and is stored on-chain in the token account PDA
|
|
243
|
+
* - Shared secret is computed as: `X25519(myPrivate, senderPublic)` — symmetric by construction
|
|
244
|
+
* - Compromise of the private key does not reveal the master seed or other derived keys
|
|
245
|
+
*
|
|
246
|
+
* ## Use Cases in Umbra
|
|
247
|
+
* - `registerTokenPublicKey`: The public key is registered on-chain for a token account
|
|
248
|
+
* - Balance decryption: The private key is used to decrypt AES-GCM ciphertexts from senders
|
|
249
|
+
* - ECDH with ephemeral sender keys for forward secrecy of individual transfers
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* import { X25519Keypair, generateX25519Keypair } from "./cryptography";
|
|
254
|
+
*
|
|
255
|
+
* // Generate a new keypair
|
|
256
|
+
* const keypair: X25519Keypair = await generateX25519Keypair();
|
|
257
|
+
*
|
|
258
|
+
* // Share public key with peer
|
|
259
|
+
* sendPublicKey(peer, keypair.publicKey);
|
|
260
|
+
*
|
|
261
|
+
* // Compute shared secret with peer's public key
|
|
262
|
+
* const sharedSecret = x25519(keypair.privateKey, peerPublicKey);
|
|
263
|
+
* ```
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* // Ephemeral key exchange for forward secrecy
|
|
268
|
+
* const ephemeralKeypair: X25519Keypair = await generateX25519Keypair();
|
|
269
|
+
*
|
|
270
|
+
* // Use ephemeral keypair for this session only
|
|
271
|
+
* const sessionKey = deriveSessionKey(
|
|
272
|
+
* x25519(ephemeralKeypair.privateKey, recipientPublicKey)
|
|
273
|
+
* );
|
|
274
|
+
*
|
|
275
|
+
* // Discard private key after use for forward secrecy
|
|
276
|
+
* ```
|
|
277
|
+
*
|
|
278
|
+
* @see {@link assertX25519Keypair}
|
|
279
|
+
* @see {@link X25519PrivateKey}
|
|
280
|
+
* @see {@link X25519PublicKey}
|
|
281
|
+
* @public
|
|
282
|
+
*/
|
|
283
|
+
interface X25519Keypair {
|
|
284
|
+
/**
|
|
285
|
+
* The X25519 private key (32 bytes).
|
|
286
|
+
*
|
|
287
|
+
* This key MUST be kept secret. It is used to:
|
|
288
|
+
* - Compute shared secrets with other parties' public keys
|
|
289
|
+
* - Derive the corresponding public key
|
|
290
|
+
*
|
|
291
|
+
* @remarks
|
|
292
|
+
* The private key is derived from the master seed via KMAC256 with the
|
|
293
|
+
* domain separator `"UserAccountX25519Keypair"`. The X25519 algorithm applies
|
|
294
|
+
* RFC 8032 §5.1.5 clamping to the scalar during use.
|
|
295
|
+
*
|
|
296
|
+
* @readonly
|
|
297
|
+
*/
|
|
298
|
+
readonly privateKey: X25519PrivateKey;
|
|
299
|
+
/**
|
|
300
|
+
* The X25519 public key (32 bytes).
|
|
301
|
+
*
|
|
302
|
+
* This key can be freely shared. It is:
|
|
303
|
+
* - Computed from the private key via scalar multiplication with the base point
|
|
304
|
+
* - Used by other parties to compute shared secrets with their own private key
|
|
305
|
+
* - Stored on-chain in the Umbra token account PDA
|
|
306
|
+
* - Safe to transmit over insecure channels
|
|
307
|
+
*
|
|
308
|
+
* @readonly
|
|
309
|
+
*/
|
|
310
|
+
readonly publicKey: X25519PublicKey;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Ed25519 keypair for digital signatures on the Edwards form of Curve25519.
|
|
314
|
+
*
|
|
315
|
+
* Ed25519 is the signing scheme defined in RFC 8032. In Umbra, an Ed25519
|
|
316
|
+
* keypair is derived from the same 32-byte seed as the corresponding X25519
|
|
317
|
+
* keypair (they are related via the birational equivalence of Curve25519 in
|
|
318
|
+
* Edwards vs Montgomery form). The Ed25519 public key is used as the on-chain
|
|
319
|
+
* signer identity in registration transactions.
|
|
320
|
+
*
|
|
321
|
+
* @remarks
|
|
322
|
+
* ## Key Derivation
|
|
323
|
+
* - Seed: First 32 bytes of a 64-byte KMAC256 output keyed by the master seed
|
|
324
|
+
* - Public key: Derived via `ed25519.getPublicKey(seed)`; uses SHA-512 internally
|
|
325
|
+
* - The relationship to X25519: the Ed25519 public key can be converted to the
|
|
326
|
+
* Montgomery form via `ed25519.utils.toMontgomery(edPublicKey)`
|
|
327
|
+
*
|
|
328
|
+
* ## Relationship to X25519
|
|
329
|
+
* - Ed25519 uses compressed Edwards curve coordinates
|
|
330
|
+
* - X25519 uses Montgomery curve coordinates
|
|
331
|
+
* - Both represent points on the same underlying elliptic curve (Curve25519)
|
|
332
|
+
* - The birational map between them is cheap and deterministic
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* import { ed25519 } from "@noble/curves/ed25519";
|
|
337
|
+
*
|
|
338
|
+
* const seed = crypto.getRandomValues(new Uint8Array(32));
|
|
339
|
+
* const publicKey = ed25519.getPublicKey(seed);
|
|
340
|
+
*
|
|
341
|
+
* const keypair: Ed25519Keypair = { seed, publicKey };
|
|
342
|
+
* ```
|
|
343
|
+
*
|
|
344
|
+
* @see {@link assertEd25519Keypair}
|
|
345
|
+
* @see {@link Curve25519KeypairResult}
|
|
346
|
+
* @public
|
|
347
|
+
*/
|
|
348
|
+
interface Ed25519Keypair {
|
|
349
|
+
/**
|
|
350
|
+
* The Ed25519 private key seed (32 bytes).
|
|
351
|
+
*
|
|
352
|
+
* This is the raw 32-byte seed from which both the signing scalar and the
|
|
353
|
+
* public key are derived (via SHA-512 key expansion defined in RFC 8032).
|
|
354
|
+
* MUST be kept secret.
|
|
355
|
+
*/
|
|
356
|
+
readonly seed: Uint8Array;
|
|
357
|
+
/**
|
|
358
|
+
* The Ed25519 public key (32 bytes).
|
|
359
|
+
*
|
|
360
|
+
* A compressed Edwards curve point derived from the seed via SHA-512 key
|
|
361
|
+
* expansion and scalar multiplication. Can be freely shared and is used
|
|
362
|
+
* as the on-chain signer identity.
|
|
363
|
+
*/
|
|
364
|
+
readonly publicKey: Uint8Array;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Combined Curve25519 keypair result containing both Ed25519 and X25519 keypairs.
|
|
368
|
+
*
|
|
369
|
+
* This interface represents the result of deriving both Ed25519 (Edwards curve)
|
|
370
|
+
* and X25519 (Montgomery curve) keypairs from a single 32-byte seed. Both
|
|
371
|
+
* keypairs are cryptographically linked through the same underlying Curve25519
|
|
372
|
+
* and are derived together for efficiency.
|
|
373
|
+
*
|
|
374
|
+
* @remarks
|
|
375
|
+
* ## Derivation Pipeline
|
|
376
|
+
*
|
|
377
|
+
* 1. **Ed25519 Keypair**:
|
|
378
|
+
* - Input: First 32 bytes of a 64-byte KMAC256 output
|
|
379
|
+
* - Output: Ed25519 public key via `ed25519.getPublicKey(seed)`
|
|
380
|
+
*
|
|
381
|
+
* 2. **X25519 Keypair**:
|
|
382
|
+
* - Hash seed with SHA-512 → 64 bytes
|
|
383
|
+
* - Clamp first 32 bytes per RFC 8032 §5.1.5
|
|
384
|
+
* - Use clamped bytes as X25519 private key
|
|
385
|
+
* - Derive X25519 public key via birational map: `ed25519.utils.toMontgomery(ed25519Pub)`
|
|
386
|
+
*
|
|
387
|
+
* ## Security Properties
|
|
388
|
+
*
|
|
389
|
+
* - **Deterministic**: Same master seed always produces the same keypairs
|
|
390
|
+
* - **Domain Separated**: Independent from all other key derivations via KMAC256
|
|
391
|
+
* - **Cryptographically Linked**: Both keypairs share the same Curve25519 foundation
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```typescript
|
|
395
|
+
* import { getUserAccountX25519KeypairDeriver } from "@umbra-privacy/sdk";
|
|
396
|
+
*
|
|
397
|
+
* const generator = getUserAccountX25519KeypairDeriver({ client });
|
|
398
|
+
* const result: Curve25519KeypairResult = await generator();
|
|
399
|
+
*
|
|
400
|
+
* // Use Ed25519 for signing
|
|
401
|
+
* const signature = ed25519.sign(message, result.ed25519Keypair.seed);
|
|
402
|
+
*
|
|
403
|
+
* // Use X25519 for key exchange
|
|
404
|
+
* const sharedSecret = x25519.getSharedSecret(
|
|
405
|
+
* result.x25519Keypair.privateKey,
|
|
406
|
+
* peerPublicKey
|
|
407
|
+
* );
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* @see {@link Ed25519Keypair}
|
|
411
|
+
* @see {@link X25519Keypair}
|
|
412
|
+
* @see {@link assertCurve25519KeypairResult}
|
|
413
|
+
* @public
|
|
414
|
+
*/
|
|
415
|
+
interface Curve25519KeypairResult {
|
|
416
|
+
/**
|
|
417
|
+
* Ed25519 keypair for digital signatures.
|
|
418
|
+
*
|
|
419
|
+
* Contains the 32-byte seed and the derived 32-byte compressed Edwards
|
|
420
|
+
* public key. Used as the on-chain signer for registration transactions.
|
|
421
|
+
*/
|
|
422
|
+
readonly ed25519Keypair: Ed25519Keypair;
|
|
423
|
+
/**
|
|
424
|
+
* X25519 keypair for Diffie-Hellman key exchange.
|
|
425
|
+
*
|
|
426
|
+
* Contains the RFC 8032-clamped 32-byte private key (derived from SHA-512
|
|
427
|
+
* of the Ed25519 seed) and the derived 32-byte Montgomery public key (via
|
|
428
|
+
* birational conversion from the Ed25519 public key).
|
|
429
|
+
*/
|
|
430
|
+
readonly x25519Keypair: X25519Keypair;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Output of the Keccak-256 (pre-NIST SHA3-256) hash function.
|
|
434
|
+
*
|
|
435
|
+
* Keccak-256 produces a 256-bit (32-byte) digest. It is widely used in
|
|
436
|
+
* Ethereum-ecosystem applications and is distinct from the NIST standardized
|
|
437
|
+
* SHA3-256 (which uses a different padding rule).
|
|
438
|
+
*
|
|
439
|
+
* @remarks
|
|
440
|
+
* - Always exactly 32 bytes (256 bits)
|
|
441
|
+
* - Stored in little-endian byte order as a branded U256LeBytes
|
|
442
|
+
* - Collision-resistant and preimage-resistant under standard assumptions
|
|
443
|
+
* - NOT the same as NIST SHA3-256: uses original Keccak padding (0x01 vs 0x06)
|
|
444
|
+
*
|
|
445
|
+
* ## Type Hierarchy
|
|
446
|
+
* ```
|
|
447
|
+
* Bytes (base branded type)
|
|
448
|
+
* └── LeBytes (little-endian sub-brand)
|
|
449
|
+
* └── U256LeBytes (256-bit sized sub-sub-brand)
|
|
450
|
+
* └── Keccak256Hash (hash-specific sub-sub-sub-brand)
|
|
451
|
+
* ```
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```typescript
|
|
455
|
+
* import { assertKeccak256Hash, Keccak256Hash } from "./cryptography";
|
|
456
|
+
*
|
|
457
|
+
* const hashBytes = keccak256(data);
|
|
458
|
+
* assertKeccak256Hash(hashBytes);
|
|
459
|
+
* // hashBytes is now typed as Keccak256Hash
|
|
460
|
+
* ```
|
|
461
|
+
*
|
|
462
|
+
* @see {@link assertKeccak256Hash}
|
|
463
|
+
* @public
|
|
464
|
+
*/
|
|
465
|
+
type Keccak256Hash = SubSubSubBrandedType<U256LeBytes, "Keccak256Hash">;
|
|
466
|
+
/**
|
|
467
|
+
* Output of the Keccak-512 (pre-NIST SHA3-512) hash function.
|
|
468
|
+
*
|
|
469
|
+
* Keccak-512 produces a 512-bit (64-byte) digest, providing a higher security
|
|
470
|
+
* margin than Keccak-256. In Umbra, it is used as the basis for master seed
|
|
471
|
+
* generation: high-entropy user input is hashed with Keccak-512 to produce
|
|
472
|
+
* the canonical 64-byte master seed.
|
|
473
|
+
*
|
|
474
|
+
* @remarks
|
|
475
|
+
* - Always exactly 64 bytes (512 bits)
|
|
476
|
+
* - Stored in little-endian byte order as a branded U512LeBytes
|
|
477
|
+
* - Provides 256-bit pre-image security and 256-bit collision resistance
|
|
478
|
+
* - Used as the foundation for {@link MasterSeed} and {@link GenerationSeed}
|
|
479
|
+
*
|
|
480
|
+
* ## Type Hierarchy
|
|
481
|
+
* ```
|
|
482
|
+
* Bytes (base branded type)
|
|
483
|
+
* └── LeBytes (little-endian sub-brand)
|
|
484
|
+
* └── U512LeBytes (512-bit sized sub-sub-brand)
|
|
485
|
+
* └── Keccak512Hash (hash-specific sub-sub-sub-brand)
|
|
486
|
+
* ```
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* import { assertKeccak512Hash, Keccak512Hash } from "./cryptography";
|
|
491
|
+
*
|
|
492
|
+
* const hashBytes = keccak512(entropy);
|
|
493
|
+
* assertKeccak512Hash(hashBytes);
|
|
494
|
+
* // hashBytes is now typed as Keccak512Hash
|
|
495
|
+
* ```
|
|
496
|
+
*
|
|
497
|
+
* @see {@link assertKeccak512Hash}
|
|
498
|
+
* @see {@link MasterSeed}
|
|
499
|
+
* @public
|
|
500
|
+
*/
|
|
501
|
+
type Keccak512Hash = SubSubSubBrandedType<U512LeBytes, "Keccak512Hash">;
|
|
502
|
+
/**
|
|
503
|
+
* Strict upper bound for master viewing key values (exclusive).
|
|
504
|
+
*
|
|
505
|
+
* @remarks
|
|
506
|
+
* Master viewing keys are constrained to be strictly less than 2^252 (rather
|
|
507
|
+
* than the full BN254 field prime which is close to 2^254). This tighter bound
|
|
508
|
+
* is required for compatibility with ZK circuits that perform range checks on
|
|
509
|
+
* field element inputs. After KMAC256 derivation, the raw value is ANDed with
|
|
510
|
+
* `2^252 - 1` to enforce the constraint.
|
|
511
|
+
*
|
|
512
|
+
* @see {@link MasterViewingKey}
|
|
513
|
+
* @see {@link assertMasterViewingKey}
|
|
514
|
+
* @public
|
|
515
|
+
*/
|
|
516
|
+
declare const MASTER_VIEWING_KEY_MAX: bigint;
|
|
517
|
+
/**
|
|
518
|
+
* Master seed for hierarchical deterministic key derivation.
|
|
519
|
+
*
|
|
520
|
+
* The master seed is the root secret of the entire Umbra key hierarchy. All
|
|
521
|
+
* other keys — X25519 keypairs, Poseidon keys, master viewing key, and all
|
|
522
|
+
* time-scoped viewing keys — are derived from it deterministically via KMAC256.
|
|
523
|
+
*
|
|
524
|
+
* @remarks
|
|
525
|
+
* - Always exactly 64 bytes (512 bits)
|
|
526
|
+
* - Generated by hashing high-entropy user input with Keccak-512
|
|
527
|
+
* - MUST be kept secret at all times; its compromise reveals all derived keys
|
|
528
|
+
* - Should originate from at least 256 bits of cryptographically secure entropy
|
|
529
|
+
* - Can reconstruct the full key hierarchy when combined with the client's version
|
|
530
|
+
* and network metadata
|
|
531
|
+
*
|
|
532
|
+
* ## Security Considerations
|
|
533
|
+
* - Store securely and encrypted at rest (e.g., hardware-backed keystore)
|
|
534
|
+
* - Never log, transmit over insecure channels, or expose in error messages
|
|
535
|
+
* - Consider hardware security module (HSM) integration for production deployments
|
|
536
|
+
* - Backup procedures should use offline, air-gapped storage
|
|
537
|
+
*
|
|
538
|
+
* ## Type Hierarchy
|
|
539
|
+
* ```
|
|
540
|
+
* Bytes (base)
|
|
541
|
+
* └── LeBytes
|
|
542
|
+
* └── U512LeBytes
|
|
543
|
+
* └── Keccak512Hash
|
|
544
|
+
* └── MasterSeed
|
|
545
|
+
* ```
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* ```typescript
|
|
549
|
+
* import { assertMasterSeed, MasterSeed } from "./cryptography";
|
|
550
|
+
*
|
|
551
|
+
* // Generate master seed from entropy
|
|
552
|
+
* const entropy = crypto.getRandomValues(new Uint8Array(32));
|
|
553
|
+
* const seedBytes = keccak512(entropy);
|
|
554
|
+
* assertMasterSeed(seedBytes);
|
|
555
|
+
* // seedBytes is now typed as MasterSeed
|
|
556
|
+
*
|
|
557
|
+
* // Derive master viewing key
|
|
558
|
+
* const masterViewingKey = deriveMasterViewingKey(seedBytes);
|
|
559
|
+
* ```
|
|
560
|
+
*
|
|
561
|
+
* @see {@link assertMasterSeed}
|
|
562
|
+
* @see {@link MasterViewingKey}
|
|
563
|
+
* @public
|
|
564
|
+
*/
|
|
565
|
+
type MasterSeed = SubSubSubSubBrandedType<Keccak512Hash, "MasterSeed">;
|
|
566
|
+
/**
|
|
567
|
+
* Generation seed for ephemeral single-use key derivation.
|
|
568
|
+
*
|
|
569
|
+
* A generation seed serves as input to the ephemeral master seed generator,
|
|
570
|
+
* producing a single-use 64-byte value from which an ephemeral key sub-hierarchy
|
|
571
|
+
* can be derived. Using a generation seed instead of the master seed directly
|
|
572
|
+
* prevents long-lived secrets from being exposed in ephemeral operations.
|
|
573
|
+
*
|
|
574
|
+
* @remarks
|
|
575
|
+
* - Always exactly 64 bytes (512 bits)
|
|
576
|
+
* - Derived from external entropy or protocol-specific deterministic data
|
|
577
|
+
* - Semantically distinct from MasterSeed: it is an input, not a derived root
|
|
578
|
+
* - After all required ephemeral keys are derived, the generation seed should
|
|
579
|
+
* be discarded to limit its exposure window
|
|
580
|
+
*
|
|
581
|
+
* ## Type Hierarchy
|
|
582
|
+
* ```
|
|
583
|
+
* Bytes (base)
|
|
584
|
+
* └── LeBytes
|
|
585
|
+
* └── U512LeBytes
|
|
586
|
+
* └── Keccak512Hash
|
|
587
|
+
* └── GenerationSeed
|
|
588
|
+
* ```
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* ```typescript
|
|
592
|
+
* import { assertGenerationSeed, GenerationSeed } from "./cryptography";
|
|
593
|
+
*
|
|
594
|
+
* // Create generation seed from protocol data
|
|
595
|
+
* const seedBytes = keccak512(protocolData);
|
|
596
|
+
* assertGenerationSeed(seedBytes);
|
|
597
|
+
* // seedBytes is now typed as GenerationSeed
|
|
598
|
+
*
|
|
599
|
+
* // Use to generate ephemeral master seed
|
|
600
|
+
* const ephemeralSeed = generateEphemeralMasterSeed(seedBytes);
|
|
601
|
+
* ```
|
|
602
|
+
*
|
|
603
|
+
* @see {@link assertGenerationSeed}
|
|
604
|
+
* @see {@link MasterSeed}
|
|
605
|
+
* @public
|
|
606
|
+
*/
|
|
607
|
+
type GenerationSeed = SubSubSubSubBrandedType<Keccak512Hash, "GenerationSeed">;
|
|
608
|
+
/**
|
|
609
|
+
* Master viewing key (MVK) for full privacy-preserving transaction visibility.
|
|
610
|
+
*
|
|
611
|
+
* The master viewing key is derived from the master seed via KMAC256 and serves
|
|
612
|
+
* as the root of a Poseidon-based hierarchical viewing key tree. Holding the MVK
|
|
613
|
+
* allows an auditor or compliance tool to view ALL transactions across ALL tokens
|
|
614
|
+
* and ALL time periods, without gaining spending capability.
|
|
615
|
+
*
|
|
616
|
+
* @remarks
|
|
617
|
+
* - Element of the BN254 scalar field, constrained to be < 2^252
|
|
618
|
+
* - Derived deterministically from the master seed using KMAC256
|
|
619
|
+
* - Derivation: `KMAC256(key="Umbra Privacy - MasterViewingKey - {offset}", msg=masterSeed)`, then ANDed with `2^252 - 1`
|
|
620
|
+
* - The 252-bit constraint ensures compatibility with ZK circuits
|
|
621
|
+
* - Can be shared to grant full read-only access to the user's history
|
|
622
|
+
*
|
|
623
|
+
* ## Type Hierarchy
|
|
624
|
+
* All viewing keys are siblings under Bn254FieldElement (NOT subbrands of each other):
|
|
625
|
+
* ```
|
|
626
|
+
* bigint (base)
|
|
627
|
+
* └── U256 (SubBrandedType)
|
|
628
|
+
* └── Bn254FieldElement (SubSubBrandedType)
|
|
629
|
+
* ├── MasterViewingKey (SubSubSubBrandedType)
|
|
630
|
+
* ├── YearlyViewingKey
|
|
631
|
+
* ├── MonthlyViewingKey
|
|
632
|
+
* ├── DailyViewingKey
|
|
633
|
+
* ├── HourlyViewingKey
|
|
634
|
+
* ├── MinuteViewingKey
|
|
635
|
+
* ├── SecondViewingKey
|
|
636
|
+
* └── MintViewingKey
|
|
637
|
+
* ```
|
|
638
|
+
*
|
|
639
|
+
* ## Derivation Hierarchy (NOT type hierarchy)
|
|
640
|
+
* ```
|
|
641
|
+
* MasterSeed
|
|
642
|
+
* └── MasterViewingKey (views all time, all tokens)
|
|
643
|
+
* └── MintViewingKey = Poseidon(MVK, mintLow, mintHigh)
|
|
644
|
+
* └── YearlyViewingKey = Poseidon(MintVK, year)
|
|
645
|
+
* └── MonthlyViewingKey = Poseidon(YearlyVK, month)
|
|
646
|
+
* └── DailyViewingKey = Poseidon(MonthlyVK, day)
|
|
647
|
+
* └── HourlyViewingKey = Poseidon(DailyVK, hour)
|
|
648
|
+
* └── MinuteViewingKey = Poseidon(HourlyVK, minute)
|
|
649
|
+
* └── SecondViewingKey = Poseidon(MinuteVK, second)
|
|
650
|
+
* ```
|
|
651
|
+
*
|
|
652
|
+
* @example
|
|
653
|
+
* ```typescript
|
|
654
|
+
* import { MasterViewingKey, assertMasterViewingKey } from "./cryptography";
|
|
655
|
+
*
|
|
656
|
+
* const mvk = deriveMasterViewingKey(masterSeed);
|
|
657
|
+
* assertMasterViewingKey(mvk);
|
|
658
|
+
*
|
|
659
|
+
* // Grant viewing access to auditor (full access — all tokens, all time)
|
|
660
|
+
* shareViewingKey(auditor, mvk);
|
|
661
|
+
* ```
|
|
662
|
+
*
|
|
663
|
+
* @see {@link assertMasterViewingKey}
|
|
664
|
+
* @see {@link MASTER_VIEWING_KEY_MAX}
|
|
665
|
+
* @see {@link MintViewingKey}
|
|
666
|
+
* @public
|
|
667
|
+
*/
|
|
668
|
+
type MasterViewingKey = SubSubSubBrandedType<Bn254FieldElement, "MasterViewingKey">;
|
|
669
|
+
/**
|
|
670
|
+
* Yearly viewing key for time-scoped transaction visibility.
|
|
671
|
+
*
|
|
672
|
+
* A yearly viewing key grants read-only visibility into all transactions
|
|
673
|
+
* involving any token within a specific calendar year. It is the first
|
|
674
|
+
* time-scoped level below the mint viewing key in the derivation hierarchy.
|
|
675
|
+
*
|
|
676
|
+
* @remarks
|
|
677
|
+
* - Element of the BN254 scalar field: range [0, BN254_FIELD_PRIME)
|
|
678
|
+
* - Derivation: `Poseidon(MintViewingKey, year)`
|
|
679
|
+
* - Can view all transactions in the specified year across the specified mint
|
|
680
|
+
* - Cannot view transactions from other years or other mints
|
|
681
|
+
* - Can be used to derive finer-grained monthly, daily, etc. keys
|
|
682
|
+
*
|
|
683
|
+
* ## Use Cases
|
|
684
|
+
* - Annual financial audits
|
|
685
|
+
* - Tax reporting and regulatory compliance for a specific fiscal year
|
|
686
|
+
* - Year-over-year activity comparison
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* ```typescript
|
|
690
|
+
* import { YearlyViewingKey, assertYearlyViewingKey } from "./cryptography";
|
|
691
|
+
*
|
|
692
|
+
* const yearKey = deriveYearlyViewingKey(masterViewingKey, 2024);
|
|
693
|
+
* assertYearlyViewingKey(yearKey);
|
|
694
|
+
*
|
|
695
|
+
* // Share with tax authority for 2024 audit
|
|
696
|
+
* shareViewingKey(taxAuthority, yearKey);
|
|
697
|
+
* ```
|
|
698
|
+
*
|
|
699
|
+
* @see {@link assertYearlyViewingKey}
|
|
700
|
+
* @see {@link MasterViewingKey}
|
|
701
|
+
* @public
|
|
702
|
+
*/
|
|
703
|
+
type YearlyViewingKey = SubSubSubBrandedType<Bn254FieldElement, "YearlyViewingKey">;
|
|
704
|
+
/**
|
|
705
|
+
* Monthly viewing key for time-scoped transaction visibility.
|
|
706
|
+
*
|
|
707
|
+
* A monthly viewing key grants read-only visibility into all transactions
|
|
708
|
+
* involving a specific token within a specific calendar month. It provides
|
|
709
|
+
* more granular access control than yearly keys.
|
|
710
|
+
*
|
|
711
|
+
* @remarks
|
|
712
|
+
* - Element of the BN254 scalar field: range [0, BN254_FIELD_PRIME)
|
|
713
|
+
* - Derivation: `Poseidon(YearlyViewingKey, month)` where month is 1–12
|
|
714
|
+
* - Can view all transactions in the specified month for the specified mint
|
|
715
|
+
* - Cannot view transactions from other months or other mints
|
|
716
|
+
* - Can derive daily and finer-grained keys
|
|
717
|
+
*
|
|
718
|
+
* ## Use Cases
|
|
719
|
+
* - Monthly financial reconciliation and accounting
|
|
720
|
+
* - Periodic compliance audit sampling
|
|
721
|
+
* - Subscription billing verification for monthly periods
|
|
722
|
+
*
|
|
723
|
+
* @example
|
|
724
|
+
* ```typescript
|
|
725
|
+
* import { MonthlyViewingKey, assertMonthlyViewingKey } from "./cryptography";
|
|
726
|
+
*
|
|
727
|
+
* const monthKey = deriveMonthlyViewingKey(yearlyKey, 6); // June
|
|
728
|
+
* assertMonthlyViewingKey(monthKey);
|
|
729
|
+
*
|
|
730
|
+
* // Share with accountant for monthly review
|
|
731
|
+
* shareViewingKey(accountant, monthKey);
|
|
732
|
+
* ```
|
|
733
|
+
*
|
|
734
|
+
* @see {@link assertMonthlyViewingKey}
|
|
735
|
+
* @see {@link YearlyViewingKey}
|
|
736
|
+
* @public
|
|
737
|
+
*/
|
|
738
|
+
type MonthlyViewingKey = SubSubSubBrandedType<Bn254FieldElement, "MonthlyViewingKey">;
|
|
739
|
+
/**
|
|
740
|
+
* Daily viewing key for time-scoped transaction visibility.
|
|
741
|
+
*
|
|
742
|
+
* A daily viewing key grants read-only visibility into all transactions
|
|
743
|
+
* involving a specific token within a specific calendar day. It provides
|
|
744
|
+
* day-level precision for scenarios requiring fine-grained access control.
|
|
745
|
+
*
|
|
746
|
+
* @remarks
|
|
747
|
+
* - Element of the BN254 scalar field: range [0, BN254_FIELD_PRIME)
|
|
748
|
+
* - Derivation: `Poseidon(MonthlyViewingKey, day)` where day is 1–31
|
|
749
|
+
* - Can view all transactions on the specified day for the specified mint
|
|
750
|
+
* - Cannot view transactions from other days or other mints
|
|
751
|
+
* - Can derive hourly and finer-grained keys
|
|
752
|
+
*
|
|
753
|
+
* ## Use Cases
|
|
754
|
+
* - Daily settlement verification
|
|
755
|
+
* - Incident investigation for specific dates
|
|
756
|
+
* - Daily trading activity review and reporting
|
|
757
|
+
*
|
|
758
|
+
* @example
|
|
759
|
+
* ```typescript
|
|
760
|
+
* import { DailyViewingKey, assertDailyViewingKey } from "./cryptography";
|
|
761
|
+
*
|
|
762
|
+
* const dayKey = deriveDailyViewingKey(monthlyKey, 15); // 15th of month
|
|
763
|
+
* assertDailyViewingKey(dayKey);
|
|
764
|
+
*
|
|
765
|
+
* // Share for investigating a specific date
|
|
766
|
+
* shareViewingKey(investigator, dayKey);
|
|
767
|
+
* ```
|
|
768
|
+
*
|
|
769
|
+
* @see {@link assertDailyViewingKey}
|
|
770
|
+
* @see {@link MonthlyViewingKey}
|
|
771
|
+
* @public
|
|
772
|
+
*/
|
|
773
|
+
type DailyViewingKey = SubSubSubBrandedType<Bn254FieldElement, "DailyViewingKey">;
|
|
774
|
+
/**
|
|
775
|
+
* Hourly viewing key for time-scoped transaction visibility.
|
|
776
|
+
*
|
|
777
|
+
* An hourly viewing key grants read-only visibility into all transactions
|
|
778
|
+
* involving a specific token within a specific hour. This enables very
|
|
779
|
+
* fine-grained access control for high-frequency trading or forensic scenarios.
|
|
780
|
+
*
|
|
781
|
+
* @remarks
|
|
782
|
+
* - Element of the BN254 scalar field: range [0, BN254_FIELD_PRIME)
|
|
783
|
+
* - Derivation: `Poseidon(DailyViewingKey, hour)` where hour is 0–23
|
|
784
|
+
* - Can view all transactions in the specified hour for the specified mint
|
|
785
|
+
* - Cannot view transactions from other hours or other mints
|
|
786
|
+
* - Can derive minute and second-level keys
|
|
787
|
+
*
|
|
788
|
+
* ## Use Cases
|
|
789
|
+
* - High-frequency trading audit windows
|
|
790
|
+
* - Incident response for specific time intervals
|
|
791
|
+
* - Market manipulation investigation with hour-level isolation
|
|
792
|
+
*
|
|
793
|
+
* @example
|
|
794
|
+
* ```typescript
|
|
795
|
+
* import { HourlyViewingKey, assertHourlyViewingKey } from "./cryptography";
|
|
796
|
+
*
|
|
797
|
+
* const hourKey = deriveHourlyViewingKey(dailyKey, 14); // 2 PM
|
|
798
|
+
* assertHourlyViewingKey(hourKey);
|
|
799
|
+
* ```
|
|
800
|
+
*
|
|
801
|
+
* @see {@link assertHourlyViewingKey}
|
|
802
|
+
* @see {@link DailyViewingKey}
|
|
803
|
+
* @public
|
|
804
|
+
*/
|
|
805
|
+
type HourlyViewingKey = SubSubSubBrandedType<Bn254FieldElement, "HourlyViewingKey">;
|
|
806
|
+
/**
|
|
807
|
+
* Minute viewing key for time-scoped transaction visibility.
|
|
808
|
+
*
|
|
809
|
+
* A minute viewing key grants read-only visibility into all transactions
|
|
810
|
+
* within a specific minute. This provides extremely fine-grained access control
|
|
811
|
+
* for forensic analysis or real-time monitoring.
|
|
812
|
+
*
|
|
813
|
+
* @remarks
|
|
814
|
+
* - Element of the BN254 scalar field: range [0, BN254_FIELD_PRIME)
|
|
815
|
+
* - Derivation: `Poseidon(HourlyViewingKey, minute)` where minute is 0–59
|
|
816
|
+
* - Can view all transactions in the specified minute for the specified mint
|
|
817
|
+
* - Cannot view transactions from other minutes or other mints
|
|
818
|
+
* - Can derive second-level keys for ultimate precision
|
|
819
|
+
*
|
|
820
|
+
* ## Use Cases
|
|
821
|
+
* - Real-time fraud detection in narrow windows
|
|
822
|
+
* - Precise transaction timing verification
|
|
823
|
+
* - Forensic timeline reconstruction at minute granularity
|
|
824
|
+
*
|
|
825
|
+
* @example
|
|
826
|
+
* ```typescript
|
|
827
|
+
* import { MinuteViewingKey, assertMinuteViewingKey } from "./cryptography";
|
|
828
|
+
*
|
|
829
|
+
* const minuteKey = deriveMinuteViewingKey(hourlyKey, 30); // :30 minute
|
|
830
|
+
* assertMinuteViewingKey(minuteKey);
|
|
831
|
+
* ```
|
|
832
|
+
*
|
|
833
|
+
* @see {@link assertMinuteViewingKey}
|
|
834
|
+
* @see {@link HourlyViewingKey}
|
|
835
|
+
* @public
|
|
836
|
+
*/
|
|
837
|
+
type MinuteViewingKey = SubSubSubBrandedType<Bn254FieldElement, "MinuteViewingKey">;
|
|
838
|
+
/**
|
|
839
|
+
* Second viewing key — the finest granularity of the viewing key hierarchy.
|
|
840
|
+
*
|
|
841
|
+
* A second viewing key grants read-only visibility into all transactions
|
|
842
|
+
* within a specific second. This is the leaf level of the time-scoped
|
|
843
|
+
* viewing key tree and is primarily used for forensic analysis of
|
|
844
|
+
* individual transactions.
|
|
845
|
+
*
|
|
846
|
+
* @remarks
|
|
847
|
+
* - Element of the BN254 scalar field: range [0, BN254_FIELD_PRIME)
|
|
848
|
+
* - Derivation: `Poseidon(MinuteViewingKey, second)` where second is 0–59
|
|
849
|
+
* - Can view all transactions in the specified second for the specified mint
|
|
850
|
+
* - Cannot view transactions from other seconds or other mints
|
|
851
|
+
* - Finest time granularity; no further time-scoped sub-keys exist
|
|
852
|
+
*
|
|
853
|
+
* ## Use Cases
|
|
854
|
+
* - Precise transaction attribution and sequencing
|
|
855
|
+
* - MEV (Maximal Extractable Value) and front-running detection
|
|
856
|
+
* - Block-level transaction ordering analysis
|
|
857
|
+
*
|
|
858
|
+
* @example
|
|
859
|
+
* ```typescript
|
|
860
|
+
* import { SecondViewingKey, assertSecondViewingKey } from "./cryptography";
|
|
861
|
+
*
|
|
862
|
+
* const secondKey = deriveSecondViewingKey(minuteKey, 45); // :45 second
|
|
863
|
+
* assertSecondViewingKey(secondKey);
|
|
864
|
+
* ```
|
|
865
|
+
*
|
|
866
|
+
* @see {@link assertSecondViewingKey}
|
|
867
|
+
* @see {@link MinuteViewingKey}
|
|
868
|
+
* @public
|
|
869
|
+
*/
|
|
870
|
+
type SecondViewingKey = SubSubSubBrandedType<Bn254FieldElement, "SecondViewingKey">;
|
|
871
|
+
/**
|
|
872
|
+
* Mint viewing key for token-specific transaction visibility.
|
|
873
|
+
*
|
|
874
|
+
* A mint viewing key grants read-only visibility into all transactions involving
|
|
875
|
+
* a specific SPL token mint address. It is derived directly from the master
|
|
876
|
+
* viewing key and the mint's address split into 128-bit halves.
|
|
877
|
+
*
|
|
878
|
+
* @remarks
|
|
879
|
+
* - Element of the BN254 scalar field: range [0, BN254_FIELD_PRIME)
|
|
880
|
+
* - Derivation: `Poseidon(MVK, mintAddressLow, mintAddressHigh)` where
|
|
881
|
+
* `mintAddressLow` = bytes 0–15 of the mint address (LE U128) and
|
|
882
|
+
* `mintAddressHigh` = bytes 16–31 (LE U128)
|
|
883
|
+
* - Grants visibility into all transactions for the specified mint across all time
|
|
884
|
+
* - Cannot view transactions involving other mints
|
|
885
|
+
* - Serves as the base for all time-scoped viewing keys for this mint
|
|
886
|
+
*
|
|
887
|
+
* ## Use Cases
|
|
888
|
+
* - Token-specific compliance reporting (e.g., USDC activity only)
|
|
889
|
+
* - Asset-specific audit trails for regulated token issuers
|
|
890
|
+
* - Selective disclosure for specific token positions
|
|
891
|
+
*
|
|
892
|
+
* @example
|
|
893
|
+
* ```typescript
|
|
894
|
+
* import { MintViewingKey, assertMintViewingKey } from "./cryptography";
|
|
895
|
+
*
|
|
896
|
+
* const mintKey = deriveMintViewingKey(masterViewingKey, usdcMint);
|
|
897
|
+
* assertMintViewingKey(mintKey);
|
|
898
|
+
*
|
|
899
|
+
* // Share with auditor for USDC-specific review (no access to other tokens)
|
|
900
|
+
* shareViewingKey(auditor, mintKey);
|
|
901
|
+
* ```
|
|
902
|
+
*
|
|
903
|
+
* @see {@link assertMintViewingKey}
|
|
904
|
+
* @see {@link MasterViewingKey}
|
|
905
|
+
* @public
|
|
906
|
+
*/
|
|
907
|
+
type MintViewingKey = SubSubSubBrandedType<Bn254FieldElement, "MintViewingKey">;
|
|
908
|
+
/**
|
|
909
|
+
* Asserts that a value is a valid X25519 byte array (exactly 32 bytes).
|
|
910
|
+
*
|
|
911
|
+
* X25519 operations (public keys, private keys, shared secrets) all operate on
|
|
912
|
+
* 32-byte values. This assertion validates the runtime type (`Uint8Array`) and
|
|
913
|
+
* the required byte length.
|
|
914
|
+
*
|
|
915
|
+
* @remarks
|
|
916
|
+
* This is the base assertion for all X25519 types. The more specific assertions
|
|
917
|
+
* `assertX25519PrivateKey` and `assertX25519PublicKey` delegate to this function
|
|
918
|
+
* for length and type checks.
|
|
919
|
+
*
|
|
920
|
+
* @param value - The Uint8Array to assert as X25519Bytes
|
|
921
|
+
* @throws {CryptographyAssertionError} If the value is not a Uint8Array
|
|
922
|
+
* @throws {CryptographyAssertionError} If the value is not exactly 32 bytes
|
|
923
|
+
*
|
|
924
|
+
* @example
|
|
925
|
+
* ```typescript
|
|
926
|
+
* const rawBytes = new Uint8Array(32);
|
|
927
|
+
* assertX25519Bytes(rawBytes);
|
|
928
|
+
* // rawBytes is now typed as X25519Bytes
|
|
929
|
+
*
|
|
930
|
+
* assertX25519Bytes(new Uint8Array(31)); // Throws: wrong length
|
|
931
|
+
* ```
|
|
932
|
+
*
|
|
933
|
+
* @see {@link X25519Bytes}
|
|
934
|
+
* @public
|
|
935
|
+
*/
|
|
936
|
+
declare function assertX25519Bytes(value: Uint8Array): asserts value is X25519Bytes;
|
|
937
|
+
/**
|
|
938
|
+
* Asserts that a value is a valid X25519 private key (exactly 32 bytes).
|
|
939
|
+
*
|
|
940
|
+
* A private key must be exactly 32 bytes. This assertion validates both
|
|
941
|
+
* the runtime type and the length of the input.
|
|
942
|
+
*
|
|
943
|
+
* @remarks
|
|
944
|
+
* **Security Warning**: Private keys must be kept secret. Never log, transmit,
|
|
945
|
+
* serialize to persistent storage unencrypted, or expose private keys in
|
|
946
|
+
* error messages. Use secure in-memory storage and zero the buffer after use
|
|
947
|
+
* where the runtime permits.
|
|
948
|
+
*
|
|
949
|
+
* This assertion does NOT verify that the private key is a valid Curve25519
|
|
950
|
+
* scalar (clamping is applied by the X25519 algorithm itself during use).
|
|
951
|
+
*
|
|
952
|
+
* @param value - The Uint8Array to assert as an X25519PrivateKey
|
|
953
|
+
* @throws {CryptographyAssertionError} If the value is not a Uint8Array
|
|
954
|
+
* @throws {CryptographyAssertionError} If the value is not exactly 32 bytes
|
|
955
|
+
*
|
|
956
|
+
* @example
|
|
957
|
+
* ```typescript
|
|
958
|
+
* // Derive a private key from master seed (preferred in Umbra)
|
|
959
|
+
* const rawKey = kmac256DerivedBytes;
|
|
960
|
+
* assertX25519PrivateKey(rawKey);
|
|
961
|
+
* // rawKey is now typed as X25519PrivateKey
|
|
962
|
+
* ```
|
|
963
|
+
*
|
|
964
|
+
* @see {@link X25519PrivateKey}
|
|
965
|
+
* @public
|
|
966
|
+
*/
|
|
967
|
+
declare function assertX25519PrivateKey(value: Uint8Array): asserts value is X25519PrivateKey;
|
|
968
|
+
/**
|
|
969
|
+
* Asserts that a value is a valid X25519 public key (exactly 32 bytes).
|
|
970
|
+
*
|
|
971
|
+
* A public key must be exactly 32 bytes. This assertion validates both
|
|
972
|
+
* the runtime type and the length of the input.
|
|
973
|
+
*
|
|
974
|
+
* @remarks
|
|
975
|
+
* This assertion does NOT perform curve-point validity checks (checking that
|
|
976
|
+
* the point lies on Curve25519). The X25519 algorithm itself handles invalid
|
|
977
|
+
* points by producing the all-zero output, which callers should check for.
|
|
978
|
+
*
|
|
979
|
+
* @param value - The Uint8Array to assert as an X25519PublicKey
|
|
980
|
+
* @throws {CryptographyAssertionError} If the value is not a Uint8Array
|
|
981
|
+
* @throws {CryptographyAssertionError} If the value is not exactly 32 bytes
|
|
982
|
+
*
|
|
983
|
+
* @example
|
|
984
|
+
* ```typescript
|
|
985
|
+
* // Receive and validate a public key from on-chain storage
|
|
986
|
+
* const theirKey = fetchPublicKeyFromChain();
|
|
987
|
+
* assertX25519PublicKey(theirKey);
|
|
988
|
+
* // theirKey is now typed as X25519PublicKey
|
|
989
|
+
*
|
|
990
|
+
* // Use in key exchange
|
|
991
|
+
* const sharedSecret = x25519(myPrivateKey, theirKey);
|
|
992
|
+
* ```
|
|
993
|
+
*
|
|
994
|
+
* @see {@link X25519PublicKey}
|
|
995
|
+
* @public
|
|
996
|
+
*/
|
|
997
|
+
declare function assertX25519PublicKey(value: Uint8Array): asserts value is X25519PublicKey;
|
|
998
|
+
/**
|
|
999
|
+
* Asserts that a value is a valid X25519 shared secret (exactly 32 bytes).
|
|
1000
|
+
*
|
|
1001
|
+
* A shared secret is the raw 32-byte output of an X25519 ECDH operation.
|
|
1002
|
+
* This assertion validates the runtime type and the required byte length.
|
|
1003
|
+
*
|
|
1004
|
+
* @remarks
|
|
1005
|
+
* Shared secrets MUST NOT be used directly as encryption keys. Always derive
|
|
1006
|
+
* a symmetric key from the shared secret using a proper KDF such as HKDF
|
|
1007
|
+
* (RFC 5869) or KMAC256 before use in an authenticated encryption scheme.
|
|
1008
|
+
*
|
|
1009
|
+
* @param value - The Uint8Array to assert as a SharedSecret
|
|
1010
|
+
* @throws {CryptographyAssertionError} If the value is not a Uint8Array
|
|
1011
|
+
* @throws {CryptographyAssertionError} If the value is not exactly 32 bytes
|
|
1012
|
+
*
|
|
1013
|
+
* @example
|
|
1014
|
+
* ```typescript
|
|
1015
|
+
* // After performing X25519 key exchange
|
|
1016
|
+
* const rawSecret = x25519(privateKey, publicKey);
|
|
1017
|
+
* assertSharedSecret(rawSecret);
|
|
1018
|
+
* // rawSecret is now typed as SharedSecret
|
|
1019
|
+
*
|
|
1020
|
+
* // Derive an encryption key (required — do not use rawSecret directly)
|
|
1021
|
+
* const encryptionKey = hkdf(rawSecret, salt, info);
|
|
1022
|
+
* ```
|
|
1023
|
+
*
|
|
1024
|
+
* @see {@link SharedSecret}
|
|
1025
|
+
* @public
|
|
1026
|
+
*/
|
|
1027
|
+
declare function assertSharedSecret(value: Uint8Array): asserts value is SharedSecret;
|
|
1028
|
+
/**
|
|
1029
|
+
* Asserts that a value is a valid Keccak-256 hash output (exactly 32 bytes).
|
|
1030
|
+
*
|
|
1031
|
+
* @param value - The Uint8Array to assert as a Keccak256Hash (must be exactly 32 bytes)
|
|
1032
|
+
* @throws {CryptographyAssertionError} If the value is not a Uint8Array or not exactly 32 bytes
|
|
1033
|
+
*
|
|
1034
|
+
* @example
|
|
1035
|
+
* ```typescript
|
|
1036
|
+
* const hashBytes = keccak256(data);
|
|
1037
|
+
* assertKeccak256Hash(hashBytes);
|
|
1038
|
+
* // hashBytes is now typed as Keccak256Hash
|
|
1039
|
+
* ```
|
|
1040
|
+
*
|
|
1041
|
+
* @see {@link Keccak256Hash}
|
|
1042
|
+
* @public
|
|
1043
|
+
*/
|
|
1044
|
+
declare function assertKeccak256Hash(value: Uint8Array): asserts value is Keccak256Hash;
|
|
1045
|
+
/**
|
|
1046
|
+
* Asserts that a value is a valid Keccak-512 hash output (exactly 64 bytes).
|
|
1047
|
+
*
|
|
1048
|
+
* @param value - The Uint8Array to assert as a Keccak512Hash (must be exactly 64 bytes)
|
|
1049
|
+
* @throws {CryptographyAssertionError} If the value is not a Uint8Array or not exactly 64 bytes
|
|
1050
|
+
*
|
|
1051
|
+
* @example
|
|
1052
|
+
* ```typescript
|
|
1053
|
+
* const hashBytes = keccak512(data);
|
|
1054
|
+
* assertKeccak512Hash(hashBytes);
|
|
1055
|
+
* // hashBytes is now typed as Keccak512Hash
|
|
1056
|
+
* ```
|
|
1057
|
+
*
|
|
1058
|
+
* @see {@link Keccak512Hash}
|
|
1059
|
+
* @see {@link MasterSeed}
|
|
1060
|
+
* @public
|
|
1061
|
+
*/
|
|
1062
|
+
declare function assertKeccak512Hash(value: Uint8Array): asserts value is Keccak512Hash;
|
|
1063
|
+
/**
|
|
1064
|
+
* Asserts that a value is a valid master seed (exactly 64 bytes).
|
|
1065
|
+
*
|
|
1066
|
+
* Validates that the value is a 64-byte Uint8Array as produced by Keccak-512
|
|
1067
|
+
* hashing. Does not verify the entropy quality of the seed.
|
|
1068
|
+
*
|
|
1069
|
+
* @param value - The Uint8Array to assert as a MasterSeed (must be exactly 64 bytes)
|
|
1070
|
+
* @throws {CryptographyAssertionError} If the value is not a Uint8Array or not exactly 64 bytes
|
|
1071
|
+
*
|
|
1072
|
+
* @example
|
|
1073
|
+
* ```typescript
|
|
1074
|
+
* const seedBytes = keccak512(entropy);
|
|
1075
|
+
* assertMasterSeed(seedBytes);
|
|
1076
|
+
* // seedBytes is now typed as MasterSeed
|
|
1077
|
+
* ```
|
|
1078
|
+
*
|
|
1079
|
+
* @see {@link MasterSeed}
|
|
1080
|
+
* @public
|
|
1081
|
+
*/
|
|
1082
|
+
declare function assertMasterSeed(value: Uint8Array): asserts value is MasterSeed;
|
|
1083
|
+
/**
|
|
1084
|
+
* Asserts that a value is a valid generation seed (exactly 64 bytes).
|
|
1085
|
+
*
|
|
1086
|
+
* Validates that the value is a 64-byte Uint8Array as produced by Keccak-512
|
|
1087
|
+
* hashing. Structurally identical to MasterSeed but semantically distinct.
|
|
1088
|
+
*
|
|
1089
|
+
* @param value - The Uint8Array to assert as a GenerationSeed (must be exactly 64 bytes)
|
|
1090
|
+
* @throws {CryptographyAssertionError} If the value is not a Uint8Array or not exactly 64 bytes
|
|
1091
|
+
*
|
|
1092
|
+
* @example
|
|
1093
|
+
* ```typescript
|
|
1094
|
+
* const seedBytes = keccak512(protocolData);
|
|
1095
|
+
* assertGenerationSeed(seedBytes);
|
|
1096
|
+
* // seedBytes is now typed as GenerationSeed
|
|
1097
|
+
* ```
|
|
1098
|
+
*
|
|
1099
|
+
* @see {@link GenerationSeed}
|
|
1100
|
+
* @public
|
|
1101
|
+
*/
|
|
1102
|
+
declare function assertGenerationSeed(value: Uint8Array): asserts value is GenerationSeed;
|
|
1103
|
+
/**
|
|
1104
|
+
* Asserts that a value is a valid master viewing key.
|
|
1105
|
+
*
|
|
1106
|
+
* Validates that the value is a non-negative bigint strictly less than 2^252.
|
|
1107
|
+
* The 2^252 bound is tighter than the BN254 field prime to ensure compatibility
|
|
1108
|
+
* with ZK circuits that perform sub-252-bit range checks.
|
|
1109
|
+
*
|
|
1110
|
+
* @param value - The bigint to assert as a MasterViewingKey (must be in range [0, 2^252))
|
|
1111
|
+
* @throws {CryptographyAssertionError} If the value is not a bigint
|
|
1112
|
+
* @throws {CryptographyAssertionError} If the value is negative
|
|
1113
|
+
* @throws {CryptographyAssertionError} If the value is >= 2^252
|
|
1114
|
+
*
|
|
1115
|
+
* @example
|
|
1116
|
+
* ```typescript
|
|
1117
|
+
* const mvk = deriveMasterViewingKey(masterSeed);
|
|
1118
|
+
* assertMasterViewingKey(mvk);
|
|
1119
|
+
* // mvk is now typed as MasterViewingKey
|
|
1120
|
+
* ```
|
|
1121
|
+
*
|
|
1122
|
+
* @see {@link MasterViewingKey}
|
|
1123
|
+
* @see {@link MASTER_VIEWING_KEY_MAX}
|
|
1124
|
+
* @public
|
|
1125
|
+
*/
|
|
1126
|
+
declare function assertMasterViewingKey(value: bigint): asserts value is MasterViewingKey;
|
|
1127
|
+
/**
|
|
1128
|
+
* Asserts that a value is a valid yearly viewing key.
|
|
1129
|
+
*
|
|
1130
|
+
* Validates that the value is a non-negative bigint within the BN254 field prime.
|
|
1131
|
+
*
|
|
1132
|
+
* @param value - The bigint to assert (must be in range [0, BN254_FIELD_PRIME))
|
|
1133
|
+
* @throws {CryptographyAssertionError} If not a bigint or out of range
|
|
1134
|
+
*
|
|
1135
|
+
* @see {@link YearlyViewingKey}
|
|
1136
|
+
* @public
|
|
1137
|
+
*/
|
|
1138
|
+
declare function assertYearlyViewingKey(value: bigint): asserts value is YearlyViewingKey;
|
|
1139
|
+
/**
|
|
1140
|
+
* Asserts that a value is a valid monthly viewing key.
|
|
1141
|
+
*
|
|
1142
|
+
* Validates that the value is a non-negative bigint within the BN254 field prime.
|
|
1143
|
+
*
|
|
1144
|
+
* @param value - The bigint to assert (must be in range [0, BN254_FIELD_PRIME))
|
|
1145
|
+
* @throws {CryptographyAssertionError} If not a bigint or out of range
|
|
1146
|
+
*
|
|
1147
|
+
* @see {@link MonthlyViewingKey}
|
|
1148
|
+
* @public
|
|
1149
|
+
*/
|
|
1150
|
+
declare function assertMonthlyViewingKey(value: bigint): asserts value is MonthlyViewingKey;
|
|
1151
|
+
/**
|
|
1152
|
+
* Asserts that a value is a valid daily viewing key.
|
|
1153
|
+
*
|
|
1154
|
+
* Validates that the value is a non-negative bigint within the BN254 field prime.
|
|
1155
|
+
*
|
|
1156
|
+
* @param value - The bigint to assert (must be in range [0, BN254_FIELD_PRIME))
|
|
1157
|
+
* @throws {CryptographyAssertionError} If not a bigint or out of range
|
|
1158
|
+
*
|
|
1159
|
+
* @see {@link DailyViewingKey}
|
|
1160
|
+
* @public
|
|
1161
|
+
*/
|
|
1162
|
+
declare function assertDailyViewingKey(value: bigint): asserts value is DailyViewingKey;
|
|
1163
|
+
/**
|
|
1164
|
+
* Asserts that a value is a valid hourly viewing key.
|
|
1165
|
+
*
|
|
1166
|
+
* Validates that the value is a non-negative bigint within the BN254 field prime.
|
|
1167
|
+
*
|
|
1168
|
+
* @param value - The bigint to assert (must be in range [0, BN254_FIELD_PRIME))
|
|
1169
|
+
* @throws {CryptographyAssertionError} If not a bigint or out of range
|
|
1170
|
+
*
|
|
1171
|
+
* @see {@link HourlyViewingKey}
|
|
1172
|
+
* @public
|
|
1173
|
+
*/
|
|
1174
|
+
declare function assertHourlyViewingKey(value: bigint): asserts value is HourlyViewingKey;
|
|
1175
|
+
/**
|
|
1176
|
+
* Asserts that a value is a valid minute viewing key.
|
|
1177
|
+
*
|
|
1178
|
+
* Validates that the value is a non-negative bigint within the BN254 field prime.
|
|
1179
|
+
*
|
|
1180
|
+
* @param value - The bigint to assert (must be in range [0, BN254_FIELD_PRIME))
|
|
1181
|
+
* @throws {CryptographyAssertionError} If not a bigint or out of range
|
|
1182
|
+
*
|
|
1183
|
+
* @see {@link MinuteViewingKey}
|
|
1184
|
+
* @public
|
|
1185
|
+
*/
|
|
1186
|
+
declare function assertMinuteViewingKey(value: bigint): asserts value is MinuteViewingKey;
|
|
1187
|
+
/**
|
|
1188
|
+
* Asserts that a value is a valid second viewing key.
|
|
1189
|
+
*
|
|
1190
|
+
* Validates that the value is a non-negative bigint within the BN254 field prime.
|
|
1191
|
+
*
|
|
1192
|
+
* @param value - The bigint to assert (must be in range [0, BN254_FIELD_PRIME))
|
|
1193
|
+
* @throws {CryptographyAssertionError} If not a bigint or out of range
|
|
1194
|
+
*
|
|
1195
|
+
* @see {@link SecondViewingKey}
|
|
1196
|
+
* @public
|
|
1197
|
+
*/
|
|
1198
|
+
declare function assertSecondViewingKey(value: bigint): asserts value is SecondViewingKey;
|
|
1199
|
+
/**
|
|
1200
|
+
* Asserts that a value is a valid mint viewing key.
|
|
1201
|
+
*
|
|
1202
|
+
* Validates that the value is a non-negative bigint within the BN254 field prime.
|
|
1203
|
+
*
|
|
1204
|
+
* @param value - The bigint to assert (must be in range [0, BN254_FIELD_PRIME))
|
|
1205
|
+
* @throws {CryptographyAssertionError} If not a bigint or out of range
|
|
1206
|
+
*
|
|
1207
|
+
* @see {@link MintViewingKey}
|
|
1208
|
+
* @public
|
|
1209
|
+
*/
|
|
1210
|
+
declare function assertMintViewingKey(value: bigint): asserts value is MintViewingKey;
|
|
1211
|
+
/**
|
|
1212
|
+
* Asserts that a value is a valid X25519Keypair.
|
|
1213
|
+
*
|
|
1214
|
+
* Validates that the value is a non-null object with valid `privateKey` and
|
|
1215
|
+
* `publicKey` fields, each of which must pass their respective assertions.
|
|
1216
|
+
*
|
|
1217
|
+
* @param value - The object to assert as an X25519Keypair
|
|
1218
|
+
* @throws {CryptographyAssertionError} If the value is not a non-null object
|
|
1219
|
+
* @throws {CryptographyAssertionError} If `privateKey` or `publicKey` are missing
|
|
1220
|
+
* @throws {CryptographyAssertionError} If either key fails its byte-level assertion
|
|
1221
|
+
*
|
|
1222
|
+
* @example
|
|
1223
|
+
* ```typescript
|
|
1224
|
+
* const keypair = { privateKey: privKey, publicKey: pubKey };
|
|
1225
|
+
* assertX25519Keypair(keypair);
|
|
1226
|
+
* // keypair is now typed as X25519Keypair
|
|
1227
|
+
* ```
|
|
1228
|
+
*
|
|
1229
|
+
* @see {@link X25519Keypair}
|
|
1230
|
+
* @see {@link assertX25519PrivateKey}
|
|
1231
|
+
* @see {@link assertX25519PublicKey}
|
|
1232
|
+
* @public
|
|
1233
|
+
*/
|
|
1234
|
+
declare function assertX25519Keypair(value: {
|
|
1235
|
+
privateKey: Uint8Array;
|
|
1236
|
+
publicKey: Uint8Array;
|
|
1237
|
+
}): asserts value is X25519Keypair;
|
|
1238
|
+
/**
|
|
1239
|
+
* Asserts that a value is a valid Ed25519Keypair.
|
|
1240
|
+
*
|
|
1241
|
+
* Validates that the value is a non-null object with `seed` (exactly 32 bytes)
|
|
1242
|
+
* and `publicKey` (exactly 32 bytes) properties.
|
|
1243
|
+
*
|
|
1244
|
+
* @param value - The object to assert as an Ed25519Keypair (must have seed and publicKey properties)
|
|
1245
|
+
* @throws {CryptographyAssertionError} If the value is not a non-null object
|
|
1246
|
+
* @throws {CryptographyAssertionError} If `seed` or `publicKey` are missing
|
|
1247
|
+
* @throws {CryptographyAssertionError} If `seed` or `publicKey` are not Uint8Array(32)
|
|
1248
|
+
*
|
|
1249
|
+
* @example
|
|
1250
|
+
* ```typescript
|
|
1251
|
+
* const keypair = { seed, publicKey };
|
|
1252
|
+
* assertEd25519Keypair(keypair);
|
|
1253
|
+
* // keypair is now typed as Ed25519Keypair
|
|
1254
|
+
* ```
|
|
1255
|
+
*
|
|
1256
|
+
* @see {@link Ed25519Keypair}
|
|
1257
|
+
* @public
|
|
1258
|
+
*/
|
|
1259
|
+
declare function assertEd25519Keypair(value: {
|
|
1260
|
+
seed: Uint8Array;
|
|
1261
|
+
publicKey: Uint8Array;
|
|
1262
|
+
}): asserts value is Ed25519Keypair;
|
|
1263
|
+
/**
|
|
1264
|
+
* Asserts that a value is a valid Curve25519KeypairResult.
|
|
1265
|
+
*
|
|
1266
|
+
* Validates that the value is a non-null object with valid `ed25519Keypair`
|
|
1267
|
+
* and `x25519Keypair` fields, each of which must pass their respective assertions.
|
|
1268
|
+
*
|
|
1269
|
+
* @param value - The object to assert as a Curve25519KeypairResult
|
|
1270
|
+
* @throws {CryptographyAssertionError} If the value is not a non-null object
|
|
1271
|
+
* @throws {CryptographyAssertionError} If either nested keypair is missing or invalid
|
|
1272
|
+
*
|
|
1273
|
+
* @example
|
|
1274
|
+
* ```typescript
|
|
1275
|
+
* const result = { ed25519Keypair, x25519Keypair };
|
|
1276
|
+
* assertCurve25519KeypairResult(result);
|
|
1277
|
+
* // result is now typed as Curve25519KeypairResult
|
|
1278
|
+
* ```
|
|
1279
|
+
*
|
|
1280
|
+
* @see {@link Curve25519KeypairResult}
|
|
1281
|
+
* @see {@link assertEd25519Keypair}
|
|
1282
|
+
* @see {@link assertX25519Keypair}
|
|
1283
|
+
* @public
|
|
1284
|
+
*/
|
|
1285
|
+
declare function assertCurve25519KeypairResult(value: {
|
|
1286
|
+
ed25519Keypair: {
|
|
1287
|
+
seed: Uint8Array;
|
|
1288
|
+
publicKey: Uint8Array;
|
|
1289
|
+
};
|
|
1290
|
+
x25519Keypair: {
|
|
1291
|
+
privateKey: Uint8Array;
|
|
1292
|
+
publicKey: Uint8Array;
|
|
1293
|
+
};
|
|
1294
|
+
}): asserts value is Curve25519KeypairResult;
|
|
1295
|
+
|
|
1296
|
+
export { assertX25519Keypair as A, assertX25519PrivateKey as B, type Curve25519KeypairResult as C, type DailyViewingKey as D, type Ed25519Keypair as E, assertX25519PublicKey as F, type GenerationSeed as G, type HourlyViewingKey as H, assertYearlyViewingKey as I, type Keccak256Hash as K, MASTER_VIEWING_KEY_MAX as M, type SecondViewingKey as S, type X25519Bytes as X, type YearlyViewingKey as Y, type Keccak512Hash as a, type MasterSeed as b, type MasterViewingKey as c, type MintViewingKey as d, type MinuteViewingKey as e, type MonthlyViewingKey as f, type SharedSecret as g, type X25519Keypair as h, type X25519PrivateKey as i, type X25519PublicKey as j, X25519_BYTE_LENGTH as k, assertCurve25519KeypairResult as l, assertDailyViewingKey as m, assertEd25519Keypair as n, assertGenerationSeed as o, assertHourlyViewingKey as p, assertKeccak256Hash as q, assertKeccak512Hash as r, assertMasterSeed as s, assertMasterViewingKey as t, assertMintViewingKey as u, assertMinuteViewingKey as v, assertMonthlyViewingKey as w, assertSecondViewingKey as x, assertSharedSecret as y, assertX25519Bytes as z };
|