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

Ts/add neox type #72

Merged
merged 4 commits into from
Jul 31, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [4.13.1](https://github.com/nash-io/nash-protocol/compare/v4.12.1...v4.13.1) (2024-07-31)

### [4.12.1](https://github.com/nash-io/nash-protocol/compare/v4.11.21...v4.12.1) (2024-07-08)

### [4.11.21](https://github.com/nash-io/nash-protocol/compare/v4.11.19...v4.11.21) (2024-05-22)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neon-exchange/nash-protocol",
"version": "4.12.1",
"version": "4.13.1",
"description": "TypeScript implementation of Nash crypto routines",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/signatureVectors.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@
"timestamp": 1565362799120,
"signature": "30440220083a73aaaa2b69476c74b64e0f1a1bdc1f6e5d311472729712eba8b5f3343a0a02204dcd5a5aac2693865b140c041cf85d6bd079c9a4803fe83caa218bb09d13d2c2",
"raw": {
"polygon": "03FA39FDDDE46CEA3060B91F80ABED8672F77C5BEA000300000000121278900052E62CFA39FDDDE46CEA3060B91F80ABED8672F77C5BEA"
"polygon": "03FA39FDDDE46CEA3060B91F80ABED8672F77C5BEAFFFF00000000121278900052E62CFA39FDDDE46CEA3060B91F80ABED8672F77C5BEA"
},
"blockchainSignatures": {
"polygon": "e0b4e31781887a3639f24a0dee44356118f9ccc65158e7e06ef90581c7833be620ac6c6ff8906d3d0f87563c442944140b0da5ffb60d2cbfc8017a58d969bfc401"
"polygon": "1353f7e60784ef9a2b0826cd5c42bc8e09e6eaf74a22265f21464067642a2044f26c3de33d237f0be1e89a2b83a4fa0503f795826784de79d25521bdde9cd0cf00"
}
}
},
Expand Down
7 changes: 7 additions & 0 deletions src/generateWallet/generateWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export enum CoinType {
ERD = 508,
NEO = 888,
NEO3 = 888,
NEO_X = 888,
POLYGON = 966,
AVAXC = 9000,
ABRITRUM = 9001
Expand Down Expand Up @@ -108,6 +109,8 @@ export const coinTypeFromString = (s: string): CoinType => {
ltc: CoinType.LTC,
neo: CoinType.NEO,
neo3: CoinType.NEO3,
neo_x: CoinType.NEO_X,
neox: CoinType.NEO_X,
polygon: CoinType.POLYGON
}

Expand All @@ -132,6 +135,9 @@ export const blockchainFromString = (name: string): Blockchain => {
return Blockchain.POLYGON
case 'neo3':
return Blockchain.NEO3
case 'neox':
case 'neo_x':
return Blockchain.NEO_X
case 'arbitrum':
return Blockchain.ARBITRUM
default:
Expand Down Expand Up @@ -220,6 +226,7 @@ function generateWalletForCoinType(
case CoinType.AVAXC:
case CoinType.POLYGON:
case CoinType.ABRITRUM:
case CoinType.NEO_X:
// TODO: can we replace this with the elliptic package which we already
// use to trim bundle size?
const pubkey = tiny.pointFromScalar(key.privateKey, false)
Expand Down
21 changes: 21 additions & 0 deletions src/mpc/generateAPIKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,22 @@ export async function generateAPIKeys(params: GenerateApiKeysParams): Promise<AP
Blockchain.ARBITRUM
)

const neoXWallet = generateWallet(
masterSeed,
coinTypeFromString('neo_x'),
params.walletIndices.neoX,
params.net,
Blockchain.NEO_X
)

const btcSecret = btcWallet.privateKey
const ethSecret = ethWallet.privateKey
const neoSecret = neoWallet.privateKey
const avaxcSecret = avaxcWallet.privateKey
const polygonSecret = polygonWallet.privateKey
const neo3Secret = neo3Wallet.privateKey
const arbitrumSecret = arbitrumWallet.privateKey
const neoXSecret = neoXWallet.privateKey

const btc = await createAPIKey({
...params,
Expand Down Expand Up @@ -105,6 +114,12 @@ export async function generateAPIKeys(params: GenerateApiKeysParams): Promise<AP
secret: arbitrumSecret
})

const neoX = await createAPIKey({
...params,
curve: 'Secp256k1',
secret: neoXSecret
})

return {
child_keys: {
[BIP44.BTC]: {
Expand Down Expand Up @@ -143,6 +158,12 @@ export async function generateAPIKeys(params: GenerateApiKeysParams): Promise<AP
public_key: neo3Wallet.publicKey,
server_secret_share_encrypted: neo3.server_secret_share_encrypted
},
[BIP44.NEO_X]: {
address: neoXWallet.address,
client_secret_share: neoX.client_secret_share,
public_key: neoXWallet.publicKey,
server_secret_share_encrypted: neoX.server_secret_share_encrypted
},
[BIP44.ARBITRUM]: {
address: arbitrumWallet.address,
client_secret_share: arbitrum.client_secret_share,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test('sign derc20 withdraw movement', async () => {
expect(payloadRes.blockchainMovement).toEqual({
address: 'fa39fddde46cea3060b91f80abed8672f77c5bea',
amount: '303200400',
asset: '0003',
asset: 'ffff',
nonce: '0052e62c',
prefix: '03',
userPubKey: 'fa39fddde46cea3060b91f80abed8672f77c5bea',
Expand Down Expand Up @@ -118,7 +118,7 @@ test('sign MATIC/DERC20 market buy order', async () => {
orderData
)
expect(rawData).toBe(
'019BAE2051097DC5DDF68D3C01D5FA5CCC7833109D000300000000001700000005FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF00000000000000000000002A'
'019BAE2051097DC5DDF68D3C01D5FA5CCC7833109DFFFF00000000001700000005FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF00000000000000000000002A'
)
})

Expand All @@ -145,7 +145,7 @@ test('sign USDC/WBTC market buy order', async () => {
)

expect(rawData).toBe(
'019BAE2051097DC5DDF68D3C01D5FA5CCC7833109D000300000000001700000005FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF00000000000000000000002A'
'019BAE2051097DC5DDF68D3C01D5FA5CCC7833109DFFFF000100000001FFFFFFFFFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF00000000000000000000002A'
)
// console.log("Raw data: ", rawData)

Expand Down
4 changes: 4 additions & 0 deletions src/types/MPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export enum Blockchain {
ETH = 'ETH',
NEO = 'NEO',
NEO3 = 'NEO3',
NEO_X = 'NEO_X',
AVAXC = 'AVAXC',
POLYGON = 'POLYGON',
ARBITRUM = 'ARBITRUM'
Expand All @@ -18,6 +19,7 @@ export const BlockchainCurve: Record<Blockchain, Curve> = {
[Blockchain.BTC]: 'Secp256k1',
[Blockchain.ETH]: 'Secp256k1',
[Blockchain.NEO]: 'Secp256r1',
[Blockchain.NEO_X]: 'Secp256k1',
[Blockchain.AVAXC]: 'Secp256k1',
[Blockchain.POLYGON]: 'Secp256k1',
[Blockchain.NEO3]: 'Secp256r1',
Expand Down Expand Up @@ -90,6 +92,7 @@ export enum BIP44 {
ETH = "m/44'/60'/0'/0/0",
NEO = "m/44'/888'/0'/0/0",
NEO3 = "m/44'/888'/1'/0/0",
NEO_X = "m/44'/888'/2'/0/0",
POLYGON = "m/44'/966'/0'/0/0",
AVAXC = "m/44'/9000'/0'/0/0",
ARBITRUM = "m/44'/9001'/0'/0/0"
Expand All @@ -116,6 +119,7 @@ export interface APIKey {
[BIP44.AVAXC]?: ChildKey
[BIP44.POLYGON]?: ChildKey
[BIP44.NEO3]?: ChildKey
[BIP44.NEO_X]?: ChildKey
[BIP44.ARBITRUM]?: ChildKey
}
payload_signing_key: string
Expand Down
Loading