From 7de32b0ab82358b7bdbccd68e25376c4f59473a5 Mon Sep 17 00:00:00 2001 From: Nicolas Assouad Date: Tue, 1 Apr 2025 18:52:47 +0200 Subject: [PATCH] feat: new external signer to handle external signer provider such as Dfns --- src/signer/externalSigner.ts | 23 +++++++++++++++++++++++ src/signer/index.ts | 1 + 2 files changed, 24 insertions(+) create mode 100644 src/signer/externalSigner.ts diff --git a/src/signer/externalSigner.ts b/src/signer/externalSigner.ts new file mode 100644 index 000000000..3afc9be79 --- /dev/null +++ b/src/signer/externalSigner.ts @@ -0,0 +1,23 @@ +import { Signature } from '../types'; +import { Signer } from './default'; +import { SignerInterface } from './interface'; + +export class ExternalSigner extends Signer implements SignerInterface { + private readonly pubkey: () => Promise; + + private readonly signHash: (hash: string) => Promise; + + constructor(pubkey: () => Promise, signHash: (hash: string) => Promise) { + super(); + this.pubkey = pubkey; + this.signHash = signHash; + } + + public async getPubKey(): Promise { + return this.pubkey(); + } + + protected async signRaw(hash: string): Promise { + return this.signHash(hash); + } +} diff --git a/src/signer/index.ts b/src/signer/index.ts index 2a5e89a79..2d8c6dbf5 100644 --- a/src/signer/index.ts +++ b/src/signer/index.ts @@ -1,6 +1,7 @@ export * from './interface'; export * from './default'; export * from './ethSigner'; +export * from './externalSigner'; export { LedgerSigner111, getLedgerPathBuffer111,