Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tally wallet #506

Merged
merged 78 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
7781611
Add Tally HD wallet
0xzoz Apr 4, 2022
81166be
First pass - add tally as a hdwallet
0xzoz Apr 7, 2022
0ecada7
Modify tallyho-onboarding import
0xzoz Apr 7, 2022
8481ba8
Add tally to tsconfig
0xzoz Apr 8, 2022
948ce8b
Remove used type
0xzoz Apr 8, 2022
7d7e637
Remove Metamask references
0xzoz Apr 8, 2022
07cc87b
Reorder deps
0xzoz Apr 8, 2022
586fb9a
Make functions async
0xzoz Apr 8, 2022
0fcae1c
Fix package import
0xzoz Apr 8, 2022
5c4d9c8
Update packages/hdwallet-tally/tsconfig.json
0xzoz Apr 8, 2022
4e3a838
Update packages/hdwallet-tally/package.json
0xzoz Apr 8, 2022
0b0e667
Fix init function
0xzoz Apr 8, 2022
ed959f6
Merge branch 'add-tally-wallet' of https://github.com/0xzoz/hdwallet …
0xzoz Apr 8, 2022
4c5318c
Remove unneccesary functions and properties
0xzoz Apr 8, 2022
66a876a
Fix hdwallet-tally versioning
0xzoz Apr 8, 2022
273f353
Remove unneccesary properties
0xzoz Apr 8, 2022
8d12504
Remove TallyTransport function and references
0xzoz Apr 8, 2022
44c2ba6
Inject provider from adapter
0xzoz Apr 11, 2022
04a5333
Add adapter test
0xzoz Apr 12, 2022
b941445
Add ethereum test
0xzoz Apr 12, 2022
d599527
Add index test
0xzoz Apr 12, 2022
ba4518d
Fix isolated modules error
0xzoz Apr 12, 2022
e78237e
Fix isolated modules error
0xzoz Apr 12, 2022
56739fa
Fix tally test errors
0xzoz Apr 12, 2022
ddd480b
Fix tally test errors
0xzoz Apr 13, 2022
403a8bf
Fix Tally tests to pass
0xzoz Apr 14, 2022
97bd37a
Fix Tally tests to pass
0xzoz Apr 14, 2022
35a2712
Change error wording to match prod error
0xzoz Apr 15, 2022
399ebe1
Update packages/hdwallet-tally/src/tally.ts
0xzoz Apr 15, 2022
371d1df
Add test button in sandbox
0xzoz Apr 15, 2022
a3b9c7e
Merge branch 'add-tally-wallet' of https://github.com/0xzoz/hdwallet …
0xzoz Apr 15, 2022
1c32bf2
Fix name
0xzoz Apr 15, 2022
3e307a6
merge conflicts
0xzoz Apr 18, 2022
bcb5eae
Fix conflicts
0xzoz Apr 18, 2022
743c72b
Fix lint issues
0xzoz Apr 20, 2022
47e150a
Merge branch 'master' into add-tally-wallet
0xzoz Apr 20, 2022
0864019
Address merge issue with xDefi casing
0xzoz Apr 22, 2022
fa79588
Fix lockfile
0xzoz Apr 22, 2022
2390e4e
Merge branch 'shapeshift:master' into add-tally-wallet
0xzoz Apr 22, 2022
0c142aa
Downgrade typescript version
0xzoz Apr 25, 2022
1548023
Merge branch 'add-tally-wallet' of https://github.com/0xzoz/hdwallet …
0xzoz Apr 25, 2022
38d9522
Downgrade typescript version
0xzoz Apr 25, 2022
079901b
Fix typo
0xzoz Apr 25, 2022
dc92d5d
Fix yarn.lock
0xzoz Apr 25, 2022
3540db3
Fix yarn.lock
0xzoz Apr 25, 2022
468bb59
Fix typo
0xzoz Apr 25, 2022
4200e45
Fix xDEFI typo
0xzoz Apr 25, 2022
eac4450
Update tsconfig.json
0xzoz Apr 28, 2022
adb18b5
Update integration/src/wallets/tally.ts
0xzoz Apr 28, 2022
19ae7aa
Update package.json
0xzoz Apr 28, 2022
dd5d8da
Update packages/hdwallet-tally/src/adapter.ts
0xzoz Apr 28, 2022
132c06e
Update packages/hdwallet-tally/src/adapter.ts
0xzoz Apr 28, 2022
b52c472
Update packages/hdwallet-tally/src/adapter.ts
0xzoz Apr 28, 2022
66513b1
Update packages/hdwallet-tally/src/adapter.ts
0xzoz Apr 28, 2022
beb80dd
Update packages/hdwallet-tally/src/adapter.ts
0xzoz Apr 28, 2022
66f0e2e
Fix linting and testing issues after previous commits
0xzoz Apr 28, 2022
568ce3d
Update packages/hdwallet-tally/src/ethereum.ts
0xzoz Apr 28, 2022
cf85c7e
Update packages/hdwallet-tally/src/ethereum.ts
0xzoz Apr 28, 2022
7dccbd2
Update packages/hdwallet-tally/src/tally.ts
0xzoz Apr 28, 2022
08cc3dc
Update packages/hdwallet-tally/src/tally.ts
0xzoz Apr 28, 2022
8d2ab92
Update packages/hdwallet-tally/src/tally.ts
0xzoz Apr 28, 2022
1f88543
Update packages/hdwallet-tally/tsconfig.json
0xzoz Apr 28, 2022
9c47622
Update packages/hdwallet-xdefi/tsconfig.json
0xzoz Apr 28, 2022
812cfb1
Remove private from public var
0xzoz Apr 28, 2022
6599597
fix lint issue
0xzoz Apr 28, 2022
6d002fa
downgrade ts version
0xzoz May 10, 2022
53e1c79
Rename tally > tally ho due to branding change
0xzoz May 11, 2022
ae3a726
Fix build issue - name change
0xzoz May 11, 2022
70af112
Fix lint issues
0xzoz May 11, 2022
42d41cb
Rename folder to match package naming
0xzoz May 11, 2022
badf43c
Rename to match package naming
0xzoz May 11, 2022
06e8a32
Remove MM dependancies for Tally
0xzoz May 11, 2022
435ea5c
Remove noop
0xzoz May 11, 2022
d02c69f
Merge branch 'shapeshift:master' into add-tally-wallet
0xzoz May 12, 2022
2bad1a8
Add try/catch
0xzoz May 12, 2022
a261f6f
Merge branch 'add-tally-wallet' of https://github.com/0xzoz/hdwallet …
0xzoz May 12, 2022
904bde5
Make function private
0xzoz May 12, 2022
067ac70
Add commenting
0xzoz May 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/hdwallet-tally/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@shapeshiftoss/hdwallet-tally",
"version": "1.0.0",
0xzoz marked this conversation as resolved.
Show resolved Hide resolved
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "dist/index.js",
"source": "src/index.ts",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc --build",
"clean": "rm -rf dist tsconfig.tsbuildinfo",
"prepublishOnly": "yarn clean && yarn build"
},
"dependencies": {
"@metamask/detect-provider": "^1.2.0",
0xzoz marked this conversation as resolved.
Show resolved Hide resolved
"tallyho-onboarding": "^1.0.2",
mrnerdhair marked this conversation as resolved.
Show resolved Hide resolved
"@shapeshiftoss/hdwallet-core": "1.19.0",
"lodash": "^4.17.21"
0xzoz marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@types/lodash": "^4.14.168",
"typescript": "^4.3.2"
}
}
46 changes: 46 additions & 0 deletions packages/hdwallet-tally/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import { TallyHDWallet } from "./tally";
import TallyOnboarding from "tallyho-onboarding";
import detectEthereumProvider from "@metamask/detect-provider";

