Skip to content

Commit

Permalink
Update Ledger signing for multisig changes (anoma#388)
Browse files Browse the repository at this point in the history
* Update Ledger signing for multisig fixes

* Enable IBC now that it can be parsed
  • Loading branch information
jurevans authored Sep 26, 2023
1 parent 3bc89fa commit 2fb1bd5
Show file tree
Hide file tree
Showing 23 changed files with 188 additions and 266 deletions.
4 changes: 2 additions & 2 deletions apps/extension/src/background/ledger/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const DEFAULT_LEDGER_BIP44_PATH = makeBip44Path(coinType, {
});

export class Ledger {
constructor(public readonly namadaApp: NamadaApp | undefined = undefined) {}
constructor(public readonly namadaApp: NamadaApp | undefined = undefined) { }

/**
* Returns an initialized Ledger class instance with initialized Transport
Expand Down Expand Up @@ -85,7 +85,7 @@ export class Ledger {
// Return address as bech32-encoded string
address: address.toString(),
// Return public key as hex-encoded string
publicKey: publicKey.toString("hex"),
publicKey: publicKey.toString("hex").substring(2),
};
}

Expand Down
36 changes: 18 additions & 18 deletions apps/extension/src/background/ledger/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,20 @@ export class LedgerService {
bytes: string,
signatures: ResponseSign
): Promise<void> {
const { wrapperSignature, rawSignature } = signatures;
const { signature } = signatures;

if (!signature) {
throw new Error("Signature not provided")
}

try {
// Serialize signatures
const rawSig = encodeSignature(rawSignature);
const wrapperSig = encodeSignature(wrapperSignature);
const sig = encodeSignature(signature);

await this.sdk.submit_signed_reveal_pk(
fromBase64(txMsg),
fromBase64(bytes),
rawSig,
wrapperSig
sig,
);
} catch (e) {
console.warn(e);
Expand All @@ -118,25 +120,23 @@ export class LedgerService {
}

const encodedTx = getEncodedTxByType(txType, txMsg);
const { wrapperSignature, rawSignature } = signatures;
const { signature } = signatures;

if (!signature) {
throw new Error("Signature not provided!")
}

// Serialize signatures
const rawSig = encodeSignature(rawSignature);
const wrapperSig = encodeSignature(wrapperSignature);
const sig = encodeSignature(signature);

await this.broadcaster.startTx(msgId, txType);

try {
// TODO: Remove this check once IBC Transfer is supported on Ledger!
// Disable tx submission for Ledger devices
if (txType !== TxType.IBCTransfer) {
await this.sdk.submit_signed_tx(
encodedTx,
fromBase64(bytes),
rawSig,
wrapperSig
);
}
await this.sdk.submit_signed_tx(
encodedTx,
fromBase64(bytes),
sig,
);

// Clear pending tx if successful
await this.txStore.set(msgId, null);
Expand Down
12 changes: 6 additions & 6 deletions apps/extension/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ export const generateId = (
* Convert ISignature into serialized and encoded signature
*/
export const encodeSignature = (sig: ISignature): Uint8Array => {
const { secIndices, singlesig, sigType, multisigIndices, multisig } = sig;
const { pubkey, raw_indices, raw_signature, wrapper_indices, wrapper_signature } = sig;

/* eslint-disable */
const props = {
secIndices: new Uint8Array((secIndices as any).data),
singlesig: singlesig ? new Uint8Array((singlesig as any).data) : undefined,
sigType,
multisigIndices: new Uint8Array((multisigIndices as any).data),
multisig: multisig.map((sig) => new Uint8Array((sig as any).data))
pubkey: new Uint8Array((pubkey as any).data),
rawIndices: new Uint8Array((raw_indices as any).data),
rawSignature: new Uint8Array((raw_signature as any).data),
wrapperIndices: new Uint8Array((wrapper_indices as any).data),
wrapperSignature: new Uint8Array((wrapper_signature as any).data),
};
/* eslint-enable */

Expand Down
4 changes: 0 additions & 4 deletions packages/ledger-namada/dist/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ export declare const SIGN_VALUES_P2: {
export declare const ERROR_CODE: {
NoError: number;
};
export declare const enum SignatureType {
RawSignature = 0,
WrapperSignature = 1
}
export declare enum LedgerError {
U2FUnknown = 1,
U2FBadRequest = 2,
Expand Down
2 changes: 1 addition & 1 deletion packages/ledger-namada/dist/common.js.map

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions packages/ledger-namada/dist/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ export declare const INS: {
GET_IVK: number;
GET_OVK: number;
GET_NF: number;
GET_SIGNATURE: number;
};
export declare const SALT_LEN = 8;
export declare const HASH_LEN = 32;
export declare const PK_LEN_25519 = 32;
export declare const ED25519_SIGNATURE_LEN = 64;
export declare const PK_LEN_PLUS_TAG = 33;
export declare const SIG_LEN_PLUS_TAG = 65;
7 changes: 3 additions & 4 deletions packages/ledger-namada/dist/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/ledger-namada/dist/config.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions packages/ledger-namada/dist/namadaApp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
******************************************************************************* */
import Transport from '@ledgerhq/hw-transport';
import { ResponseAddress, ResponseAppInfo, ResponseBase, ResponseSign, ResponseVersion } from './types';
import { LedgerError, SignatureType } from './common';
export { LedgerError, SignatureType };
import { LedgerError } from './common';
export { LedgerError };
export * from './types';
export declare class NamadaApp {
transport: Transport;
Expand All @@ -28,7 +28,5 @@ export declare class NamadaApp {
getAddressAndPubKey(path: string): Promise<ResponseAddress>;
showAddressAndPubKey(path: string): Promise<ResponseAddress>;
signSendChunk(chunkIdx: number, chunkNum: number, chunk: Buffer, ins: number): Promise<ResponseBase>;
getSignature(signatureType: SignatureType): Promise<any>;
_sign(path: string, message: Buffer): Promise<any>;
sign(path: string, message: Buffer): Promise<ResponseSign>;
}
30 changes: 8 additions & 22 deletions packages/ledger-namada/dist/namadaApp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/ledger-namada/dist/namadaApp.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions packages/ledger-namada/dist/processResponses.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
******************************************************************************* */
/// <reference types="node" />
import { SignatureType } from './common';
import { ISignature } from './types';
export declare function processGetSignatureResponse(signatureType: SignatureType, response: Buffer): ISignature;
export declare function getSignatureResponse(response: Buffer): ISignature;
export declare function processGetAddrResponse(response: Buffer): {
publicKey: Buffer;
address: Buffer;
Expand Down
90 changes: 33 additions & 57 deletions packages/ledger-namada/dist/processResponses.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2fb1bd5

Please sign in to comment.