Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 10 additions & 2 deletions src/client/LumClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,23 @@ 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++) {
const account = await this.getAccount(wallets[i].getAddress());
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);
};
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/LumLedgerWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class LumLedgerWallet extends LumWallet {
throw new Error('Feature not supported.');
};

signTransaction = async (doc: LumTypes.Doc): Promise<Uint8Array> => {
signTransaction = async (doc: LumTypes.Doc): Promise<[LumTypes.SignDoc, Uint8Array]> => {
if (!this.hdPath) {
throw new Error('No account selected.');
}
Expand Down Expand Up @@ -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<LumTypes.SignMsg> => {
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/LumOfflineSignerWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class LumOfflineSignerWallet extends LumWallet {
throw new Error('Feature not supported.');
};

signTransaction = async (doc: LumTypes.Doc): Promise<Uint8Array> => {
signTransaction = async (doc: LumTypes.Doc): Promise<[LumTypes.SignDoc, Uint8Array]> => {
if (!this.address || !this.publicKey) {
throw new Error('No account selected.');
}
Expand All @@ -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<LumTypes.SignMsg> => {
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/LumPaperWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class LumPaperWallet extends LumWallet {
return signature;
};

signTransaction = async (doc: LumTypes.Doc): Promise<Uint8Array> => {
signTransaction = async (doc: LumTypes.Doc): Promise<[LumTypes.SignDoc, Uint8Array]> => {
if (!this.privateKey || !this.publicKey) {
throw new Error('No account selected.');
}
Expand All @@ -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<LumTypes.SignMsg> => {
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/LumWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export abstract class LumWallet {
*
* @param doc document to sign
*/
abstract signTransaction(doc: LumTypes.Doc): Promise<Uint8Array>;
abstract signTransaction(doc: LumTypes.Doc): Promise<[LumTypes.SignDoc, Uint8Array]>;

/**
* Sign a message using a LumWallet
Expand Down