export class TallyAdapter {
keyring: core.Keyring;

// wallet id to remove from the keyring when the active wallet changes
currentDeviceID?: string;

0xzoz marked this conversation as resolved.
Show resolved Hide resolved
private constructor(keyring: core.Keyring) {
this.keyring = keyring;
}

public static useKeyring(keyring: core.Keyring) {
return new TallyAdapter(keyring);
}

public async initialize(): Promise<number> {
return Object.keys(this.keyring.wallets).length;
}
0xzoz marked this conversation as resolved.
Show resolved Hide resolved
0xzoz marked this conversation as resolved.
Show resolved Hide resolved

public async pairDevice(): Promise<TallyHDWallet> {
const provider: any = await detectEthereumProvider({ mustBeMetaMask: false, silent: false, timeout: 3000 });
if (!provider) {
const onboarding = new TallyOnboarding();
onboarding.startOnboarding();
console.error("Please install Tally!");
}
try {
await provider.request({ method: "eth_requestAccounts" });
} catch (error) {
console.error("Could not get Tally accounts. ");
throw error;
}
const wallet = new TallyHDWallet();
await wallet.initialize();
0xzoz marked this conversation as resolved.
Show resolved Hide resolved
const deviceID = await wallet.getDeviceID();
this.keyring.add(wallet, deviceID);
this.currentDeviceID = deviceID;
0xzoz marked this conversation as resolved.
Show resolved Hide resolved
this.keyring.emit(["Tally", deviceID, core.Events.CONNECT], deviceID);

return wallet;
}
}
129 changes: 129 additions & 0 deletions packages/hdwallet-tally/src/ethereum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import { ETHSignedMessage } from "@shapeshiftoss/hdwallet-core";
0xzoz marked this conversation as resolved.
Show resolved Hide resolved

