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

New Release #10

Merged
merged 8 commits into from
Sep 21, 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
14 changes: 7 additions & 7 deletions README-npm.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Use `yarn install` to avoid issues.

# Available commands

| Operation | Response | Command |
|--------------|------------------------------------------|-------------------------------|
| getVersion | app version | --------------- |
| appInfo | name, version, flags, etc | --------------- |
| deviceInfo | fw and mcu version, id, etc | Only available in dashboard |
| sign | signed message | path + message |
| retrieveKeys | address or view key or proof gen key | path + key type + verify flag |
| Operation | Response | Command |
| ------------ | ------------------------------------ | ----------------------------- |
| getVersion | app version | --------------- |
| appInfo | name, version, flags, etc | --------------- |
| deviceInfo | fw and mcu version, id, etc | Only available in dashboard |
| sign | signed message | path + message |
| retrieveKeys | address or view key or proof gen key | path + key type + verify flag |

# Who we are?

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Use `yarn install` to avoid issues.

# Available commands

| Operation | Response | Command |
|--------------|------------------------------------------|-------------------------------|
| getVersion | app version | --------------- |
| appInfo | name, version, flags, etc | --------------- |
| deviceInfo | fw and mcu version, id, etc | Only available in dashboard |
| sign | signed message | path + message |
| retrieveKeys | address or view key or proof gen key | path + key type + verify flag |
| Operation | Response | Command |
| ------------ | ------------------------------------ | ----------------------------- |
| getVersion | app version | --------------- |
| appInfo | name, version, flags, etc | --------------- |
| deviceInfo | fw and mcu version, id, etc | Only available in dashboard |
| sign | signed message | path + message |
| retrieveKeys | address or view key or proof gen key | path + key type + verify flag |

# Who we are?

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/zondax/ledger-ironfish-js/issues"
},
"dependencies": {
"@zondax/ledger-js": "^0.2.1"
"@zondax/ledger-js": "^1.0.1"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
Expand Down
3 changes: 3 additions & 0 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ export const KEY_TYPES = {
PROOF_GEN_KEY: 0x02,
}

export const VERSION = 1
export const KEY_LENGTH = 32
export const REDJUBJUB_SIGNATURE_LEN = 64
export const ED25519_SIGNATURE_LEN = 64
export const IDENTITY_LEN = VERSION + KEY_LENGTH + KEY_LENGTH + ED25519_SIGNATURE_LEN
37 changes: 37 additions & 0 deletions src/deserialize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export const deserializeDkgRound1 = (data?: Buffer) => {
if (!data) throw new Error('unexpected empty data')

let pos = 0
const secretPackageLen = data.readUint16BE(pos)
pos += 2
const secretPackage = data.subarray(pos, pos + secretPackageLen)
pos += secretPackageLen
const publicPackageLen = data.readUint16BE(pos)
pos += 2
const publicPackage = data.subarray(pos, pos + publicPackageLen)
pos += publicPackageLen

return {
secretPackage,
publicPackage,
}
}

export const deserializeDkgRound2 = (data?: Buffer) => {
if (!data) throw new Error('unexpected empty data')

let pos = 0
const secretPackageLen = data.readUint16BE(pos)
pos += 2
const secretPackage = data.subarray(pos, pos + secretPackageLen)
pos += secretPackageLen
const publicPackageLen = data.readUint16BE(pos)
pos += 2
const publicPackage = data.subarray(pos, pos + publicPackageLen)
pos += publicPackageLen

return {
secretPackage,
publicPackage,
}
}
54 changes: 18 additions & 36 deletions src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,43 @@
import { errorCodeToString } from '@zondax/ledger-js'
import { ResponsePayload } from '@zondax/ledger-js/dist/payload'

import { KEY_LENGTH } from './consts'
import { IronfishKeys, KeyResponse } from './types'

export function processGetKeysResponse(response: Buffer, keyType: IronfishKeys): KeyResponse {
const errorCodeData = response.subarray(-2)
const returnCode = errorCodeData[0] * 256 + errorCodeData[1]

let requestedKey: KeyResponse = {
returnCode: returnCode,
errorMessage: errorCodeToString(returnCode),
}
import { ED25519_SIGNATURE_LEN, IDENTITY_LEN, KEY_LENGTH, REDJUBJUB_SIGNATURE_LEN, VERSION } from './consts'
import { IronfishKeys, KeyResponse, ResponseIdentity } from './types'

export function processGetKeysResponse(response: ResponsePayload, keyType: IronfishKeys): KeyResponse {
switch (keyType) {
case IronfishKeys.PublicAddress: {
const publicAddress = Buffer.from(response.subarray(0, KEY_LENGTH))
requestedKey = {
...requestedKey,
const publicAddress = response.readBytes(KEY_LENGTH)
return {
publicAddress,
}
break
}

case IronfishKeys.ViewKey: {
const viewKey = Buffer.from(response.subarray(0, 2 * KEY_LENGTH))
response = response.subarray(2 * KEY_LENGTH)

const ivk = Buffer.from(response.subarray(0, KEY_LENGTH))
response = response.subarray(KEY_LENGTH)
const viewKey = response.readBytes(2 * KEY_LENGTH)
const ivk = response.readBytes(KEY_LENGTH)
const ovk = response.readBytes(KEY_LENGTH)

const ovk = Buffer.from(response.subarray(0, KEY_LENGTH))
response = response.subarray(KEY_LENGTH)

requestedKey = {
...requestedKey,
return {
viewKey,
ivk,
ovk,
}
break
}

case IronfishKeys.ProofGenerationKey: {
const ak = Buffer.from(response.subarray(0, KEY_LENGTH))
response = response.subarray(KEY_LENGTH)

const nsk = Buffer.from(response.subarray(0, KEY_LENGTH))
response = response.subarray(KEY_LENGTH)
const ak = response.readBytes(KEY_LENGTH)
const nsk = response.readBytes(KEY_LENGTH)

requestedKey = {
...requestedKey,
return {
ak,
nsk,
}
break
}
}
}

export function processGetIdentityResponse(response: ResponsePayload): ResponseIdentity {
const identity = response.readBytes(IDENTITY_LEN)

return requestedKey
return { identity }
}
Loading