diff --git a/package.json b/package.json index 98ae9de..cc4a6bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lum-network/sdk-javascript", - "version": "0.5.3", + "version": "0.6.0", "license": "Apache-2.0", "description": "Javascript SDK library for NodeJS and Web browsers to interact with the Lum Network.", "homepage": "https://github.com/lum-network/sdk-javascript#readme", diff --git a/src/client/LumClient.ts b/src/client/LumClient.ts index 7ef476b..7c6841d 100644 --- a/src/client/LumClient.ts +++ b/src/client/LumClient.ts @@ -272,7 +272,8 @@ export class LumClient { if (wallets.length < 1) { throw new Error('At least one wallet is required to sign the transaction'); } - const signDoc = LumUtils.generateSignDoc(doc, 0, wallets[0].signingMode()); + + let signDoc: LumTypes.SignDoc | undefined = undefined; const signatures: Uint8Array[] = []; for (let i = 0; i < wallets.length; i++) { @@ -280,7 +281,14 @@ export class LumClient { if (!account) { throw new Error(`Account not found for wallet at index ${i}`); } - signatures.push(await wallets[i].signTransaction(doc)); + const [walletSignedDoc, signature] = await wallets[i].signTransaction(doc); + if (i === 0) { + signDoc = walletSignedDoc; + } + signatures.push(signature); + } + if (!signDoc) { + throw new Error('Impossible error to avoid typescript warnings'); } return LumUtils.generateTxBytes(signDoc, signatures); }; diff --git a/src/wallet/LumLedgerWallet.ts b/src/wallet/LumLedgerWallet.ts index c5c72e6..a6c20ea 100644 --- a/src/wallet/LumLedgerWallet.ts +++ b/src/wallet/LumLedgerWallet.ts @@ -47,7 +47,7 @@ export class LumLedgerWallet extends LumWallet { throw new Error('Feature not supported.'); }; - signTransaction = async (doc: LumTypes.Doc): Promise => { + signTransaction = async (doc: LumTypes.Doc): Promise<[LumTypes.SignDoc, Uint8Array]> => { if (!this.hdPath) { throw new Error('No account selected.'); } @@ -76,7 +76,7 @@ export class LumLedgerWallet extends LumWallet { throw new Error(`Failed to sign message: error code ${return_code}`); } const sig = ExtendedSecp256k1Signature.fromDer(signature); - return new Uint8Array([...sig.r(32), ...sig.s(32)]); + return [LumUtils.generateSignDoc(doc, signerIndex, this.signingMode()), new Uint8Array([...sig.r(32), ...sig.s(32)])]; }; signMessage = async (msg: string): Promise => { diff --git a/src/wallet/LumOfflineSignerWallet.ts b/src/wallet/LumOfflineSignerWallet.ts index bc4ed16..74a9e0c 100644 --- a/src/wallet/LumOfflineSignerWallet.ts +++ b/src/wallet/LumOfflineSignerWallet.ts @@ -42,7 +42,7 @@ export class LumOfflineSignerWallet extends LumWallet { throw new Error('Feature not supported.'); }; - signTransaction = async (doc: LumTypes.Doc): Promise => { + signTransaction = async (doc: LumTypes.Doc): Promise<[LumTypes.SignDoc, Uint8Array]> => { if (!this.address || !this.publicKey) { throw new Error('No account selected.'); } @@ -55,7 +55,7 @@ export class LumOfflineSignerWallet extends LumWallet { } const signDoc = LumUtils.generateSignDoc(doc, signerIndex, this.signingMode()); const response = await this.offlineSigner.signDirect(this.address, signDoc); - return LumUtils.fromBase64(response.signature.signature); + return [response.signed, LumUtils.fromBase64(response.signature.signature)]; }; signMessage = async (msg: string): Promise => { diff --git a/src/wallet/LumPaperWallet.ts b/src/wallet/LumPaperWallet.ts index 67bd5d9..1f3a3be 100644 --- a/src/wallet/LumPaperWallet.ts +++ b/src/wallet/LumPaperWallet.ts @@ -52,7 +52,7 @@ export class LumPaperWallet extends LumWallet { return signature; }; - signTransaction = async (doc: LumTypes.Doc): Promise => { + signTransaction = async (doc: LumTypes.Doc): Promise<[LumTypes.SignDoc, Uint8Array]> => { if (!this.privateKey || !this.publicKey) { throw new Error('No account selected.'); } @@ -67,7 +67,7 @@ export class LumPaperWallet extends LumWallet { const signBytes = LumUtils.generateSignDocBytes(signDoc); const hashedMessage = LumUtils.sha256(signBytes); const signature = await LumUtils.generateSignature(hashedMessage, this.privateKey); - return signature; + return [signDoc, signature]; }; signMessage = async (msg: string): Promise => { diff --git a/src/wallet/LumWallet.ts b/src/wallet/LumWallet.ts index 0352a68..53049f0 100644 --- a/src/wallet/LumWallet.ts +++ b/src/wallet/LumWallet.ts @@ -64,7 +64,7 @@ export abstract class LumWallet { * * @param doc document to sign */ - abstract signTransaction(doc: LumTypes.Doc): Promise; + abstract signTransaction(doc: LumTypes.Doc): Promise<[LumTypes.SignDoc, Uint8Array]>; /** * Sign a message using a LumWallet