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

Commit

Permalink
Added Albedo wallet (#172)
Browse files Browse the repository at this point in the history
* In progress

* Albedo wallet added

* Clarify changelog update
  • Loading branch information
quietbits authored Aug 13, 2020
1 parent 1df1d9a commit 10d71fd
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/KeyManager.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/constants/keys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum KeyType {
albedo = "albedo",
ledger = "ledger",
lyra = "lyra",
plaintextKey = "plaintextKey",
Expand Down
42 changes: 42 additions & 0 deletions src/keyTypeHandlers/albedo.ts
Original file line number Diff line number Diff line change
@@ -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()}.`,
);
}
},
};
1 change: 1 addition & 0 deletions src/types/modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 10d71fd

Please sign in to comment.