-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (signer-btc): Implement signMessage device action
- Loading branch information
1 parent
882ed6e
commit cc784d5
Showing
35 changed files
with
1,500 additions
and
455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
"@ledgerhq/device-signer-kit-bitcoin": minor | ||
--- | ||
|
||
Implement ClientCommands | ||
Implement SignMessage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use client"; | ||
import React from "react"; | ||
|
||
import { SessionIdWrapper } from "@/components/SessionIdWrapper"; | ||
import { SignerBitcoinView } from "@/components/SignerBtcView"; | ||
|
||
const Signer: React.FC = () => { | ||
return <SessionIdWrapper ChildComponent={SignerBitcoinView} />; | ||
}; | ||
|
||
export default Signer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { useMemo } from "react"; | ||
import { | ||
SignerBtcBuilder, | ||
type SignMessageDAError, | ||
type SignMessageDAIntermediateValue, | ||
type SignMessageDAOutput, | ||
} from "@ledgerhq/device-signer-kit-bitcoin"; | ||
|
||
import { DeviceActionsList } from "@/components/DeviceActionsView/DeviceActionsList"; | ||
import { type DeviceActionProps } from "@/components/DeviceActionsView/DeviceActionTester"; | ||
import { useDmk } from "@/providers/DeviceManagementKitProvider"; | ||
|
||
const DEFAULT_DERIVATION_PATH = "44'/501'/0'/0'"; | ||
|
||
export const SignerBitcoinView: React.FC<{ sessionId: string }> = ({ | ||
sessionId, | ||
}) => { | ||
const dmk = useDmk(); | ||
const signer = new SignerBtcBuilder({ dmk, sessionId }).build(); | ||
|
||
const deviceModelId = dmk.getConnectedDevice({ | ||
sessionId, | ||
}).modelId; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const deviceActions: DeviceActionProps<any, any, any, any>[] = useMemo( | ||
() => [ | ||
{ | ||
title: "Sign message", | ||
description: | ||
"Perform all the actions necessary to sign a message with the device", | ||
executeDeviceAction: ({ derivationPath, message }) => { | ||
if (!signer) { | ||
throw new Error("Signer not initialized"); | ||
} | ||
return signer.signMessage(derivationPath, message); | ||
}, | ||
initialValues: { | ||
derivationPath: DEFAULT_DERIVATION_PATH, | ||
message: "Hello World", | ||
}, | ||
deviceModelId, | ||
} satisfies DeviceActionProps< | ||
SignMessageDAOutput, | ||
{ | ||
derivationPath: string; | ||
message: string; | ||
}, | ||
SignMessageDAError, | ||
SignMessageDAIntermediateValue | ||
>, | ||
], | ||
[deviceModelId, signer], | ||
); | ||
|
||
return ( | ||
<DeviceActionsList title="Bitcoin Signer" deviceActions={deviceActions} /> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
type DeviceManagementKit, | ||
type DeviceSessionId, | ||
} from "@ledgerhq/device-management-kit"; | ||
|
||
import { DefaultSignerBtc } from "@internal/DefaultSignerBtc"; | ||
|
||
type SignerBtcBuilderConstructorArgs = { | ||
dmk: DeviceManagementKit; | ||
sessionId: DeviceSessionId; | ||
}; | ||
|
||
/** | ||
* Builder for the `SignerBtc` class. | ||
* | ||
* @example | ||
* ``` | ||
* const signer = new SignerBtcBuilder({ dmk, sessionId }) | ||
* .build(); | ||
* ``` | ||
*/ | ||
export class SignerBtcBuilder { | ||
private _dmk: DeviceManagementKit; | ||
private _sessionId: DeviceSessionId; | ||
|
||
constructor({ dmk, sessionId }: SignerBtcBuilderConstructorArgs) { | ||
this._dmk = dmk; | ||
this._sessionId = sessionId; | ||
} | ||
|
||
/** | ||
* Build the btc signer | ||
* | ||
* @returns the bitcoin signer | ||
*/ | ||
public build() { | ||
return new DefaultSignerBtc({ | ||
dmk: this._dmk, | ||
sessionId: this._sessionId, | ||
}); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/signer/signer-btc/src/api/app-binder/SignMessageDeviceActionType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
type CommandErrorResult, | ||
type DeviceActionState, | ||
type ExecuteDeviceActionReturnType, | ||
type OpenAppDAError, | ||
type OpenAppDARequiredInteraction, | ||
type UserInteractionRequired, | ||
} from "@ledgerhq/device-management-kit"; | ||
|
||
import { type Signature } from "@api/model/Signature"; | ||
|
||
export type SignMessageDAOutput = Signature; | ||
|
||
export type SignMessageDAInput = { | ||
readonly derivationPath: string; | ||
readonly message: string; | ||
}; | ||
|
||
export type SignMessageDAError = OpenAppDAError | CommandErrorResult["error"]; | ||
|
||
type SignMessageDARequiredInteraction = | ||
| OpenAppDARequiredInteraction | ||
| UserInteractionRequired.SignPersonalMessage; | ||
|
||
export type SignMessageDAIntermediateValue = { | ||
requiredUserInteraction: SignMessageDARequiredInteraction; | ||
}; | ||
|
||
export type SignMessageDAState = DeviceActionState< | ||
SignMessageDAOutput, | ||
SignMessageDAError, | ||
SignMessageDAIntermediateValue | ||
>; | ||
|
||
export type SignMessageDAInternalState = { | ||
readonly error: SignMessageDAError | null; | ||
readonly signature: Signature | null; | ||
}; | ||
|
||
export type SignMessageDAReturnType = ExecuteDeviceActionReturnType< | ||
SignMessageDAOutput, | ||
SignMessageDAError, | ||
SignMessageDAIntermediateValue | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
export { type SignerBtc } from "./SignerBtc"; | ||
export * from "@api/app-binder/GetExtendedPublicKeyDeviceActionTypes"; | ||
export type { | ||
SignMessageDAError, | ||
SignMessageDAInput, | ||
SignMessageDAIntermediateValue, | ||
SignMessageDAOutput, | ||
SignMessageDAState, | ||
} from "@api/app-binder/SignMessageDeviceActionType"; | ||
export * from "@api/app-binder/SignMessageDeviceActionType"; | ||
export * from "@api/SignerBtc"; | ||
export * from "@api/SignerBtcBuilder"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.