@@ -68,17 +68,23 @@ export class Account {
68
68
69
69
/**
70
70
* Attempts to create an account from a private key ciphertext
71
- * @param {PrivateKeyCiphertext | string } ciphertext The encrypted private key ciphertext or its string representation
72
- * @param {string } password The password used to decrypt the private key ciphertext
71
+ * @param {Object } params
72
+ * @param {PrivateKeyCiphertext | string } params.ciphertext The encrypted private key ciphertext or its string representation
73
+ * @param {string } params.password The password used to decrypt the private key ciphertext
73
74
* @returns {Account } A new Account instance created from the decrypted private key
74
75
*
75
76
* @example
76
77
* import { Account } from "@provablehq/sdk/testnet.js";
77
78
*
78
79
* // Create an account object from a previously encrypted ciphertext and password.
79
- * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
80
+ * const account = Account.fromCiphertext({
81
+ * ciphertext: process.env.ciphertext,
82
+ * password: process.env.password,
83
+ * });
80
84
*/
81
- public static fromCiphertext ( ciphertext : PrivateKeyCiphertext | string , password : string ) : Account {
85
+ public static fromCiphertext ( params : { ciphertext : PrivateKeyCiphertext | string , password : string } ) : Account {
86
+ let { ciphertext, password } = params ;
87
+
82
88
try {
83
89
ciphertext = ( typeof ciphertext === "string" ) ? PrivateKeyCiphertext . fromString ( ciphertext ) : ciphertext ;
84
90
const _privateKey = PrivateKey . fromPrivateKeyCiphertext ( ciphertext , password ) ;
@@ -211,7 +217,10 @@ export class Account {
211
217
*
212
218
* // Create a connection to the Aleo network and an account
213
219
* const networkClient = new AleoNetworkClient({ host: "https://api.explorer.provable.com/v1" });
214
- * const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
220
+ * const account = Account.fromCiphertext({
221
+ * ciphertext: process.env.ciphertext!,
222
+ * password: process.env.password!,
223
+ * });
215
224
*
216
225
* // Get the record ciphertexts from a transaction.
217
226
* const transaction = await networkClient.getTransactionObject("at1fjy6s9md2v4rgcn3j3q4qndtfaa2zvg58a4uha0rujvrn4cumu9qfazxdd");
@@ -241,7 +250,10 @@ export class Account {
241
250
*
242
251
* // Create a connection to the Aleo network and an account
243
252
* const networkClient = new AleoNetworkClient({ host: "https://api.explorer.provable.com/v1" });
244
- * const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
253
+ * const account = Account.fromCiphertext({
254
+ * ciphertext: process.env.ciphertext!,
255
+ * password: process.env.password!,
256
+ * });
245
257
*
246
258
* // Get the record ciphertexts from a transaction.
247
259
* const transaction = await networkClient.getTransactionObject("at1fjy6s9md2v4rgcn3j3q4qndtfaa2zvg58a4uha0rujvrn4cumu9qfazxdd");
@@ -259,14 +271,17 @@ export class Account {
259
271
* This key can be used to decrypt the record without revealing the account's view key.
260
272
* @param {RecordCiphertext | string } recordCiphertext The record ciphertext to generate the view key for
261
273
* @returns {Field } The record view key
262
- *
274
+ *
263
275
* @example
264
276
* // Import the Account class
265
277
* import { Account } from "@provablehq/sdk/testnet.js";
266
- *
278
+ *
267
279
* // Create an account object from a previously encrypted ciphertext and password.
268
- * const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
269
- *
280
+ * const account = Account.fromCiphertext({
281
+ * ciphertext: process.env.ciphertext!,
282
+ * password: process.env.password!,
283
+ * });
284
+ *
270
285
* // Generate a record view key from the account's view key and a record ciphertext
271
286
* const recordCiphertext = RecordCiphertext.fromString("your_record_ciphertext_here");
272
287
* const recordViewKey = account.generateRecordViewKey(recordCiphertext);
@@ -283,18 +298,18 @@ export class Account {
283
298
284
299
/**
285
300
* Generates a transition view key from the account owner's view key and the transition public key.
286
- * This key can be used to decrypt the private inputs and outputs of a the transition without
301
+ * This key can be used to decrypt the private inputs and outputs of a the transition without
287
302
* revealing the account's view key.
288
303
* @param {string | Group } tpk The transition public key
289
304
* @returns {Field } The transition view key
290
- *
305
+ *
291
306
* @example
292
307
* // Import the Account class
293
308
* import { Account } from "@provablehq/sdk/testnet.js";
294
- *
309
+ *
295
310
* // Generate a transition view key from the account's view key and a transition public key
296
311
* const tpk = Group.fromString("your_transition_public_key_here");
297
- *
312
+ *
298
313
* const transitionViewKey = account.generateTransitionViewKey(tpk);
299
314
*/
300
315
generateTransitionViewKey ( tpk : string | Group ) : Field {
@@ -315,7 +330,10 @@ export class Account {
315
330
*
316
331
* // Create a connection to the Aleo network and an account
317
332
* const networkClient = new AleoNetworkClient({ host: "https://api.explorer.provable.com/v1" });
318
- * const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
333
+ * const account = Account.fromCiphertext({
334
+ * ciphertext: process.env.ciphertext!,
335
+ * password: process.env.password!,
336
+ * });
319
337
*
320
338
* // Get the record ciphertexts from a transaction and check ownership of them.
321
339
* const transaction = await networkClient.getTransactionObject("at1fjy6s9md2v4rgcn3j3q4qndtfaa2zvg58a4uha0rujvrn4cumu9qfazxdd");
@@ -356,15 +374,18 @@ export class Account {
356
374
* import { Account } from "@provablehq/sdk/testnet.js";
357
375
*
358
376
* // Create a connection to the Aleo network and an account
359
- * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
377
+ * const account = Account.fromCiphertext({
378
+ * ciphertext: process.env.ciphertext,
379
+ * password: process.env.password,
380
+ * });
360
381
*
361
382
* // Create an account and a message to sign.
362
383
* const account = new Account();
363
384
* const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
364
385
* const signature = account.sign(message);
365
386
*
366
387
* // Verify the signature.
367
- * assert(account.verify(message, signature));
388
+ * assert(account.verify({ message, signature } ));
368
389
*/
369
390
sign ( message : Uint8Array ) : Signature {
370
391
return this . _privateKey . sign ( message ) ;
@@ -373,25 +394,30 @@ export class Account {
373
394
/**
374
395
* Verifies the Signature on a message.
375
396
*
376
- * @param {Uint8Array } message Message in bytes to be signed.
377
- * @param {Signature } signature Signature to be verified.
397
+ * @param {Object } params
398
+ * @param {Uint8Array } params.message Message in bytes to be signed.
399
+ * @param {Signature } params.signature Signature to be verified.
378
400
* @returns {boolean } True if the signature is valid, false otherwise.
379
401
*
380
402
* @example
381
403
* // Import the Account class
382
404
* import { Account } from "@provablehq/sdk/testnet.js";
383
405
*
384
406
* // Create a connection to the Aleo network and an account
385
- * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
407
+ * const account = Account.fromCiphertext({
408
+ * ciphertext: process.env.ciphertext,
409
+ * password: process.env.password,
410
+ * });
386
411
*
387
412
* // Sign a message.
388
413
* const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
389
414
* const signature = account.sign(message);
390
415
*
391
416
* // Verify the signature.
392
- * assert(account.verify(message, signature));
417
+ * assert(account.verify({ message, signature } ));
393
418
*/
394
- verify ( message : Uint8Array , signature : Signature ) : boolean {
419
+ verify ( params : { message : Uint8Array , signature : Signature } ) : boolean {
420
+ const { message, signature } = params ;
395
421
return this . _address . verify ( message , signature ) ;
396
422
}
397
423
}
0 commit comments