Skip to content

Commit

Permalink
Return not prefixed signature from sdk event response
Browse files Browse the repository at this point in the history
  • Loading branch information
Comp0te committed Dec 9, 2024
1 parent cdc5091 commit c3a9479
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/libs/services/deployer-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export const signLedgerDeploy = async (

const approval = new DeployUtil.Approval();
approval.signer = activeAccount.publicKey;
approval.signature = resp.signatureHex;
approval.signature = resp.prefixedSignatureHex;
deploy.approvals.push(approval);

return deploy;
Expand Down
14 changes: 8 additions & 6 deletions src/libs/services/ledger/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,18 @@ export class Ledger {
? result.signatureRSV.subarray(0, 64)
: result.signatureRSV;

const signatureHex = `02${patchedSignature.toString('hex')}`;
const prefixedSignatureHex = `02${patchedSignature.toString('hex')}`;

this.#LedgerEventStatussSubject.next({
status: LedgerEventStatus.SignatureCompleted,
publicKey: account.publicKey,
deployHash,
signatureHex
signatureHex: prefixedSignatureHex
});

const prefix = new Uint8Array([0x02]);

if (!signatureHex) {
if (!prefixedSignatureHex) {
this.#processError({
status: LedgerEventStatus.SignatureFailed,
publicKey: account.publicKey,
Expand All @@ -323,8 +323,10 @@ export class Ledger {
}

return {
signatureHex,
signature: new Uint8Array([...prefix, ...patchedSignature])
signatureHex: patchedSignature.toString('hex'),
signature: patchedSignature,
prefixedSignatureHex,
prefixedSignature: new Uint8Array([...prefix, ...patchedSignature])
};
} catch (e) {
if (e instanceof LedgerError) {
Expand All @@ -342,7 +344,7 @@ export class Ledger {
async signMessage(
message: string,
account: Partial<LedgerAccount>
): Promise<SignResult> {
): Promise<Pick<SignResult, 'signature' | 'signatureHex'>> {
try {
if (account.index === undefined) {
this.#processError({ status: LedgerEventStatus.InvalidIndex });
Expand Down
2 changes: 2 additions & 0 deletions src/libs/services/ledger/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export interface LedgerAccountsOptions {
export interface SignResult {
signatureHex: string;
signature: Uint8Array;
prefixedSignatureHex: string;
prefixedSignature: Uint8Array;
}

export type LedgerTransport = 'USB' | 'Bluetooth';
Expand Down

0 comments on commit c3a9479

Please sign in to comment.