export function describeETHPath(path: core.BIP32Path): core.PathDescription {
let pathStr = core.addressNListToBIP32(path);
let unknown: core.PathDescription = {
verbose: pathStr,
coin: "Ethereum",
isKnown: false,
};

if (path.length !== 5) return unknown;

if (path[0] !== 0x80000000 + 44) return unknown;

if (path[1] !== 0x80000000 + core.slip44ByCoin("Ethereum")) return unknown;

if ((path[2] & 0x80000000) >>> 0 !== 0x80000000) return unknown;

if (path[3] !== 0) return unknown;

if (path[4] !== 0) return unknown;

let index = path[2] & 0x7fffffff;
return {
verbose: `Ethereum Account #${index}`,
accountIdx: index,
wholeAccount: true,
coin: "Ethereum",
isKnown: true,
};
}

export async function ethVerifyMessage(msg: core.ETHVerifyMessage, ethereum: any): Promise<boolean | null> {
console.error("Method ethVerifyMessage unsupported for MetaMask wallet!");
0xdef1cafe marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

export function ethGetAccountPaths(msg: core.ETHGetAccountPath): Array<core.ETHAccountPath> {
const slip44 = core.slip44ByCoin(msg.coin);
if (slip44 === undefined) return [];
return [
{
addressNList: [0x80000000 + 44, 0x80000000 + slip44, 0x80000000 + msg.accountIdx, 0, 0],
hardenedPath: [0x80000000 + 44, 0x80000000 + slip44, 0x80000000 + msg.accountIdx],
relPath: [0, 0],
description: "MetaMask",
0xdef1cafe marked this conversation as resolved.
Show resolved Hide resolved
},
];
}

export async function ethSignTx(msg: core.ETHSignTx, ethereum: any, from: string): Promise<core.ETHSignedTx | null> {
console.error("Method ethSignTx unsupported for MetaMask wallet!");
0xdef1cafe marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

export async function ethSendTx(msg: core.ETHSignTx, ethereum: any, from: string): Promise<core.ETHTxHash | null> {
try {
const utxBase = {
from: from,
to: msg.to,
value: msg.value,
data: msg.data,
chainId: msg.chainId,
nonce: msg.nonce,
// MetaMask, like other Web3 libraries, derives its transaction schema from Ethereum's official JSON-RPC API specification
0xdef1cafe marked this conversation as resolved.
Show resolved Hide resolved
// (https://github.com/ethereum/execution-apis/blob/d63d2a02bcd2a8cef54ae2fc5bbff8b4fac944eb/src/schemas/transaction.json).
// That schema defines the use of the label `gas` to set the transaction's gas limit and not `gasLimit` as used in other
// libraries and as stated in the official yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf).
gas: msg.gasLimit,
};

const utx = msg.maxFeePerGas
0xzoz marked this conversation as resolved.
Show resolved Hide resolved
? {
...utxBase,
maxFeePerGas: msg.maxFeePerGas,
maxPriorityFeePerGas: msg.maxPriorityFeePerGas,
}
: { ...utxBase, gasPrice: msg.gasPrice };

const signedTx = await ethereum.request({
method: "eth_sendTransaction",
params: [utx],
});

return {
hash: signedTx,
} as core.ETHTxHash;
} catch (error) {
console.error(error);
return null;
}
}

export async function ethSignMessage(
msg: core.ETHSignMessage,
ethereum: any,
address: string
): Promise<core.ETHSignedMessage | null> {
try {
const signedMsg = await ethereum.request({
method: "personal_sign",
params: [Buffer.from(msg.message).toString("hex"), address],
});

return {
address: address,
signature: signedMsg,
} as ETHSignedMessage;
0xzoz marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
console.error(error);
return null;
}
}

export async function ethGetAddress(ethereum: any): Promise<string | null> {
if (!(ethereum && ethereum.request)) {
return null;
}
try {
const ethAccounts = await ethereum.request({
method: "eth_accounts",
});
return ethAccounts[0];
} catch (error) {
console.error(error);
return null;
}
}
2 changes: 2 additions & 0 deletions packages/hdwallet-tally/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./adapter";
export * from "./tally";
Loading