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

feat v4: Support Nervos OK-25210 OK-25885 OK-26082 #4230

Merged
merged 8 commits into from
Mar 19, 2024
Merged
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
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@
"@onekeyfe/cross-inpage-provider-injected": "1.1.55",
"@onekeyfe/cross-inpage-provider-types": "1.1.55",
"@onekeyfe/extension-bridge-hosted": "1.1.55",
"@onekeyfe/hd-ble-sdk": "0.3.39",
"@onekeyfe/hd-core": "0.3.39",
"@onekeyfe/hd-shared": "0.3.39",
"@onekeyfe/hd-transport": "0.3.39",
"@onekeyfe/hd-web-sdk": "0.3.39",
"@onekeyfe/hd-ble-sdk": "0.3.40-alpha.2",
"@onekeyfe/hd-core": "0.3.40-alpha.2",
"@onekeyfe/hd-shared": "0.3.40-alpha.2",
"@onekeyfe/hd-transport": "0.3.40-alpha.2",
"@onekeyfe/hd-web-sdk": "0.3.40-alpha.2",
"@onekeyfe/onekey-cross-webview": "1.1.55",
"@starcoin/starcoin": "2.1.5",
"@web3-react/core": "8.0.35-beta.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"rimraf": "^3"
},
"dependencies": {
"@ckb-lumos/ckb-indexer": "^0.21.1",
"@ckb-lumos/common-scripts": "^0.21.1",
"@ckb-lumos/helpers": "^0.21.1",
"@conflux-dev/conflux-address-js": "^1.3.13",
"@ethersproject/keccak256": "^5.6.0",
"@ethersproject/transactions": "^5.6.0",
Expand Down
11 changes: 11 additions & 0 deletions packages/engine/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,17 @@ export class MinimumTransferBalanceRequiredForSendingAssetError extends OneKeyEr
}
}

export class ChangeLessThanMinInputCapacityError extends OneKeyError {
override key = 'msg__the_balance_after_the_tx_must_not_be_less_than_str';

constructor(amount: string) {
super(`The change cannot be less than that ${amount}`, {
'0': amount,
});
this.key = 'msg__the_balance_after_the_tx_must_not_be_less_than_str';
}
}

