forked from trezor/trezor-suite
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(connect): Add doc and more tests
- Loading branch information
Showing
3 changed files
with
205 additions
and
13 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,100 @@ | ||
## Cardano: Sign message | ||
|
||
Asks device to sign given message. User is presented with the first few bytes of the message and the hash of the whole message. User is asked to confirm details on Trezor. | ||
|
||
```javascript | ||
const result = await TrezorConnect.cardanoSignMessage(params); | ||
``` | ||
|
||
### Params | ||
|
||
[Optional common params](commonParams.md) | ||
|
||
[CardanoSignMessage type](https://github.com/trezor/trezor-suite/blob/develop/packages/connect/src/types/api/cardano/index.ts) | ||
|
||
- `signingPath` - _required_ `string | Array<number>` minimum length is `5`. [read more](../path.md) | ||
- `payload` - _required_ `string` message bytes in hex. | ||
- `hashPayload` - _required_ `boolean` if true, device will hash the payload before signing. Must be enabled if payload exceeds 1024 bytes. | ||
- `displayAscii` - _required_ `boolean` if true, device will decode payload as ASCII. | ||
- `networkId` - _optional_ `number` network identifier. Required if `addressParameters` are set. | ||
- `protocolMagic` - _optional_ `number` protocol magic. Required if `addressParameters` are set. | ||
- `addressParameters` - _optional_ `CardanoAddressParameters` object. [read more](./cardanoGetAddress.md#address-parameters) Used to derive address for message header. If not set then the key hash given by `signingPath` will be used instead. | ||
- `derivationType` — _optional_ `CardanoDerivationType` enum. determines used derivation type. Default is set to ICARUS_TREZOR=2 | ||
|
||
### Displaying payload | ||
|
||
If `hashPayload` is `true`, the device will display just the first 56 bytes of the payload. Otherwise 1024 bytes are displayed. | ||
|
||
The payload is decoded as a hex string if `displayAscii` is set to `false`. Otherwise it is decoded as an ASCII string, which succeeds only given the following conditions are met: | ||
|
||
- The payload is a valid ASCII string. | ||
- It must be clear to the user what the contents of the payload are, specifically there is: | ||
- At least one character | ||
- No control characters | ||
- No leading, trailing nor multiple consecutive spaces | ||
|
||
### Example | ||
|
||
Sign hash of "Hello Trezor!": | ||
|
||
```javascript | ||
TrezorConnect.cardanoSignMessage({ | ||
signingPath: "m/1852'/1815'/0'/0/0", | ||
payload: '48656c6c6f205472657a6f7221', // "Hello Trezor!" in hex | ||
hashPayload: true, | ||
displayAscii: true, | ||
}); | ||
``` | ||
|
||
Sign hash of "Hello Trezor!" using address parameters for header: | ||
|
||
```javascript | ||
TrezorConnect.cardanoSignMessage({ | ||
signingPath: "m/1852'/1815'/0'/0/0", | ||
payload: '48656c6c6f205472657a6f7221', // "Hello Trezor!" in hex | ||
hashPayload: true, | ||
displayAscii: true, | ||
networkId: 1, | ||
protocolMagic: 764824073, | ||
addressParameters: { | ||
addressType: 0, | ||
path: "m/1852'/1815'/0'/0/0", | ||
stakingPath: "m/1852'/1815'/0'/2/0", | ||
}, | ||
}); | ||
``` | ||
|
||
### Result | ||
|
||
[CardanoSignedMessage type](https://github.com/trezor/trezor-suite/blob/develop/packages/connect/src/types/api/cardano/index.ts) | ||
|
||
```javascript | ||
{ | ||
success: true, | ||
payload: { | ||
signature: string, | ||
payload: string, | ||
headers: { | ||
protected: { | ||
1: -8, // EdDSA algorithm | ||
address: string, | ||
}, | ||
unprotected: { | ||
hashed: boolean, | ||
version: number, | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Error | ||
|
||
```javascript | ||
{ | ||
success: false, | ||
payload: { | ||
error: string // error message | ||
} | ||
} | ||
``` |
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