Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Trezor: custom prop to add manifest (#182)
Browse files Browse the repository at this point in the history
* Trezor: custom prop to add manifest

* Require custom prop to be an object + changelog updates
  • Loading branch information
quietbits authored Oct 28, 2020
1 parent 76fed29 commit 5ae0af7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## In master

## [v0.3.0-rc.1]
## [v0.3.0-rc.2]

- [KeyManager] Added optional `custom` prop to `signTransaction()` to allow
passing additional info.
- [KeyManager] Trezor wallet: pass manifest info through `custom` prop.

## [v0.3.0-rc.1](https://github.com/stellar/js-stellar-wallets/compare/v0.2.0-rc.2...v0.3.0-rc.1)

**Breaking changes**:

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stellar/wallet-sdk",
"version": "0.3.0-rc.1",
"version": "0.3.0-rc.2",
"description": "Libraries to help you write Stellar-enabled wallets in Javascript",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -87,7 +87,7 @@
"lodash": "^4.17.14",
"query-string": "^6.4.2",
"scrypt-async": "^2.0.1",
"trezor-connect": "^8.1.9",
"trezor-connect": "^8.1.16",
"tweetnacl": "^1.0.1",
"tweetnacl-util": "^0.15.0"
}
Expand Down
6 changes: 5 additions & 1 deletion src/KeyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export interface SignTransactionParams {
transaction: Transaction;
id: string;
password: string;
custom?: {
[key: string]: any;
};
}

export interface ChangePasswordParams {
Expand Down Expand Up @@ -236,7 +239,7 @@ export class KeyManager {
public async signTransaction(
params: SignTransactionParams,
): Promise<Transaction> {
const { transaction, id, password } = params;
const { transaction, id, password, custom } = params;
let key = this._readFromCache(id);

if (!key) {
Expand All @@ -257,6 +260,7 @@ export class KeyManager {
const signedTransaction = await keyHandler.signTransaction({
transaction,
key,
custom,
});
return signedTransaction;
}
Expand Down
14 changes: 13 additions & 1 deletion src/keyTypeHandlers/trezor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { transformTransaction } from "../helpers/trezorTransformTransaction";
export const trezorHandler: KeyTypeHandler = {
keyType: KeyType.trezor,
async signTransaction(params: HandlerSignTransactionParams) {
const { transaction, key } = params;
const { transaction, key, custom } = params;

if (key.privateKey !== "") {
throw new Error(
Expand All @@ -18,7 +18,19 @@ export const trezorHandler: KeyTypeHandler = {
);
}

if (!custom || !custom.email || !custom.appUrl) {
throw new Error(
`Trezor Connect manifest with "email" and "appUrl" props is required.
Make sure they are passed through "custom" prop.`,
);
}

try {
TrezorConnect.manifest({
email: custom.email,
appUrl: custom.appUrl,
});

const trezorParams = transformTransaction("m/44'/148'/0'", transaction);
const response = await TrezorConnect.stellarSignTransaction(trezorParams);

Expand Down
3 changes: 3 additions & 0 deletions src/types/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ export interface KeyStore {
export interface HandlerSignTransactionParams {
transaction: Transaction;
key: Key;
custom?: {
[key: string]: any;
};
}

/**
Expand Down

0 comments on commit 5ae0af7

Please sign in to comment.