// all networks ----------------------------------------------
export class AllNetworksMinAccountsError extends OneKeyError {
override key = 'msg__you_need_str_accounts_on_any_network_to_create';
Expand Down
8 changes: 8 additions & 0 deletions packages/engine/src/managers/derivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
COINTYPE_LIGHTNING_TESTNET,
COINTYPE_LTC,
COINTYPE_NEAR,
COINTYPE_NERVOS,
COINTYPE_NEURAI,
COINTYPE_NEXA,
COINTYPE_NOSTR,
COINTYPE_SOL,
Expand All @@ -39,6 +41,8 @@ import {
IMPL_KASPA,
IMPL_LTC,
IMPL_NEAR,
IMPL_NERVOS,
IMPL_NEURAI,
IMPL_NOSTR,
IMPL_SOL,
IMPL_STC,
Expand Down Expand Up @@ -84,6 +88,8 @@ const purposeMap: Record<string, Array<number>> = {
[IMPL_XMR]: [44],
[IMPL_KASPA]: [44],
[IMPL_NOSTR]: [44],
[IMPL_NERVOS]: [44],
[IMPL_NEURAI]: [44],
};

// derive path template by coin types.
Expand Down Expand Up @@ -117,6 +123,8 @@ const derivationPathTemplates: Record<string, string> = {
[COINTYPE_LIGHTNING]: `m/44'/${COINTYPE_LIGHTNING}'/${INCREMENT_LEVEL_TAG}`,
[COINTYPE_LIGHTNING_TESTNET]: `m/44'/${COINTYPE_LIGHTNING_TESTNET}'/${INCREMENT_LEVEL_TAG}`,
[COINTYPE_NOSTR]: `m/44'/${COINTYPE_NOSTR}'/${INCREMENT_LEVEL_TAG}'`,
[COINTYPE_NERVOS]: `m/44'/${COINTYPE_NERVOS}'/0'/0/${INCREMENT_LEVEL_TAG}`,
[COINTYPE_NEURAI]: `m/44'/${COINTYPE_NEURAI}'/${INCREMENT_LEVEL_TAG}'`,
};

function getDerivationPaths(
Expand Down
19 changes: 18 additions & 1 deletion packages/engine/src/managers/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
COINTYPE_LIGHTNING_TESTNET,
COINTYPE_LTC,
COINTYPE_NEAR,
COINTYPE_NERVOS,
COINTYPE_NEURAI,
COINTYPE_NEXA,
COINTYPE_NOSTR,
COINTYPE_SOL,
Expand All @@ -43,6 +45,8 @@ import {
IMPL_LIGHTNING_TESTNET,
IMPL_LTC,
IMPL_NEAR,
IMPL_NERVOS,
IMPL_NEURAI,
IMPL_NEXA,
IMPL_NOSTR,
IMPL_SOL,
Expand Down Expand Up @@ -93,6 +97,8 @@ const implToCoinTypes: Partial<Record<string, string | string[]>> = {
[IMPL_LIGHTNING]: COINTYPE_LIGHTNING,
[IMPL_LIGHTNING_TESTNET]: COINTYPE_LIGHTNING_TESTNET,
[IMPL_NOSTR]: COINTYPE_NOSTR,
[IMPL_NERVOS]: COINTYPE_NERVOS,
[IMPL_NEURAI]: COINTYPE_NEURAI,
};

const coinTypeToImpl: Record<string, string> = Object.fromEntries(
Expand Down Expand Up @@ -132,6 +138,8 @@ const implToAccountType: Record<string, AccountType> = {
[IMPL_LIGHTNING]: AccountType.VARIANT,
[IMPL_LIGHTNING_TESTNET]: AccountType.VARIANT,
[IMPL_NOSTR]: AccountType.VARIANT,
[IMPL_NERVOS]: AccountType.SIMPLE,
[IMPL_NEURAI]: AccountType.UTXO,
};

function isCoinTypeCompatibleWithImpl(coinType: string, impl: string): boolean {
Expand Down Expand Up @@ -166,6 +174,8 @@ const defaultCurveMap: Record<string, Curve> = {
[IMPL_LIGHTNING]: Curve.SECP256K1,
[IMPL_LIGHTNING_TESTNET]: Curve.SECP256K1,
[IMPL_NOSTR]: Curve.SECP256K1,
[IMPL_NERVOS]: Curve.SECP256K1,
[IMPL_NEURAI]: Curve.SECP256K1,
};

function getCurveByImpl(impl: string): string {
Expand Down Expand Up @@ -279,7 +289,14 @@ function migrateNextAccountIds(nextAccountIds: Record<string, number>) {
}

function isBtcLikeImpl(impl: string): boolean {
return [IMPL_BTC, IMPL_TBTC, IMPL_LTC, IMPL_BCH, IMPL_DOGE].includes(impl);
return [
IMPL_BTC,
IMPL_TBTC,
IMPL_LTC,
IMPL_BCH,
IMPL_DOGE,
IMPL_NEURAI,
].includes(impl);
}

export {
Expand Down
3 changes: 2 additions & 1 deletion packages/engine/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
IMPL_BTC,
IMPL_DOGE,
IMPL_LTC,
IMPL_NEURAI,
IMPL_TBTC,
SEPERATOR,
} from '@onekeyhq/shared/src/engine/engineConsts';
Expand Down Expand Up @@ -76,7 +77,7 @@ function fromDBNetworkToChainInfo(dbNetwork: DBNetwork): ChainInfo {

let code = dbNetwork.id;
if (
[IMPL_BTC, IMPL_DOGE, IMPL_LTC, IMPL_BCH, IMPL_TBTC].includes(
[IMPL_BTC, IMPL_DOGE, IMPL_LTC, IMPL_BCH, IMPL_TBTC, IMPL_NEURAI].includes(
dbNetwork.impl,
)
) {
Expand Down
8 changes: 8 additions & 0 deletions packages/engine/src/vaults/factory.createVaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
IMPL_LIGHTNING_TESTNET,
IMPL_LTC,
IMPL_NEAR,
IMPL_NERVOS,
IMPL_NEURAI,
IMPL_NEXA,
IMPL_NOSTR,
IMPL_SOL,
Expand Down Expand Up @@ -125,6 +127,12 @@ export function createVaultSettings(options: {
if (impl === IMPL_NOSTR) {
return require('./impl/nostr/settings').default as IVaultSettings;
}
if (impl === IMPL_NERVOS) {
return require('./impl/nervos/settings').default as IVaultSettings;
}
if (impl === IMPL_NEURAI) {
return require('./impl/neurai/settings').default as IVaultSettings;
}
throw new OneKeyInternalError(
`VaultSettings not found for: networkId=${options.networkId ?? ''}, impl=${
impl ?? ''
Expand Down
18 changes: 18 additions & 0 deletions packages/engine/src/vaults/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
IMPL_LIGHTNING_TESTNET,
IMPL_LTC,
IMPL_NEAR,
IMPL_NERVOS,
IMPL_NEURAI,
IMPL_NEXA,
IMPL_NOSTR,
IMPL_SOL,
Expand Down Expand Up @@ -53,6 +55,8 @@ import VaultHelperKaspa from './impl/kaspa/VaultHelper';
import VaultHelperLightning from './impl/lightning-network/VaultHelper';
import VaultHelperLtc from './impl/ltc/VaultHelper';
import VaultHelperNear from './impl/near/VaultHelper';
import VaultHelperNervos from './impl/nervos/VaultHelper';
import VaultHelperNeurai from './impl/neurai/VaultHelper';
import VaultHelperNexa from './impl/nexa/VaultHelper';
import VaultHelperNostr from './impl/nostr/VaultHelper';
import VauleHelperSol from './impl/sol/VaultHelper';
Expand Down Expand Up @@ -147,6 +151,12 @@ export async function createVaultHelperInstance(
if (impl === IMPL_NOSTR) {
return new VaultHelperNostr(options);
}
if (impl === IMPL_NERVOS) {
return new VaultHelperNervos(options);
}
if (impl === IMPL_NEURAI) {
return new VaultHelperNeurai(options);
}
throw new OneKeyInternalError(
`VaultHelper Class not found for: networkId=${options.networkId}, accountId=${options.accountId}`,
);
Expand Down Expand Up @@ -292,6 +302,14 @@ export async function createVaultInstance(options: IVaultOptions) {
const VaultNostr = (await import('./impl/nostr/Vault')).default;
vault = new VaultNostr(options);
}
if (network.impl === IMPL_NERVOS) {
const VaultNervos = (await import('./impl/nervos/Vault')).default;
vault = new VaultNervos(options);
}
if (network.impl === IMPL_NEURAI) {
const VaultNeurai = (await import('./impl/neurai/Vault')).default;
vault = new VaultNeurai(options);
}
if (!vault) {
throw new OneKeyInternalError(
`Vault Class not found for: networkId=${options.networkId}, accountId=${options.accountId}`,
Expand Down
Loading
Loading