-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (signer-btc) [DSDK-471]: SignPsbt task (#581)
- Loading branch information
Showing
70 changed files
with
3,566 additions
and
1,162 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/device-management-kit": patch | ||
--- | ||
|
||
Fix CommandUtils static calls |
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,5 @@ | ||
--- | ||
"@ledgerhq/signer-utils": patch | ||
--- | ||
|
||
Create CommandErrorHelper to handle command errors |
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,5 @@ | ||
--- | ||
"@ledgerhq/device-signer-kit-bitcoin": minor | ||
--- | ||
|
||
Create SignPsbt API |
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,5 @@ | ||
--- | ||
"@ledgerhq/device-management-kit": patch | ||
--- | ||
|
||
Expose CommandSuccessResult |
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,5 @@ | ||
--- | ||
"@ledgerhq/device-signer-kit-bitcoin": patch | ||
--- | ||
|
||
Use CommandErrorHelper in BTC commands |
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
100 changes: 100 additions & 0 deletions
100
apps/sample/src/components/SignerBtcView/SignPsbtDAInputValusForm.tsx
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,100 @@ | ||
import React, { useCallback, useEffect } from "react"; | ||
import { DefaultDescriptorTemplate } from "@ledgerhq/device-signer-kit-bitcoin"; | ||
import { Flex, Input, SelectInput, Text } from "@ledgerhq/react-ui"; | ||
|
||
import { useForm } from "@/hooks/useForm"; | ||
|
||
type SignPsbtInputValuesType = { | ||
psbt: string; | ||
path: string; | ||
descriptorTemplate: DefaultDescriptorTemplate; | ||
}; | ||
|
||
const descriptorTemplateToDerivationPath: Record< | ||
DefaultDescriptorTemplate, | ||
string | ||
> = { | ||
[DefaultDescriptorTemplate.TAPROOT]: "86'/0'/0'", | ||
[DefaultDescriptorTemplate.NATIVE_SEGWIT]: "84'/0'/0'", | ||
[DefaultDescriptorTemplate.NESTED_SEGWIT]: "49'/0'/0'", | ||
[DefaultDescriptorTemplate.LEGACY]: "44'/0'/0'", | ||
}; | ||
|
||
const descriptorTemplateToLabel = { | ||
[DefaultDescriptorTemplate.TAPROOT]: "Taproot", | ||
[DefaultDescriptorTemplate.NATIVE_SEGWIT]: "Native Segwit", | ||
[DefaultDescriptorTemplate.NESTED_SEGWIT]: "Nested Segwit", | ||
[DefaultDescriptorTemplate.LEGACY]: "Legacy", | ||
}; | ||
|
||
export const SignPsbtDAInputValuesForm: React.FC<{ | ||
initialValues: SignPsbtInputValuesType; | ||
onChange: (values: SignPsbtInputValuesType) => void; | ||
disabled?: boolean; | ||
}> = ({ initialValues, onChange, disabled }) => { | ||
const { formValues, setFormValues, setFormValue } = useForm(initialValues); | ||
|
||
useEffect(() => { | ||
onChange(formValues); | ||
}, [formValues, onChange]); | ||
|
||
const onWalletDescriptorTemplateChange = useCallback( | ||
(value: DefaultDescriptorTemplate) => { | ||
const newValues = { | ||
path: descriptorTemplateToDerivationPath[value], | ||
descriptorTemplate: value, | ||
}; | ||
setFormValues((prev) => ({ ...prev, ...newValues })); | ||
}, | ||
[setFormValues], | ||
); | ||
|
||
return ( | ||
<Flex | ||
flexDirection="column" | ||
flex={1} | ||
rowGap={6} | ||
columnGap={6} | ||
flexWrap="wrap" | ||
> | ||
<Flex flexDirection="row" alignItems="center" mb={4}> | ||
<Text style={{ marginRight: 8 }}>Wallet address type</Text> | ||
<SelectInput | ||
options={Object.entries(DefaultDescriptorTemplate).map( | ||
([_key, value]) => ({ | ||
label: descriptorTemplateToLabel[value], | ||
value, | ||
}), | ||
)} | ||
value={{ | ||
label: descriptorTemplateToLabel[formValues.descriptorTemplate], | ||
value: formValues.descriptorTemplate, | ||
}} | ||
isMulti={false} | ||
isSearchable={false} | ||
onChange={(newVal) => | ||
newVal && onWalletDescriptorTemplateChange(newVal.value) | ||
} | ||
/> | ||
</Flex> | ||
|
||
<Input | ||
id="path" | ||
value={formValues.path} | ||
placeholder="path" | ||
onChange={(newVal) => setFormValue("path", newVal)} | ||
disabled={disabled} | ||
data-testid="input-text_path" | ||
/> | ||
|
||
<Input | ||
id="psbt" | ||
value={formValues.psbt} | ||
placeholder="psbt" | ||
onChange={(newVal) => setFormValue("psbt", newVal)} | ||
disabled={disabled} | ||
data-testid="input-text_psbt" | ||
/> | ||
</Flex> | ||
); | ||
}; |
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
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
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>; | ||
} |
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.