diff --git a/CHANGELOG.md b/CHANGELOG.md index b29940d4..f664edce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ - [KeyManager] Added Trezor wallet. - [KeyManager] Only sign SEP-10 auth transactions with seq number 0. - [DataProvider] Fix `watchPayments` stopper. -- [KeyManager] Added Lyra wallet. +- [KeyManager] Added Lyra wallet for key management. +- [KeyManager] Added Albedo wallet for key management. ## [v0.1.0-rc.1](https://github.com/stellar/js-stellar-wallets/compare/v0.0.9-rc.1...v0.1.0-rc.1) diff --git a/package.json b/package.json index b1ac4f48..01ef2fbf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@stellar/wallet-sdk", - "version": "0.1.0-rc.10", + "version": "0.1.0-rc.11", "description": "Libraries to help you write Stellar-enabled wallets in Javascript", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -78,6 +78,7 @@ "webpack-cli": "^3.3.10" }, "dependencies": { + "@albedo-link/intent": "^0.9.2", "@ledgerhq/hw-app-str": "^4.48.0", "@ledgerhq/hw-transport-u2f": "^4.48.0", "@stellar/lyra-api": "^1.0.0-alpha.2", diff --git a/src/KeyManager.ts b/src/KeyManager.ts index 7d7cf599..0e3ecfe4 100644 --- a/src/KeyManager.ts +++ b/src/KeyManager.ts @@ -1,5 +1,6 @@ import StellarSdk, { Transaction } from "stellar-sdk"; +import { albedoHandler } from "./keyTypeHandlers/albedo"; import { ledgerHandler } from "./keyTypeHandlers/ledger"; import { lyraHandler } from "./keyTypeHandlers/lyra"; import { plaintextKeyHandler } from "./keyTypeHandlers/plaintextKey"; @@ -86,6 +87,7 @@ export class KeyManager { constructor(params: KeyManagerParams) { this.encrypterMap = {}; this.keyHandlerMap = { + [KeyType.albedo]: albedoHandler, [KeyType.ledger]: ledgerHandler, [KeyType.lyra]: lyraHandler, [KeyType.plaintextKey]: plaintextKeyHandler, diff --git a/src/constants/keys.ts b/src/constants/keys.ts index ff120cb1..8a558e2c 100644 --- a/src/constants/keys.ts +++ b/src/constants/keys.ts @@ -1,4 +1,5 @@ export enum KeyType { + albedo = "albedo", ledger = "ledger", lyra = "lyra", plaintextKey = "plaintextKey", diff --git a/src/keyTypeHandlers/albedo.ts b/src/keyTypeHandlers/albedo.ts new file mode 100644 index 00000000..36bd4664 --- /dev/null +++ b/src/keyTypeHandlers/albedo.ts @@ -0,0 +1,42 @@ +import albedo from "@albedo-link/intent"; +import { Networks, Transaction, TransactionBuilder } from "stellar-sdk"; + +import { HandlerSignTransactionParams, KeyTypeHandler } from "../types"; + +import { KeyType } from "../constants/keys"; + +export const albedoHandler: KeyTypeHandler = { + keyType: KeyType.albedo, + async signTransaction(params: HandlerSignTransactionParams) { + const { transaction, key } = params; + + if (key.privateKey !== "") { + throw new Error( + `Non-ledger key sent to ledger handler: ${JSON.stringify( + key.publicKey, + )}`, + ); + } + + try { + const xdr = transaction.toXDR(); + const response = await albedo.tx({ xdr }); + + if (!response.signed_envelope_xdr) { + throw new Error("We couldn’t sign the transaction with Albedo."); + } + + // fromXDR() returns type "Transaction | FeeBumpTransaction" and + // signTransaction() doesn't like "| FeeBumpTransaction" type, so casting + // to "Transaction" type. + return TransactionBuilder.fromXDR( + response.signed_envelope_xdr, + Networks.PUBLIC, + ) as Transaction; + } catch (error) { + throw new Error( + `We couldn’t sign the transaction with Albedo. ${error.toString()}.`, + ); + } + }, +}; diff --git a/src/types/modules.d.ts b/src/types/modules.d.ts index a4173e47..3f148972 100644 --- a/src/types/modules.d.ts +++ b/src/types/modules.d.ts @@ -3,3 +3,4 @@ declare module "scrypt-async"; declare module "jest-mock-random"; // @types/trezor-connect doesn't have stellarSignTransaction() declare module "trezor-connect"; +declare module "@albedo-link/intent"; diff --git a/yarn.lock b/yarn.lock index f80c3dc2..a8b03ffa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,11 @@ # yarn lockfile v1 +"@albedo-link/intent@^0.9.2": + version "0.9.2" + resolved "https://registry.yarnpkg.com/@albedo-link/intent/-/intent-0.9.2.tgz#64d198a3a8fb4ed70ab17dee555f2fe59f5dcac6" + integrity sha512-toETcSL3seYeNvP9mxUdzpJ/7UxekF6+XrqnFWrlT7Khwne/ufEE2+kT7Zqc4Zp2awNZZtlyKzTdLEud4c+uEw== + "@babel/code-frame@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0.tgz#06e2ab19bdb535385559aabb5ba59729482800f8"