Skip to content

Commit

Permalink
feat: bump ledger-js package and implement it
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelm41 committed Sep 18, 2024
1 parent 1dd2062 commit a9857ea
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 487 deletions.
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
4 changes: 2 additions & 2 deletions src/deserialize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const deserializeDkgRound1 = (data?: Buffer) => {
if (!data) return {}
if (!data) throw new Error('unexpected empty data')

let pos = 0
const secretPackageLen = data.readUint16BE(pos)
Expand All @@ -18,7 +18,7 @@ export const deserializeDkgRound1 = (data?: Buffer) => {
}

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

let pos = 0
const secretPackageLen = data.readUint16BE(pos)
Expand Down
65 changes: 14 additions & 51 deletions src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,43 @@
import { errorCodeToString } from '@zondax/ledger-js'
import { ResponsePayload } from '@zondax/ledger-js/dist/payload'

import { ED25519_SIGNATURE_LEN, IDENTITY_LEN, KEY_LENGTH, REDJUBJUB_SIGNATURE_LEN, VERSION } from './consts'
import { IronfishKeys, KeyResponse, ResponseIdentity } 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),
}

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 viewKey = response.readBytes(2 * KEY_LENGTH)
const ivk = response.readBytes(KEY_LENGTH)
const ovk = response.readBytes(KEY_LENGTH)

const ivk = Buffer.from(response.subarray(0, KEY_LENGTH))
response = response.subarray(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
}
}

return requestedKey
}

export function processGetIdentityResponse(response: Buffer): ResponseIdentity {
const errorCodeData = response.subarray(-2)
const returnCode = errorCodeData[0] * 256 + errorCodeData[1]

let getIdentityResponse: ResponseIdentity = {
returnCode: returnCode,
errorMessage: errorCodeToString(returnCode),
}

const identity = Buffer.from(response.subarray(0, IDENTITY_LEN))

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

return getIdentityResponse
return { identity }
}
Loading

0 comments on commit a9857ea

Please sign in to comment.