Skip to content

Commit cc63dc9

Browse files
authored
Update wallet interface to return signed doc (#31)
* Update wallet interface to return signed doc * Bump version to 0.6.0
1 parent 5ecc986 commit cc63dc9

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lum-network/sdk-javascript",
3-
"version": "0.5.3",
3+
"version": "0.6.0",
44
"license": "Apache-2.0",
55
"description": "Javascript SDK library for NodeJS and Web browsers to interact with the Lum Network.",
66
"homepage": "https://github.com/lum-network/sdk-javascript#readme",

src/client/LumClient.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,23 @@ export class LumClient {
272272
if (wallets.length < 1) {
273273
throw new Error('At least one wallet is required to sign the transaction');
274274
}
275-
const signDoc = LumUtils.generateSignDoc(doc, 0, wallets[0].signingMode());
275+
276+
let signDoc: LumTypes.SignDoc | undefined = undefined;
276277
const signatures: Uint8Array[] = [];
277278

278279
for (let i = 0; i < wallets.length; i++) {
279280
const account = await this.getAccount(wallets[i].getAddress());
280281
if (!account) {
281282
throw new Error(`Account not found for wallet at index ${i}`);
282283
}
283-
signatures.push(await wallets[i].signTransaction(doc));
284+
const [walletSignedDoc, signature] = await wallets[i].signTransaction(doc);
285+
if (i === 0) {
286+
signDoc = walletSignedDoc;
287+
}
288+
signatures.push(signature);
289+
}
290+
if (!signDoc) {
291+
throw new Error('Impossible error to avoid typescript warnings');
284292
}
285293
return LumUtils.generateTxBytes(signDoc, signatures);
286294
};

src/wallet/LumLedgerWallet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class LumLedgerWallet extends LumWallet {
4747
throw new Error('Feature not supported.');
4848
};
4949

50-
signTransaction = async (doc: LumTypes.Doc): Promise<Uint8Array> => {
50+
signTransaction = async (doc: LumTypes.Doc): Promise<[LumTypes.SignDoc, Uint8Array]> => {
5151
if (!this.hdPath) {
5252
throw new Error('No account selected.');
5353
}
@@ -76,7 +76,7 @@ export class LumLedgerWallet extends LumWallet {
7676
throw new Error(`Failed to sign message: error code ${return_code}`);
7777
}
7878
const sig = ExtendedSecp256k1Signature.fromDer(signature);
79-
return new Uint8Array([...sig.r(32), ...sig.s(32)]);
79+
return [LumUtils.generateSignDoc(doc, signerIndex, this.signingMode()), new Uint8Array([...sig.r(32), ...sig.s(32)])];
8080
};
8181

8282
signMessage = async (msg: string): Promise<LumTypes.SignMsg> => {

src/wallet/LumOfflineSignerWallet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class LumOfflineSignerWallet extends LumWallet {
4242
throw new Error('Feature not supported.');
4343
};
4444

45-
signTransaction = async (doc: LumTypes.Doc): Promise<Uint8Array> => {
45+
signTransaction = async (doc: LumTypes.Doc): Promise<[LumTypes.SignDoc, Uint8Array]> => {
4646
if (!this.address || !this.publicKey) {
4747
throw new Error('No account selected.');
4848
}
@@ -55,7 +55,7 @@ export class LumOfflineSignerWallet extends LumWallet {
5555
}
5656
const signDoc = LumUtils.generateSignDoc(doc, signerIndex, this.signingMode());
5757
const response = await this.offlineSigner.signDirect(this.address, signDoc);
58-
return LumUtils.fromBase64(response.signature.signature);
58+
return [response.signed, LumUtils.fromBase64(response.signature.signature)];
5959
};
6060

6161
signMessage = async (msg: string): Promise<LumTypes.SignMsg> => {

src/wallet/LumPaperWallet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class LumPaperWallet extends LumWallet {
5252
return signature;
5353
};
5454

55-
signTransaction = async (doc: LumTypes.Doc): Promise<Uint8Array> => {
55+
signTransaction = async (doc: LumTypes.Doc): Promise<[LumTypes.SignDoc, Uint8Array]> => {
5656
if (!this.privateKey || !this.publicKey) {
5757
throw new Error('No account selected.');
5858
}
@@ -67,7 +67,7 @@ export class LumPaperWallet extends LumWallet {
6767
const signBytes = LumUtils.generateSignDocBytes(signDoc);
6868
const hashedMessage = LumUtils.sha256(signBytes);
6969
const signature = await LumUtils.generateSignature(hashedMessage, this.privateKey);
70-
return signature;
70+
return [signDoc, signature];
7171
};
7272

7373
signMessage = async (msg: string): Promise<LumTypes.SignMsg> => {

src/wallet/LumWallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export abstract class LumWallet {
6464
*
6565
* @param doc document to sign
6666
*/
67-
abstract signTransaction(doc: LumTypes.Doc): Promise<Uint8Array>;
67+
abstract signTransaction(doc: LumTypes.Doc): Promise<[LumTypes.SignDoc, Uint8Array]>;
6868

6969
/**
7070
* Sign a message using a LumWallet

0 commit comments

Comments
 (0)