@icp-sdk/vetkeys 0.5.0-beta.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 +31 -0
- package/dist/lib/actor-4fotMNaR.mjs +5718 -0
- package/dist/lib/encrypted_maps.es.js +650 -0
- package/dist/lib/index-BUXhtQhx.mjs +3932 -0
- package/dist/lib/index.es.js +20 -0
- package/dist/lib/key_manager.es.js +274 -0
- package/dist/types/declarations/ic_vetkeys_encrypted_maps_canister/ic_vetkeys_encrypted_maps_canister.d.ts +109 -0
- package/dist/types/declarations/ic_vetkeys_encrypted_maps_canister/ic_vetkeys_encrypted_maps_canister.did.d.ts +62 -0
- package/dist/types/declarations/ic_vetkeys_manager_canister/ic_vetkeys_manager_canister.d.ts +66 -0
- package/dist/types/declarations/ic_vetkeys_manager_canister/ic_vetkeys_manager_canister.did.d.ts +33 -0
- package/dist/types/encrypted_maps/encrypted_maps_canister.d.ts +66 -0
- package/dist/types/encrypted_maps/encrypted_maps_canister.test.d.ts +1 -0
- package/dist/types/encrypted_maps/index.d.ts +466 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/key_manager/index.d.ts +216 -0
- package/dist/types/key_manager/key_manager_canister.d.ts +32 -0
- package/dist/types/key_manager/key_manager_canister.test.d.ts +1 -0
- package/dist/types/utils/utils.d.ts +491 -0
- package/dist/types/utils/utils.test.d.ts +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Principal } from '@icp-sdk/core/principal';
|
|
2
|
+
import { ActorSubclass, HttpAgent } from '@icp-sdk/core/agent';
|
|
3
|
+
import { _SERVICE as _DEFAULT_KEY_MANAGER_SERVICE, AccessRights, ByteBuf } from '../declarations/ic_vetkeys_manager_canister/ic_vetkeys_manager_canister.did.js';
|
|
4
|
+
import { KeyManagerClient } from './index';
|
|
5
|
+
export declare class DefaultKeyManagerClient implements KeyManagerClient {
|
|
6
|
+
canisterId: string;
|
|
7
|
+
actor: ActorSubclass<_DEFAULT_KEY_MANAGER_SERVICE>;
|
|
8
|
+
verificationKey: ByteBuf | undefined;
|
|
9
|
+
constructor(agent: HttpAgent, canisterId: string);
|
|
10
|
+
get_accessible_shared_key_ids(): Promise<[Principal, ByteBuf][]>;
|
|
11
|
+
set_user_rights(owner: Principal, vetkeyName: ByteBuf, user: Principal, userRights: AccessRights): Promise<{
|
|
12
|
+
Ok: [] | [AccessRights];
|
|
13
|
+
} | {
|
|
14
|
+
Err: string;
|
|
15
|
+
}>;
|
|
16
|
+
get_user_rights(owner: Principal, vetkeyName: ByteBuf, user: Principal): Promise<{
|
|
17
|
+
Ok: [] | [AccessRights];
|
|
18
|
+
} | {
|
|
19
|
+
Err: string;
|
|
20
|
+
}>;
|
|
21
|
+
remove_user(owner: Principal, vetkeyName: ByteBuf, user: Principal): Promise<{
|
|
22
|
+
Ok: [] | [AccessRights];
|
|
23
|
+
} | {
|
|
24
|
+
Err: string;
|
|
25
|
+
}>;
|
|
26
|
+
get_encrypted_vetkey(keyOwner: Principal, vetkeyName: ByteBuf, transportKey: ByteBuf): Promise<{
|
|
27
|
+
Ok: ByteBuf;
|
|
28
|
+
} | {
|
|
29
|
+
Err: string;
|
|
30
|
+
}>;
|
|
31
|
+
get_vetkey_verification_key(): Promise<ByteBuf>;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import { WeierstrassPoint } from '@noble/curves/abstract/weierstrass';
|
|
2
|
+
import { Fp, Fp2 } from '@noble/curves/abstract/tower';
|
|
3
|
+
import { Principal } from '@icp-sdk/core/principal';
|
|
4
|
+
export type G1Point = WeierstrassPoint<Fp>;
|
|
5
|
+
export type G2Point = WeierstrassPoint<Fp2>;
|
|
6
|
+
/**
|
|
7
|
+
* Transport Secret Key
|
|
8
|
+
*
|
|
9
|
+
* Applications using VetKD create an ephemeral transport secret key and send
|
|
10
|
+
* the public key to the IC as part of their VetKD request. The returned VetKey
|
|
11
|
+
* is encrypted, and can only be decrypted using the transport secret key.
|
|
12
|
+
*/
|
|
13
|
+
export declare class TransportSecretKey {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* Create a random transport secret key
|
|
17
|
+
*/
|
|
18
|
+
static random(): TransportSecretKey;
|
|
19
|
+
/**
|
|
20
|
+
* Deserialize TransportSecretKey from a bytestring
|
|
21
|
+
*
|
|
22
|
+
* The passed value would typically be a string previously returned
|
|
23
|
+
* by calling serialize on a randomly-created TransportSecretKey.
|
|
24
|
+
*/
|
|
25
|
+
static deserialize(sk: Uint8Array): TransportSecretKey;
|
|
26
|
+
/**
|
|
27
|
+
* Return the encoding of the transport public key; this value is
|
|
28
|
+
* sent to the IC
|
|
29
|
+
*/
|
|
30
|
+
publicKeyBytes(): Uint8Array;
|
|
31
|
+
/**
|
|
32
|
+
* Return the transport secret key value
|
|
33
|
+
*
|
|
34
|
+
* Applications would not normally need to call this
|
|
35
|
+
*/
|
|
36
|
+
serialize(): Uint8Array;
|
|
37
|
+
/**
|
|
38
|
+
* @internal constructor
|
|
39
|
+
*/
|
|
40
|
+
private constructor();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Check if a transport public key is valid
|
|
44
|
+
*
|
|
45
|
+
* This tests if the passed byte array is of the expected size and encodes
|
|
46
|
+
* a valid group element.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isValidTransportPublicKey(tpk: Uint8Array): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Enumeration identifying possible master public keys
|
|
51
|
+
*/
|
|
52
|
+
export declare enum MasterPublicKeyId {
|
|
53
|
+
/** The production key generated in June 2025 */
|
|
54
|
+
KEY_1 = "key_1",
|
|
55
|
+
/** The test key generated in May 2025 */
|
|
56
|
+
TEST_KEY_1 = "test_key_1"
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Enumeration identifying possible PocketIC test keys
|
|
60
|
+
*/
|
|
61
|
+
export declare enum PocketIcMasterPublicKeyId {
|
|
62
|
+
KEY_1 = "key_1",
|
|
63
|
+
TEST_KEY_1 = "test_key_1",
|
|
64
|
+
DFX_TEST_KEY = "dfx_test_key"
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* VetKD master key
|
|
68
|
+
*
|
|
69
|
+
* The VetKD subnet contains a small number of master keys, from which canister
|
|
70
|
+
* keys are derived. In turn, many keys can be derived from the canister keys
|
|
71
|
+
* using a context string.
|
|
72
|
+
*/
|
|
73
|
+
export declare class MasterPublicKey {
|
|
74
|
+
#private;
|
|
75
|
+
/**
|
|
76
|
+
* Read a MasterPublicKey from the bytestring encoding
|
|
77
|
+
*
|
|
78
|
+
* Normally the bytes provided here will have been returned by
|
|
79
|
+
* the `vetkd_public_key` management canister interface.
|
|
80
|
+
*/
|
|
81
|
+
static deserialize(bytes: Uint8Array): MasterPublicKey;
|
|
82
|
+
/**
|
|
83
|
+
* Derive a canister master key from the subnet master key
|
|
84
|
+
*
|
|
85
|
+
* To create the derived public key in VetKD, a two step derivation is performed. The first step
|
|
86
|
+
* creates a key that is specific to the canister that is making VetKD requests to the
|
|
87
|
+
* management canister, sometimes called canister master key.
|
|
88
|
+
*
|
|
89
|
+
* This function can be used to compute canister master keys knowing just the subnet master key
|
|
90
|
+
* plus the canister identity. This avoids having to interact with the IC for performing this
|
|
91
|
+
* computation.
|
|
92
|
+
*/
|
|
93
|
+
deriveCanisterKey(canisterId: Uint8Array): DerivedPublicKey;
|
|
94
|
+
/**
|
|
95
|
+
* Return the bytestring encoding of the master public key
|
|
96
|
+
*/
|
|
97
|
+
publicKeyBytes(): Uint8Array;
|
|
98
|
+
/**
|
|
99
|
+
* Return the hardcoded master public key used on IC
|
|
100
|
+
*
|
|
101
|
+
* This allows performing public key derivation offline
|
|
102
|
+
*/
|
|
103
|
+
static productionKey(keyId?: MasterPublicKeyId): MasterPublicKey;
|
|
104
|
+
/**
|
|
105
|
+
* Return the hardcoded master public key used in PocketIC
|
|
106
|
+
*
|
|
107
|
+
* This allows performing public key derivation offline
|
|
108
|
+
*/
|
|
109
|
+
static pocketicKey(keyId?: PocketIcMasterPublicKeyId): MasterPublicKey;
|
|
110
|
+
/**
|
|
111
|
+
* @internal constructor
|
|
112
|
+
*/
|
|
113
|
+
private constructor();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* VetKD derived public key
|
|
117
|
+
*
|
|
118
|
+
* An unencrypted VetKey is a BLS signature generated with a canister-specific
|
|
119
|
+
* key. This type represents such keys.
|
|
120
|
+
*/
|
|
121
|
+
export declare class DerivedPublicKey {
|
|
122
|
+
#private;
|
|
123
|
+
/**
|
|
124
|
+
* Read a DerivedPublicKey from the bytestring encoding
|
|
125
|
+
*
|
|
126
|
+
* Normally the bytes provided here will have been returned by
|
|
127
|
+
* the `vetkd_public_key` management canister interface.
|
|
128
|
+
*/
|
|
129
|
+
static deserialize(bytes: Uint8Array): DerivedPublicKey;
|
|
130
|
+
/**
|
|
131
|
+
* Perform second-stage derivation of a public key
|
|
132
|
+
*
|
|
133
|
+
* To create the derived public key in VetKD, a two step derivation is performed. The first step
|
|
134
|
+
* creates a key that is specific to the canister that is making VetKD requests to the
|
|
135
|
+
* management canister, sometimes called canister master key. The second step incorporates the
|
|
136
|
+
* "derivation context" value provided to the `vetkd_public_key` management canister interface.
|
|
137
|
+
*
|
|
138
|
+
* If `vetkd_public_key` is invoked with an empty derivation context, it simply returns the
|
|
139
|
+
* canister master key. Then the second derivation step can be done offline, using this
|
|
140
|
+
* function. This is useful if you wish to derive multiple keys without having to interact with
|
|
141
|
+
* the IC each time.
|
|
142
|
+
*
|
|
143
|
+
* If `context` is empty, then this simply returns the underlying key. This matches the behavior
|
|
144
|
+
* of `vetkd_public_key`
|
|
145
|
+
*/
|
|
146
|
+
deriveSubKey(context: Uint8Array): DerivedPublicKey;
|
|
147
|
+
/**
|
|
148
|
+
* Return the bytestring encoding of the derived public key
|
|
149
|
+
*
|
|
150
|
+
* Applications would not normally need to call this, unless they
|
|
151
|
+
* are using VetKD for creating a random beacon, in which case
|
|
152
|
+
* these bytes are used by anyone verifying the beacon.
|
|
153
|
+
*/
|
|
154
|
+
publicKeyBytes(): Uint8Array;
|
|
155
|
+
/**
|
|
156
|
+
* @internal getter returning the point element of the derived public key
|
|
157
|
+
*
|
|
158
|
+
* Applications would not normally need to call this
|
|
159
|
+
*/
|
|
160
|
+
getPoint(): G2Point;
|
|
161
|
+
/**
|
|
162
|
+
* @internal constructor
|
|
163
|
+
*
|
|
164
|
+
* This is public for typing reasons but there should be no need
|
|
165
|
+
* for an application to call this.
|
|
166
|
+
*/
|
|
167
|
+
constructor(pk: G2Point);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Hash an input to a scalar in the BLS12-381 group
|
|
171
|
+
*
|
|
172
|
+
* This is useful if you want to derive a BLS12-381 secret key from some other
|
|
173
|
+
* input data, but this is not a common operation.
|
|
174
|
+
*/
|
|
175
|
+
export declare function hashToScalar(input: Uint8Array, domainSep: string): bigint;
|
|
176
|
+
/**
|
|
177
|
+
* Derive a symmetric key from the provided input using HKDF-SHA256.
|
|
178
|
+
*
|
|
179
|
+
* The `input` parameter should be a sufficiently long random input generated
|
|
180
|
+
* in a secure way. 256 bits (32 bytes) or longer is preferable.
|
|
181
|
+
*
|
|
182
|
+
* The `domainSep` parameter should be a string unique to your application and
|
|
183
|
+
* also your usage of the resulting key. For example say your application
|
|
184
|
+
* "my-app" is deriving two keys, one for usage "foo" and the other for
|
|
185
|
+
* "bar". You might use as domain separators "my-app-foo" and "my-app-bar".
|
|
186
|
+
*
|
|
187
|
+
* The returned Uint8Array will be `outputLength` bytes long.
|
|
188
|
+
*/
|
|
189
|
+
export declare function deriveSymmetricKey(input: Uint8Array, domainSep: Uint8Array | string, outputLength: number): Uint8Array;
|
|
190
|
+
/**
|
|
191
|
+
* @internal hash a derived public key plus a message into the BLS12-381 G1 group
|
|
192
|
+
*
|
|
193
|
+
* This is not normally needed by applications using VetKD.
|
|
194
|
+
*/
|
|
195
|
+
export declare function augmentedHashToG1(pk: DerivedPublicKey, message: Uint8Array): G1Point;
|
|
196
|
+
/**
|
|
197
|
+
* Verify a BLS signature
|
|
198
|
+
*
|
|
199
|
+
* A VetKey is in the end a valid BLS signature; this function checks that a
|
|
200
|
+
* provided BLS signature is the valid one for the provided public key and
|
|
201
|
+
* message.
|
|
202
|
+
*
|
|
203
|
+
* Specifically this verifies "augmented" BLS signature, which includes the
|
|
204
|
+
* public key of the signer as an input to the hash. This addition ensures that
|
|
205
|
+
* messages signed by different public keys are distinct.
|
|
206
|
+
*
|
|
207
|
+
* See section 3.2 of the IETF draft `draft-irtf-cfrg-bls-signature` for details.
|
|
208
|
+
*
|
|
209
|
+
* When a VetKey struct is created (using EncryptedVetKey.decryptAndVerify) the signature
|
|
210
|
+
* is already verified, so using this function is only necessary when
|
|
211
|
+
* using a vetKey as a VRF or for threshold BLS signatures, with the bytes obtained
|
|
212
|
+
* from VetKey.signatureBytes.
|
|
213
|
+
*/
|
|
214
|
+
export declare function verifyBlsSignature(pk: DerivedPublicKey, message: Uint8Array, signature: G1Point | Uint8Array): boolean;
|
|
215
|
+
/**
|
|
216
|
+
* A VetKey (verifiably encrypted threshold key)
|
|
217
|
+
*
|
|
218
|
+
* This is the end product of executing the VetKD protocol.
|
|
219
|
+
*
|
|
220
|
+
* Internally a VetKey is a valid BLS signature for the bytestring
|
|
221
|
+
* `input` which provided when calling the `vetkd_derive_encrypted_key`
|
|
222
|
+
* management canister interface.
|
|
223
|
+
*
|
|
224
|
+
* For certain usages, such as a beacon, the VetKey is actually used directly.
|
|
225
|
+
* However the more common usage of VetKD protocol is for distribution of
|
|
226
|
+
* encryption keys (eg AES keys to encrypt content).
|
|
227
|
+
*/
|
|
228
|
+
export declare class VetKey {
|
|
229
|
+
#private;
|
|
230
|
+
/**
|
|
231
|
+
* Return the VetKey bytes, aka the BLS signature
|
|
232
|
+
*
|
|
233
|
+
* Use the raw bytes only if your design makes use of the fact that VetKeys
|
|
234
|
+
* are BLS signatures (eg for random beacon or threshold BLS signature
|
|
235
|
+
* generation). If you are using VetKD for key distribution, instead use
|
|
236
|
+
* deriveSymmetricKey or asHkdfCryptoKey
|
|
237
|
+
*/
|
|
238
|
+
signatureBytes(): Uint8Array;
|
|
239
|
+
/**
|
|
240
|
+
* Return the serialization of the VetKey
|
|
241
|
+
*
|
|
242
|
+
* This is the byte encoding of the unencrypted VetKey.
|
|
243
|
+
*/
|
|
244
|
+
serialize(): Uint8Array;
|
|
245
|
+
/**
|
|
246
|
+
* Derive a symmetric key of the requested length from the VetKey
|
|
247
|
+
*
|
|
248
|
+
* As an alternative to this function consider using asDerivedKeyMaterial,
|
|
249
|
+
* which uses the WebCrypto API and prevents export of the underlying key.
|
|
250
|
+
*
|
|
251
|
+
* The `domainSep` parameter should be a string unique to your application and
|
|
252
|
+
* also your usage of the resulting key. For example say your application
|
|
253
|
+
* "my-app" is deriving two keys, one for usage "foo" and the other for
|
|
254
|
+
* "bar". You might use as domain separators "my-app-foo" and "my-app-bar".
|
|
255
|
+
*
|
|
256
|
+
* The returned Uint8Array will be `outputLength` bytes long.
|
|
257
|
+
*/
|
|
258
|
+
deriveSymmetricKey(domainSep: Uint8Array | string, outputLength: number): Uint8Array;
|
|
259
|
+
/**
|
|
260
|
+
* Return a DerivedKeyMaterial type which is suitable for further key derivation
|
|
261
|
+
*/
|
|
262
|
+
asDerivedKeyMaterial(): Promise<DerivedKeyMaterial>;
|
|
263
|
+
/**
|
|
264
|
+
* Deserialize a VetKey from the 48 byte encoding of the BLS signature
|
|
265
|
+
*
|
|
266
|
+
* This deserializes the same value as returned by serialize (or signatureBytes)
|
|
267
|
+
*/
|
|
268
|
+
static deserialize(bytes: Uint8Array): VetKey;
|
|
269
|
+
/**
|
|
270
|
+
* @internal getter returning the point object of the VetKey
|
|
271
|
+
*
|
|
272
|
+
* Applications would not usually need to call this
|
|
273
|
+
*/
|
|
274
|
+
getPoint(): G1Point;
|
|
275
|
+
/**
|
|
276
|
+
* @internal constructor
|
|
277
|
+
*
|
|
278
|
+
* This is public for typing reasons but there is no reason for an application
|
|
279
|
+
* to call this constructor.
|
|
280
|
+
*/
|
|
281
|
+
constructor(pt: G1Point);
|
|
282
|
+
}
|
|
283
|
+
export declare class DerivedKeyMaterial {
|
|
284
|
+
#private;
|
|
285
|
+
/**
|
|
286
|
+
* @internal constructor
|
|
287
|
+
*/
|
|
288
|
+
private constructor();
|
|
289
|
+
static fromCryptoKey(raw: CryptoKey): Promise<DerivedKeyMaterial>;
|
|
290
|
+
/**
|
|
291
|
+
* @internal constructor
|
|
292
|
+
*/
|
|
293
|
+
static setup(vetkey: Uint8Array<ArrayBuffer>): Promise<DerivedKeyMaterial>;
|
|
294
|
+
/**
|
|
295
|
+
* Return the CryptoKey
|
|
296
|
+
*/
|
|
297
|
+
getCryptoKey(): CryptoKey;
|
|
298
|
+
/**
|
|
299
|
+
* Return a WebCrypto CryptoKey handle suitable for AES-GCM encryption/decryption
|
|
300
|
+
*
|
|
301
|
+
* The key is derived using HKDF with the provided domain separator
|
|
302
|
+
*
|
|
303
|
+
* The CryptoKey is not exportable
|
|
304
|
+
*/
|
|
305
|
+
private deriveAesGcmCryptoKey;
|
|
306
|
+
/**
|
|
307
|
+
* Encrypt the provided message using AES-GCM and a key derived using HKDF
|
|
308
|
+
*
|
|
309
|
+
* The GCM key is derived using HKDF with the provided domain separator
|
|
310
|
+
*/
|
|
311
|
+
encryptMessage(message: Uint8Array | string, domainSep: Uint8Array | string, associatedData: Uint8Array | string): Promise<Uint8Array>;
|
|
312
|
+
/**
|
|
313
|
+
* Decrypt the provided ciphertext using AES-GCM and a key derived using HKDF
|
|
314
|
+
*
|
|
315
|
+
* The GCM key is derived using HKDF with the provided domain separator
|
|
316
|
+
*/
|
|
317
|
+
decryptMessage(message: Uint8Array, domainSep: Uint8Array | string, associatedData: Uint8Array | string): Promise<Uint8Array>;
|
|
318
|
+
}
|
|
319
|
+
export declare class EncryptedVetKey {
|
|
320
|
+
#private;
|
|
321
|
+
/**
|
|
322
|
+
* Parse an encrypted key returned by the `vetkd_derive_encrypted_key`
|
|
323
|
+
* managment canister interface
|
|
324
|
+
*/
|
|
325
|
+
static deserialize(bytes: Uint8Array): EncryptedVetKey;
|
|
326
|
+
/**
|
|
327
|
+
* Decrypt the encrypted key returning a VetKey
|
|
328
|
+
*/
|
|
329
|
+
decryptAndVerify(tsk: TransportSecretKey, dpk: DerivedPublicKey, input: Uint8Array): VetKey;
|
|
330
|
+
/**
|
|
331
|
+
* @internal constructor
|
|
332
|
+
*/
|
|
333
|
+
private constructor();
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* An identity used for identity based encryption
|
|
337
|
+
*
|
|
338
|
+
* As far as the IBE encryption scheme goes this is simply an opauqe bytestring
|
|
339
|
+
* We provide a type to make code using the IBE a bit easier to understand
|
|
340
|
+
*/
|
|
341
|
+
export declare class IbeIdentity {
|
|
342
|
+
#private;
|
|
343
|
+
private constructor();
|
|
344
|
+
/**
|
|
345
|
+
* Create an identity from a byte string
|
|
346
|
+
*/
|
|
347
|
+
static fromBytes(bytes: Uint8Array): IbeIdentity;
|
|
348
|
+
/**
|
|
349
|
+
* Create an identity from a string
|
|
350
|
+
*/
|
|
351
|
+
static fromString(bytes: string): IbeIdentity;
|
|
352
|
+
/**
|
|
353
|
+
* Create an identity from a Principal
|
|
354
|
+
*/
|
|
355
|
+
static fromPrincipal(principal: Principal): IbeIdentity;
|
|
356
|
+
/**
|
|
357
|
+
* @internal getter returning the encoded
|
|
358
|
+
*/
|
|
359
|
+
getBytes(): Uint8Array;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* A random seed, used for identity based encryption
|
|
363
|
+
*/
|
|
364
|
+
export declare class IbeSeed {
|
|
365
|
+
#private;
|
|
366
|
+
private constructor();
|
|
367
|
+
/**
|
|
368
|
+
* Create a seed for IBE encryption from a byte string
|
|
369
|
+
*
|
|
370
|
+
* This input should be randomly chosen by a secure random number generator.
|
|
371
|
+
* If the seed is not securely generated the IBE scheme will be insecure.
|
|
372
|
+
*
|
|
373
|
+
* At least 128 bits (16 bytes) must be provided.
|
|
374
|
+
*
|
|
375
|
+
* If the input is exactly 256 bits it is used directly. Otherwise the input
|
|
376
|
+
* is hashed with HKDF to produce a 256 bit seed.
|
|
377
|
+
*/
|
|
378
|
+
static fromBytes(bytes: Uint8Array): IbeSeed;
|
|
379
|
+
/**
|
|
380
|
+
* Create a random seed for IBE encryption
|
|
381
|
+
*/
|
|
382
|
+
static random(): IbeSeed;
|
|
383
|
+
/**
|
|
384
|
+
* @internal getter returning the seed bytes
|
|
385
|
+
*/
|
|
386
|
+
getBytes(): Uint8Array;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* IBE (Identity Based Encryption)
|
|
390
|
+
*/
|
|
391
|
+
export declare class IbeCiphertext {
|
|
392
|
+
#private;
|
|
393
|
+
/**
|
|
394
|
+
* Helper function for determining the size of an IBE ciphertext in bytes.
|
|
395
|
+
*/
|
|
396
|
+
static ciphertextSize(plaintextSize: number): number;
|
|
397
|
+
/**
|
|
398
|
+
* Helper function for determining the size of an IBE plaintext in bytes.
|
|
399
|
+
*/
|
|
400
|
+
static plaintextSize(ciphertextSize: number): number;
|
|
401
|
+
/**
|
|
402
|
+
* Serialize the IBE ciphertext to a bytestring
|
|
403
|
+
*/
|
|
404
|
+
serialize(): Uint8Array;
|
|
405
|
+
/**
|
|
406
|
+
* Deserialize an IBE ciphertext
|
|
407
|
+
*/
|
|
408
|
+
static deserialize(bytes: Uint8Array): IbeCiphertext;
|
|
409
|
+
/**
|
|
410
|
+
* Encrypt a message using IBE, returning the ciphertext
|
|
411
|
+
*
|
|
412
|
+
* Any user who is able to retrieve the VetKey for the specified derived public key and
|
|
413
|
+
* identity will be able to decrypt this message.
|
|
414
|
+
*
|
|
415
|
+
* There is no fixed upper bound on the size of the message that can be encrypted using
|
|
416
|
+
* this scheme. However, internally during the encryption process several heap allocations
|
|
417
|
+
* are performed which are approximately the same length as the message itself, so
|
|
418
|
+
* encrypting or decrypting very large messages may result in memory allocation errors.
|
|
419
|
+
*
|
|
420
|
+
* If you anticipate using IBE to encrypt very large messages, consider using IBE just to
|
|
421
|
+
* encrypt a symmetric key, and then using a standard cipher such as AES-GCM to encrypt the
|
|
422
|
+
* data.
|
|
423
|
+
*
|
|
424
|
+
* The seed parameter must be a randomly generated value that was generated just for this
|
|
425
|
+
* one message. Using it for a second message, or for any other purpose, compromises the
|
|
426
|
+
* security of the IBE scheme.
|
|
427
|
+
*/
|
|
428
|
+
static encrypt(dpk: DerivedPublicKey, identity: IbeIdentity, msg: Uint8Array, seed: IbeSeed): IbeCiphertext;
|
|
429
|
+
/**
|
|
430
|
+
* Decrypt an IBE ciphertext, returning the message
|
|
431
|
+
*
|
|
432
|
+
* There is no fixed upper bound on the size of the message that can be encrypted using
|
|
433
|
+
* this scheme. However, internally during the encryption process several heap allocations
|
|
434
|
+
* are performed which are approximately the same length as the message itself, so
|
|
435
|
+
* encrypting or decrypting very large messages may result in memory allocation errors.
|
|
436
|
+
*/
|
|
437
|
+
decrypt(vetkd: VetKey): Uint8Array;
|
|
438
|
+
/**
|
|
439
|
+
* Private constructor
|
|
440
|
+
*/
|
|
441
|
+
private constructor();
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* VRF (Verifiable Random Function) Output
|
|
445
|
+
*
|
|
446
|
+
* VetKD can be used to construct a VRF, which is a public key version of a
|
|
447
|
+
* keyed hash. Like a standard keyed hash, it takes an input string and produces
|
|
448
|
+
* a output string which is indistinguishable from random. The difference
|
|
449
|
+
* between a VRF and a normal keyed hash is that a VRF can only be computed
|
|
450
|
+
* by someone with access to the VRF secret key, while the VRF output can be verified
|
|
451
|
+
* by any party with access to the public key.
|
|
452
|
+
*
|
|
453
|
+
* For some general background on VRFs consult [RFC 9381](https://www.rfc-editor.org/rfc/rfc9381.html)
|
|
454
|
+
*/
|
|
455
|
+
export declare class VrfOutput {
|
|
456
|
+
#private;
|
|
457
|
+
private static computeVrfHash;
|
|
458
|
+
/**
|
|
459
|
+
* Serialize a VrfOutput to a byte string
|
|
460
|
+
*/
|
|
461
|
+
serialize(): Uint8Array;
|
|
462
|
+
/**
|
|
463
|
+
* Deserialize and verify a VrfOutput
|
|
464
|
+
*
|
|
465
|
+
* Note this verifies the VrfOutput with respect to the derived public key
|
|
466
|
+
* and VRF input which are included in the struct. It is the responsibility
|
|
467
|
+
* of the application to examine the return value of `publicKey` and `input`
|
|
468
|
+
* and ensure these values make sense in the context where this VRF is being
|
|
469
|
+
* used.
|
|
470
|
+
*/
|
|
471
|
+
static deserialize(bytes: Uint8Array): VrfOutput;
|
|
472
|
+
/**
|
|
473
|
+
* Return the public key under which this VRF output was derived
|
|
474
|
+
*/
|
|
475
|
+
publicKey(): DerivedPublicKey;
|
|
476
|
+
/**
|
|
477
|
+
* Return the input that was used to create this VRF output
|
|
478
|
+
*/
|
|
479
|
+
input(): Uint8Array;
|
|
480
|
+
/**
|
|
481
|
+
* Return the VRF output
|
|
482
|
+
*
|
|
483
|
+
* This is a random-looking value which was provably generated by some party with
|
|
484
|
+
* access to the VRF secret key.
|
|
485
|
+
*/
|
|
486
|
+
output(): Uint8Array;
|
|
487
|
+
/**
|
|
488
|
+
* Private constructor
|
|
489
|
+
*/
|
|
490
|
+
private constructor();
|
|
491
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@icp-sdk/vetkeys",
|
|
3
|
+
"version": "0.5.0-beta.0",
|
|
4
|
+
"packageManager": "pnpm@10.10.0",
|
|
5
|
+
"author": "DFINITY Stiftung",
|
|
6
|
+
"description": "JavaScript and TypeScript library to use Internet Computer vetKeys",
|
|
7
|
+
"homepage": "https://internetcomputer.org/docs/building-apps/network-features/vetkeys/introduction",
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/dfinity/vetkeys.git",
|
|
12
|
+
"directory": "frontend/ic_vetkeys"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/dfinity/vetkeys/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"internet computer",
|
|
19
|
+
"internet-computer",
|
|
20
|
+
"ic",
|
|
21
|
+
"icp",
|
|
22
|
+
"dfinity",
|
|
23
|
+
"vetkeys",
|
|
24
|
+
"encryption",
|
|
25
|
+
"decryption",
|
|
26
|
+
"threshold",
|
|
27
|
+
"motoko",
|
|
28
|
+
"rust",
|
|
29
|
+
"javascript",
|
|
30
|
+
"typescript",
|
|
31
|
+
"blockchain",
|
|
32
|
+
"crypto",
|
|
33
|
+
"distributed",
|
|
34
|
+
"api",
|
|
35
|
+
"bls",
|
|
36
|
+
"bls12-381",
|
|
37
|
+
"ibe",
|
|
38
|
+
"signature",
|
|
39
|
+
"signing"
|
|
40
|
+
],
|
|
41
|
+
"files": [
|
|
42
|
+
"dist"
|
|
43
|
+
],
|
|
44
|
+
"exports": {
|
|
45
|
+
".": {
|
|
46
|
+
"import": "./dist/lib/index.es.js",
|
|
47
|
+
"types": "./dist/types/index.d.ts"
|
|
48
|
+
},
|
|
49
|
+
"./key_manager": {
|
|
50
|
+
"import": "./dist/lib/key_manager.es.js",
|
|
51
|
+
"types": "./dist/types/key_manager/index.d.ts"
|
|
52
|
+
},
|
|
53
|
+
"./encrypted_maps": {
|
|
54
|
+
"import": "./dist/lib/encrypted_maps.es.js",
|
|
55
|
+
"types": "./dist/types/encrypted_maps/index.d.ts"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"module": "dist/lib/index.es.js",
|
|
59
|
+
"typings": "dist/types/index.d.ts",
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@icp-sdk/core": "^5.2.1",
|
|
62
|
+
"idb-keyval": "^6.2.1"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@noble/curves": "^1.9.7",
|
|
66
|
+
"@noble/hashes": "^1.8.0",
|
|
67
|
+
"@eslint/js": "^9.22.0",
|
|
68
|
+
"@types/node": "^24.0.4",
|
|
69
|
+
"@vitest/coverage-v8": "^3.0.5",
|
|
70
|
+
"eslint": "^9.22",
|
|
71
|
+
"eslint-config-prettier": "^10.1.5",
|
|
72
|
+
"eslint-plugin-prettier": "^5.2.6",
|
|
73
|
+
"fake-indexeddb": "^6.0.0",
|
|
74
|
+
"prettier": "^3.5.3",
|
|
75
|
+
"typedoc": "^0.28.3",
|
|
76
|
+
"typescript": "^5.9.3",
|
|
77
|
+
"typescript-eslint": "^8.59.0",
|
|
78
|
+
"vite": "^7.0.8",
|
|
79
|
+
"vite-plugin-dts": "^4.5.3",
|
|
80
|
+
"vitest": "^3.0.5"
|
|
81
|
+
},
|
|
82
|
+
"scripts": {
|
|
83
|
+
"build": "tsc && vite build",
|
|
84
|
+
"prepare": "pnpm run build",
|
|
85
|
+
"coverage": "pnpm run test:deploy_all && CANISTER_ID_IC_VETKEYS_MANAGER_CANISTER=$(cd $(git rev-parse --show-toplevel)/backend/rs/canisters && icp canister status ic_vetkeys_manager_canister -e local --id-only) CANISTER_ID_IC_VETKEYS_ENCRYPTED_MAPS_CANISTER=$(cd $(git rev-parse --show-toplevel)/backend/rs/canisters && icp canister status ic_vetkeys_encrypted_maps_canister -e local --id-only) vitest run --coverage",
|
|
86
|
+
"lint": "eslint",
|
|
87
|
+
"make:docs": "mkdir -p $(git rev-parse --show-toplevel)/docs/key_manager && mkdir -p $(git rev-parse --show-toplevel)/docs/encrypted_maps && typedoc --out $(git rev-parse --show-toplevel)/docs",
|
|
88
|
+
"prettier": "prettier --write .",
|
|
89
|
+
"prettier-check": "prettier --check .",
|
|
90
|
+
"test_utils": "vitest utils",
|
|
91
|
+
"test": "pnpm run test:deploy_all && CANISTER_ID_IC_VETKEYS_MANAGER_CANISTER=$(cd $(git rev-parse --show-toplevel)/backend/rs/canisters && icp canister status ic_vetkeys_manager_canister -e local --id-only) CANISTER_ID_IC_VETKEYS_ENCRYPTED_MAPS_CANISTER=$(cd $(git rev-parse --show-toplevel)/backend/rs/canisters && icp canister status ic_vetkeys_encrypted_maps_canister -e local --id-only) vitest run --sequence.concurrent",
|
|
92
|
+
"test:deploy_all": "cd $(git rev-parse --show-toplevel)/backend/rs/canisters && (icp network stop || true) && icp network start -d && icp deploy ic_vetkeys_manager_canister -e local && icp deploy ic_vetkeys_encrypted_maps_canister -e local",
|
|
93
|
+
"test:deploy_key_manager_canister": "cd $(git rev-parse --show-toplevel)/backend/rs/canisters && (icp network stop || true) && icp network start -d && icp deploy ic_vetkeys_manager_canister -e local",
|
|
94
|
+
"test:deploy_encrypted_maps_canister": "cd $(git rev-parse --show-toplevel)/backend/rs/canisters && (icp network stop || true) && icp network start -d && icp deploy ic_vetkeys_encrypted_maps_canister -e local"
|
|
95
|
+
}
|
|
96
|
+
}
|