-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
β¨ (signer-btc) [DSDK-471]: SignPsbt task #581
base: develop
Are you sure you want to change the base?
Changes from 9 commits
a342407
4ab77ac
758c7f9
4d156b7
562e05f
42114ec
5ee3e96
cee7864
0663f38
4f01dfe
242b0c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/device-management-kit": patch | ||
--- | ||
|
||
Fix CommandUtils static calls |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/signer-utils": patch | ||
--- | ||
|
||
Create CommandErrorHelper to handle command errors |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/device-signer-kit-bitcoin": minor | ||
--- | ||
|
||
Create SignPsbt API |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/device-management-kit": patch | ||
--- | ||
|
||
Expose CommandSuccessResult |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/device-signer-kit-bitcoin": patch | ||
--- | ||
|
||
Use CommandErrorHelper in BTC commands |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
import React, { useMemo } from "react"; | ||
import { | ||
DefaultDescriptorTemplate, | ||
DefaultWallet, | ||
type GetExtendedDAIntermediateValue, | ||
type GetExtendedPublicKeyDAError, | ||
type GetExtendedPublicKeyDAOutput, | ||
SignerBtcBuilder, | ||
type SignMessageDAError, | ||
type SignMessageDAIntermediateValue, | ||
type SignMessageDAOutput, | ||
type SignPsbtDAError, | ||
type SignPsbtDAIntermediateValue, | ||
type SignPsbtDAOutput, | ||
} from "@ledgerhq/device-signer-kit-bitcoin"; | ||
|
||
import { DeviceActionsList } from "@/components/DeviceActionsView/DeviceActionsList"; | ||
|
@@ -78,6 +83,37 @@ export const SignerBtcView: React.FC<{ sessionId: string }> = ({ | |
SignMessageDAError, | ||
SignMessageDAIntermediateValue | ||
>, | ||
{ | ||
title: "Sign psbt", | ||
description: | ||
"Perform all the actions necessary to sign a PSBT with the device", | ||
executeDeviceAction: ({ derivationPath, psbt }) => { | ||
if (!signer) { | ||
throw new Error("Signer not initialized"); | ||
} | ||
|
||
return signer.signPsbt( | ||
new DefaultWallet( | ||
derivationPath, | ||
DefaultDescriptorTemplate.NATIVE_SEGWIT, | ||
), | ||
psbt, | ||
); | ||
}, | ||
initialValues: { | ||
derivationPath: DEFAULT_DERIVATION_PATH, | ||
psbt: "70736274ff0104010101fb0402000000010204020000000105010100011004000000000103040100000001007102000000013daeeb9a92e7b5af90c787d53f0e60d2cf4cfd47bca9a0d8bc77a7464b024c0b00000000000000000002ff0300000000000016001402fe597c6ec0e2982712929bcf079a4e11d37e8d950b0000000000001600144dc432cb6a26c52a1e6ddd2bcf0ee49199fae0cc000000002206031869567d5e88d988ff7baf6827983f89530ddd79dbaeadaa6ec538a8f03dea8b18f5acc2fd540000800000008000000080000000000000000001011fff0300000000000016001402fe597c6ec0e2982712929bcf079a4e11d37e8d010e200cf08d04fa11ff024d5a50165ba65e495409b50ba6657788dfa15274adb682df010f0400000000000103086b01000000000000010416001429159115f12bb6a7e977439c83d3f8d555d72d5f00", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [COULD] Remove the default psbt here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, it's a heartache after so much difficulties to create it πΏ |
||
}, | ||
deviceModelId, | ||
} satisfies DeviceActionProps< | ||
SignPsbtDAOutput, | ||
{ | ||
psbt: string; | ||
derivationPath: string; | ||
}, | ||
SignPsbtDAError, | ||
SignPsbtDAIntermediateValue | ||
>, | ||
], | ||
[deviceModelId, signer], | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
// import { type AddressOptions } from "@api/model/AddressOptions"; | ||
// import { type Psbt } from "@api/model/Psbt"; | ||
// import { type Signature } from "@api/model/Signature"; | ||
// import { type Wallet } from "@api/model/Wallet"; | ||
import { type GetExtendedPublicKeyDAReturnType } from "@api/app-binder/GetExtendedPublicKeyDeviceActionTypes"; | ||
import { type SignMessageDAReturnType } from "@api/app-binder/SignMessageDeviceActionTypes"; | ||
import { type SignPsbtDAReturnType } from "@api/app-binder/SignPsbtDeviceActionTypes"; | ||
import { type AddressOptions } from "@api/model/AddressOptions"; | ||
import { | ||
type GetExtendedPublicKeyReturnType, | ||
type SignMessageDAReturnType, | ||
} from "@root/src"; | ||
import { type Psbt } from "@api/model/Psbt"; | ||
import { type Wallet } from "@api/model/Wallet"; | ||
|
||
export interface SignerBtc { | ||
getExtendedPublicKey: ( | ||
derivationPath: string, | ||
options: AddressOptions, | ||
) => GetExtendedPublicKeyReturnType; | ||
) => GetExtendedPublicKeyDAReturnType; | ||
signMessage: ( | ||
derivationPath: string, | ||
message: string, | ||
) => SignMessageDAReturnType; | ||
signPsbt: (wallet: Wallet, psbt: Psbt) => SignPsbtDAReturnType; | ||
// getAddress: (wallet: Wallet, options?: AddressOptions) => Promise<string>; | ||
// signPsbt: (wallet: Wallet, psbt: Psbt) => Promise<Psbt>; | ||
// signTransaction: (wallet: Wallet, psbt: Psbt) => Promise<Uint8Array>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
type CommandErrorResult, | ||
type DeviceActionState, | ||
type ExecuteDeviceActionReturnType, | ||
type OpenAppDAError, | ||
type OpenAppDARequiredInteraction, | ||
} from "@ledgerhq/device-management-kit"; | ||
|
||
import { type Psbt } from "@api/model/Psbt"; | ||
import { type Wallet } from "@api/model/Wallet"; | ||
import { type BtcErrorCodes } from "@internal/app-binder/command/utils/bitcoinAppErrors"; | ||
|
||
// @toDo Update this return value to Psbt once it would be updated in SignPsbtTask | ||
export type SignPsbtDAOutput = Uint8Array[]; | ||
|
||
export type SignPsbtDAInput = { | ||
psbt: Psbt; | ||
wallet: Wallet; | ||
}; | ||
|
||
export type SignPsbtDAError = | ||
| OpenAppDAError | ||
| CommandErrorResult<BtcErrorCodes>["error"]; | ||
|
||
type SignPsbtDARequiredInteraction = OpenAppDARequiredInteraction; | ||
|
||
export type SignPsbtDAIntermediateValue = { | ||
requiredUserInteraction: SignPsbtDARequiredInteraction; | ||
}; | ||
|
||
export type SignPsbtDAState = DeviceActionState< | ||
SignPsbtDAOutput, | ||
SignPsbtDAError, | ||
SignPsbtDAIntermediateValue | ||
>; | ||
|
||
export type SignPsbtDAInternalState = { | ||
readonly error: SignPsbtDAError | null; | ||
// [SHOULD] be psbt instead of signature | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ASK] What to do with this comment ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The next task I'm working on, UpdatePsbtTask, will modify this device action to return a psbt instead of a Signature There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually as discussed, we won't return a PSBT but the list of signature, with according index/tag/pubkey_augm (typing to be refined) |
||
readonly signature: Uint8Array[] | null; | ||
}; | ||
|
||
export type SignPsbtDAReturnType = ExecuteDeviceActionReturnType< | ||
SignPsbtDAOutput, | ||
SignPsbtDAError, | ||
SignPsbtDAIntermediateValue | ||
>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally we should be able to select the template we want to test. BOr another possibility would be to deduce it from the derivation path since we only support standard wallets for now, and derivation types also follow the standard as described here: https://learnmeabitcoin.com/technical/keys/hd-wallets/derivation-paths/
(also note that if derivation path and descriptor template are not consistent, it will be rejected by the device anyway)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I'll update the device action command form with a render prop to allow custom inputs