Skip to content

Commit

Permalink
add helpers to browser and server
Browse files Browse the repository at this point in the history
  • Loading branch information
moe-dev committed Nov 26, 2024
1 parent 8f74aeb commit d8068bc
Show file tree
Hide file tree
Showing 3 changed files with 530 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { Turnkey, TurnkeyApiTypes } from "@turnkey/sdk-server";
import { refineNonNull } from "@/utils";
import { TWalletDetails } from "@/types";

Expand All @@ -9,7 +8,11 @@ import { TWalletDetails } from "@/types";
// - Purpose is a constant set to 44' following the BIP43 recommendation.
// - Coin type is set to 60 (ETH) -- see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
// - Account, Change, and Address Index are set to 0
import { DEFAULT_ETHEREUM_ACCOUNTS } from "@turnkey/sdk-server";
import {
Turnkey,
TurnkeyApiTypes,
DEFAULT_ETHEREUM_ACCOUNTS,
} from "@turnkey/sdk-server";

type TAttestation = TurnkeyApiTypes["v1Attestation"];

Expand Down
26 changes: 13 additions & 13 deletions packages/sdk-browser/src/turnkey-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ interface WalletAccount {
pathFormat: "PATH_FORMAT_BIP32";
path: string;
addressFormat:
| "ADDRESS_FORMAT_ETHEREUM"
| "ADDRESS_FORMAT_UNCOMPRESSED"
| "ADDRESS_FORMAT_COMPRESSED"
| "ADDRESS_FORMAT_ETHEREUM"
| "ADDRESS_FORMAT_SOLANA"
| "ADDRESS_FORMAT_COSMOS"
| "ADDRESS_FORMAT_TRON"
Expand Down Expand Up @@ -43,36 +43,36 @@ interface WalletAccount {
// CURVE_SECP256K1 Accounts
// ----------------------------

// Cosmos
export const defaultCosmosAccountAtIndex = (
// Ethereum
export const defaultEthereumAccountAtIndex = (
pathIndex: number
): WalletAccount => {
return {
curve: "CURVE_SECP256K1",
pathFormat: "PATH_FORMAT_BIP32",
path: `m/44'/118'/${pathIndex}'/0/0`,
addressFormat: "ADDRESS_FORMAT_COSMOS",
path: `m/44'/60'/${pathIndex}'/0/0`,
addressFormat: "ADDRESS_FORMAT_ETHEREUM",
};
};

export const DEFAULT_COSMOS_ACCOUNTS: WalletAccount[] = [
defaultCosmosAccountAtIndex(0),
export const DEFAULT_ETHEREUM_ACCOUNTS: WalletAccount[] = [
defaultEthereumAccountAtIndex(0),
];

// Ethereum
export const defaultEthereumAccountAtIndex = (
// Cosmos
export const defaultCosmosAccountAtIndex = (
pathIndex: number
): WalletAccount => {
return {
curve: "CURVE_SECP256K1",
pathFormat: "PATH_FORMAT_BIP32",
path: `m/44'/60'/${pathIndex}'/0/0`,
addressFormat: "ADDRESS_FORMAT_ETHEREUM",
path: `m/44'/118'/${pathIndex}'/0/0`,
addressFormat: "ADDRESS_FORMAT_COSMOS",
};
};

export const DEFAULT_ETHEREUM_ACCOUNTS: WalletAccount[] = [
defaultEthereumAccountAtIndex(0),
export const DEFAULT_COSMOS_ACCOUNTS: WalletAccount[] = [
defaultCosmosAccountAtIndex(0),
];

// Tron
Expand Down
Loading

0 comments on commit d8068bc

Please sign in to comment.