diff --git a/src/client.ts b/src/client.ts index 93a0f8dd..ffcd2b79 100644 --- a/src/client.ts +++ b/src/client.ts @@ -794,29 +794,35 @@ export class VocdoniSDKClient { * options, like extra information of the account, or the faucet package string * @returns {Promise} */ - createAccount( - options: { account?: Account; faucetPackage?: string; sik?: boolean; password?: string } = { + createAccount(options?: { + account?: Account; + faucetPackage?: string; + sik?: boolean; + password?: string; + }): Promise { + invariant(this.wallet, 'No wallet or signer set'); + const settings = { account: null, faucetPackage: null, sik: true, password: '0', - } - ): Promise { - invariant(this.wallet, 'No wallet or signer set'); + ...options, + }; + return this.fetchAccountInfo().catch(() => { - if (options?.sik) { + if (settings?.sik) { return this.signSIKPayload(this.wallet).then((signedPayload) => this.createAccountInfo({ - account: options?.account ?? new Account(), - faucetPackage: options?.faucetPackage, + account: settings?.account ?? new Account(), + faucetPackage: settings?.faucetPackage, signedSikPayload: signedPayload, - password: options.password, + password: settings.password, }) ); } return this.createAccountInfo({ - account: options?.account ?? new Account(), - faucetPackage: options?.faucetPackage, + account: settings?.account ?? new Account(), + faucetPackage: settings?.faucetPackage, }); }); } diff --git a/test/integration/zk.test.ts b/test/integration/zk.test.ts index 11670bde..f294c8bd 100644 --- a/test/integration/zk.test.ts +++ b/test/integration/zk.test.ts @@ -60,8 +60,6 @@ describe('zkSNARK test', () => { }); await client.createAccount({ - account: null, - faucetPackage: null, sik: true, password: 'password123', }); @@ -125,8 +123,6 @@ describe('zkSNARK test', () => { if (i % 3 == 0) { await client.createAccount({ - account: null, - faucetPackage: null, sik: true, password: participants[i].address, });