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 stacks blockchain #3919

Draft
wants to merge 9 commits into
base: onekey
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ START_LINE=`head -n1 $INPUT_FILE`

PATTERN="^(OK)-[[:digit:]]+"

if ! [[ "$START_LINE" =~ $PATTERN|^feat\:|^fix\:|^docs\:|^style\:|^refactor\:|^perf\:|^test\:|^chore\: ]]; then
if ![[ "$START_LINE" =~ $PATTERN|^feat\:|^fix\:|^docs\:|^style\:|^refactor\:|^perf\:|^test\:|^chore\: ]]; then
echo "
Bad commit message, you must add a jira issue key here. https://onekeyhq.atlassian.net/jira/your-work
See example:
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
"@onekeyfe/hd-transport": "0.3.48",
"@onekeyfe/hd-web-sdk": "0.3.48",
"@onekeyfe/onekey-cross-webview": "1.1.60",
"@stacks/blockchain-api-client": "^7.9.0",
"@stacks/network": "^6.11.3",
"@stacks/transactions": "^6.12.1",
"@starcoin/starcoin": "2.1.5",
"@web3-react/core": "8.0.35-beta.0",
"@web3-react/empty": "8.0.20-beta.0",
Expand Down
1 change: 1 addition & 0 deletions packages/blockchain-libs/src/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ const IMPLS: { [key: string]: any } = {
tron: mockProvider,
kaspa: mockProvider,
nexa: mockProvider,
stacks: mockProvider,
lightning: mockProvider,
tlightning: mockProvider,
};
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/Icon/Icons.ext-bg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const icons = {
SecretNetworkIllus: () => null,
SolanaIllus: () => null,
StarBadgeIllus: () => null,
Stacks: () => null,
StarcoinIllus: () => null,
SuiIllus: () => null,
TerraIllus: () => null,
Expand Down
11 changes: 11 additions & 0 deletions packages/components/src/Icon/react/illus/Stacks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Svg, { SvgProps, Path, Circle } from 'react-native-svg';
const SvgStacks = (props: SvgProps) => (
<Svg viewBox="0 0 16 16" fill="none" accessibilityRole="image" {...props}>
<Circle cx="79.9" cy="79.9" r="79.9" fill="#5546FF" />
<Path
d="M112.5,122L95.3,95H120V84.8H39v10.2h24.7L46.5,122h12.8l20.2-31.7L99.7,122H112.5z M120,74.9V64.7H95.8 l17-26.7H99.9L79.5,70.2L59.1,38H46.2l17,26.7H39V75L120,74.9L120,74.9z"
fill="#FFFFFF"
/>
</Svg>
);
export default SvgStacks;
1 change: 1 addition & 0 deletions packages/engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ class Engine {
'128': OnekeyNetwork.xmr,
'111111': OnekeyNetwork.kaspa,
'29223': OnekeyNetwork.nexa,
'5757': OnekeyNetwork.stacks,
'1900': OnekeyNetwork.xna,
'29538': OnekeyNetwork.dnx,
}[coinType];
Expand Down
2 changes: 2 additions & 0 deletions packages/engine/src/managers/derivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {

import type { DBAccountDerivation } from '../types/accountDerivation';
import type { Wallet } from '../types/wallet';
import { COINTYPE_STACKS } from '../../../shared/src/engine/engineConsts';

const purposeMap: Record<string, Array<number>> = {
[IMPL_EVM]: [44],
Expand Down Expand Up @@ -113,6 +114,7 @@ const derivationPathTemplates: Record<string, string> = {
[COINTYPE_LTC]: `m/${PURPOSE_TAG}'/${COINTYPE_LTC}'/${INCREMENT_LEVEL_TAG}'`,
[COINTYPE_BCH]: `m/44'/${COINTYPE_BCH}'/${INCREMENT_LEVEL_TAG}'`,
[COINTYPE_NEXA]: `m/44'/${COINTYPE_NEXA}'/${INCREMENT_LEVEL_TAG}'`,
[COINTYPE_STACKS]: `m/44'/${COINTYPE_STACKS}'/0'/0/${INCREMENT_LEVEL_TAG}`,
[COINTYPE_XRP]: `m/44'/${COINTYPE_XRP}'/${INCREMENT_LEVEL_TAG}'/0/0`,
[COINTYPE_COSMOS]: `m/44'/${COINTYPE_COSMOS}'/0'/0/${INCREMENT_LEVEL_TAG}`,
[COINTYPE_ADA]: `m/1852'/${COINTYPE_ADA}'/${INCREMENT_LEVEL_TAG}'`,
Expand Down
5 changes: 5 additions & 0 deletions packages/engine/src/managers/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
IMPL_NEXA,
IMPL_NOSTR,
IMPL_SOL,
IMPL_STACKS,
IMPL_STC,
IMPL_SUI,
IMPL_TBTC,
Expand All @@ -67,6 +68,7 @@ import { createVaultSettings } from '../vaults/factory.createVaultSettings';

import type { DBAccount } from '../types/account';
import type { AccountNameInfo } from '../types/network';
import { COINTYPE_STACKS } from '../../../shared/src/engine/engineConsts';

enum Curve {
SECP256K1 = 'secp256k1',
Expand Down Expand Up @@ -96,6 +98,7 @@ const implToCoinTypes: Partial<Record<string, string | string[]>> = {
[IMPL_XMR]: COINTYPE_XMR,
[IMPL_KASPA]: COINTYPE_KASPA,
[IMPL_NEXA]: COINTYPE_NEXA,
[IMPL_STACKS]: COINTYPE_STACKS,
[IMPL_LIGHTNING]: COINTYPE_LIGHTNING,
[IMPL_LIGHTNING_TESTNET]: COINTYPE_LIGHTNING_TESTNET,
[IMPL_NOSTR]: COINTYPE_NOSTR,
Expand Down Expand Up @@ -138,6 +141,7 @@ const implToAccountType: Record<string, AccountType> = {
[IMPL_DOT]: AccountType.VARIANT,
[IMPL_XMR]: AccountType.VARIANT,
[IMPL_KASPA]: AccountType.SIMPLE,
[IMPL_STACKS]: AccountType.SIMPLE,
[IMPL_LIGHTNING]: AccountType.VARIANT,
[IMPL_LIGHTNING_TESTNET]: AccountType.VARIANT,
[IMPL_NOSTR]: AccountType.VARIANT,
Expand Down Expand Up @@ -175,6 +179,7 @@ const defaultCurveMap: Record<string, Curve> = {
[IMPL_DOT]: Curve.ED25519,
[IMPL_XMR]: Curve.ED25519,
[IMPL_KASPA]: Curve.SECP256K1,
[IMPL_STACKS]: Curve.SECP256K1,
[IMPL_LIGHTNING]: Curve.SECP256K1,
[IMPL_LIGHTNING_TESTNET]: Curve.SECP256K1,
[IMPL_NOSTR]: Curve.SECP256K1,
Expand Down
4 changes: 4 additions & 0 deletions packages/engine/src/vaults/factory.createVaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
IMPL_NEXA,
IMPL_NOSTR,
IMPL_SOL,
IMPL_STACKS,
IMPL_STC,
IMPL_SUI,
IMPL_TBTC,
Expand Down Expand Up @@ -114,6 +115,9 @@ export function createVaultSettings(options: {
if (impl === IMPL_NEXA) {
return require('./impl/nexa/settings').default as IVaultSettings;
}
if (impl === IMPL_STACKS) {
return require('./impl/stacks/settings').default as IVaultSettings;
}
if (impl === IMPL_LIGHTNING) {
return require('./impl/lightning-network/settings')
.default as IVaultSettings;
Expand Down
9 changes: 9 additions & 0 deletions packages/engine/src/vaults/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
IMPL_NEXA,
IMPL_NOSTR,
IMPL_SOL,
IMPL_STACKS,
IMPL_STC,
IMPL_SUI,
IMPL_TBTC,
Expand Down Expand Up @@ -62,6 +63,7 @@ import VaultHelperNeurai from './impl/neurai/VaultHelper';
import VaultHelperNexa from './impl/nexa/VaultHelper';
import VaultHelperNostr from './impl/nostr/VaultHelper';
import VauleHelperSol from './impl/sol/VaultHelper';
import VaultHelperStacks from './impl/stacks/VaultHelper';
import VaultHelperStc from './impl/stc/VaultHelper';
import VaultHelperSui from './impl/sui/VaultHelper';
import VaultHelperTbtc from './impl/tbtc/VaultHelper';
Expand Down Expand Up @@ -144,6 +146,9 @@ export async function createVaultHelperInstance(
if (impl === IMPL_NEXA) {
return new VaultHelperNexa(options);
}
if (impl === IMPL_STACKS) {
return new VaultHelperStacks(options);
}
if (impl === IMPL_LIGHTNING || impl === IMPL_LIGHTNING_TESTNET) {
return new VaultHelperLightning(options);
}
Expand Down Expand Up @@ -291,6 +296,10 @@ export async function createVaultInstance(options: IVaultOptions) {
const VaultNexa = (await import('./impl/nexa/Vault')).default;
vault = new VaultNexa(options);
}
if (network.impl === IMPL_STACKS) {
const VaultStacks = (await import('./impl/stacks/Vault')).default;
vault = new VaultStacks(options);
}
if (
network.impl === IMPL_LIGHTNING ||
network.impl === IMPL_LIGHTNING_TESTNET
Expand Down
149 changes: 149 additions & 0 deletions packages/engine/src/vaults/impl/stacks/@tests/stacksMockData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import mockCredentials from '../../../../../@tests/mockCredentials';
import { AccountType } from '../../../../types/account';

import type { IUnitTestMockAccount } from '../../../../../@tests/types';
import type { DBNetwork } from '../../../../types/network';

// indexedDB -> networks
const network: DBNetwork = {
balance2FeeDecimals: 0,
decimals: 6,
enabled: true,
feeDecimals: 6,
feeSymbol: 'STX',
id: 'stacks--testnet',
impl: 'stacks',
logoURI: 'https://assets.stacks.co/Logos/Stacks%20Logo%20png.png',
name: 'Stacks Testnet',
position: 33,
rpcURL: 'wss://api.testnet.hiro.so',
symbol: 'STX',
};

const hdAccount1: IUnitTestMockAccount = {
// indexedDB -> accounts
account: {
'name': 'Stacks #1',
'address':
'02e3027885ce1ed1d21300158ce8f60649e280e2a8f746e9cea6858a3331021d8a',
'addresses': {
'nexa--testnet':
'02e3027885ce1ed1d21300158ce8f60649e280e2a8f746e9cea6858a3331021d8a',
},
'xpub': '',
'coinType': '5757',
'id': "hd-19--m/44'/5757'/0'",
'path': "m/44'/5757'/0'/0/0",
'template': "m/44'/5757'/0'/0/$$INDEX$$",
'type': AccountType.UTXO,
},
mnemonic: mockCredentials.mnemonic1,
password: mockCredentials.password,
};

const importedAccount1: IUnitTestMockAccount = {
// indexedDB -> accounts
account: {
'address':
'03560d4451deeef0d1bcc46ff062372400ecf7b6e4e058ef01792f140ce2a97c31',
'addresses': {
'stacks--testnet':
'03560d4451deeef0d1bcc46ff062372400ecf7b6e4e058ef01792f140ce2a97c31',
},
'coinType': '5757',
'id': 'imported--5757--03560d4451deeef0d1bcc46ff062372400ecf7b6e4e058ef01792f140ce2a97c31',
name: 'Account #1',
path: '',
xpub: '',
type: AccountType.SIMPLE,
},
// indexedDB -> credentials
privateKey:
'6b4d9dee8a37f4329cbf7db9a137a2ecdc63be8e6caa881ef05b3a3349ef8db9',
password: mockCredentials.password,
};

const importedAccount2: IUnitTestMockAccount = {
account: {
'address':
'03560d4451deeef0d1bcc46ff062372400ecf7b6e4e058ef01792f140ce2a97c31',
'addresses': {
'stacks--testnet':
'03560d4451deeef0d1bcc46ff062372400ecf7b6e4e058ef01792f140ce2a97c31',
},
'coinType': '5757',
'id': 'imported--5757--03560d4451deeef0d1bcc46ff062372400ecf7b6e4e058ef01792f140ce2a97c31',
name: 'Account #1',
path: '',
xpub: '',
type: AccountType.SIMPLE,
},
// indexedDB -> credentials
privateKey:
'b848990d04878c4bbdcb671f45ed02807bcb4b200bfab2d636cb088e921b483fb01e7b872377c5b6dd582f0ca5d16ae5e4565163607df61ec5b5c96cbde8f4bb892865e079c0c4d64f29e5ba8b6a8d80317c1c7a97cf476a7459d24aa80d2a0f',
password: '12345678',
};

const watchingAccount1: IUnitTestMockAccount = {
account: {
address: 'stackstest:nqtsq5g5s9cd8fsl9d9a7jhsuzsw7u9exztnnz8n9un89t0k',
'coinType': '5757',
'id': 'external--5757--stackstest:nqtsq5g5s9cd8fsl9d9a7jhsuzsw7u9exztnnz8n9un89t0k',
name: 'Account #1',
path: '',
pub: '',
type: AccountType.SIMPLE,
},
password: '',
};

const watchingAccount2: IUnitTestMockAccount = {
account: {
address: 'stackstest:fmza0ttf3pnv5zpg8e2q8lr3t2cesrrv9xdk395r5g5qsqtn',
coinType: '5757',
id: 'external--397--ed25519:8wbWQQkeK9NV1qkiQZ95jbj7JNhpeapHafLPw3qsJdqi',
name: 'Account #1',
path: '',
pub: '',
type: AccountType.SIMPLE,
},
password: '',
};

const watchingAccount3: IUnitTestMockAccount = {
account: {
address:
'03560d4451deeef0d1bcc46ff062372400ecf7b6e4e058ef01792f140ce2a97c31',
coinType: '5757',
id: 'external--5757--03560d4451deeef0d1bcc46ff062372400ecf7b6e4e058ef01792f140ce2a97c31',
name: 'Account #1',
path: '',
pub: '',
type: AccountType.SIMPLE,
},
password: '',
};

const watchingAccount4: IUnitTestMockAccount = {
account: {
address: 'stacks:nqtsq5g50frur0vav60gupjlrr8cta8vyqufu7p98vx97c66',
coinType: '5757',
id: 'external--5757--03560d4451deeef0d1bcc46ff062372400ecf7b6e4e058ef01792f140ce2a97c31',
name: 'Account #1',
path: '',
pub: '',
type: AccountType.SIMPLE,
},
password: '',
};

export default {
network,
hdAccount1,
importedAccount1,
importedAccount2,
watchingAccount1,
watchingAccount2,
watchingAccount3,
watchingAccount4,
};
Loading