-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove duplicated code by using our generic ledger js package to hand…
…le error response function and improve FVK type definition fix subarray offset
- Loading branch information
Showing
4 changed files
with
51 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
import { ADDRLEN, FVKLEN } from "./consts"; | ||
import { ResponseAddress, ResponseFvk } from "./types"; | ||
import { ResponsePayload } from '@zondax/ledger-js/dist/payload' | ||
|
||
export function processGetAddrResponse(response: Buffer): ResponseAddress { | ||
const errorCodeData = response.subarray(-2); | ||
const returnCode = errorCodeData[0] * 256 + errorCodeData[1]; | ||
import { ADDRLEN, AK_LEN, FVKLEN, NK_LEN } from './consts' | ||
import { ResponseAddress, ResponseFvk } from './types' | ||
|
||
const address = Buffer.from(response.subarray(0, ADDRLEN)); | ||
response = response.subarray(ADDRLEN); | ||
export function processGetAddrResponse(response: ResponsePayload): ResponseAddress { | ||
const address = response.readBytes(ADDRLEN) | ||
|
||
return { | ||
address, | ||
}; | ||
} | ||
} | ||
|
||
export function processGetFvkResponse(response: Buffer): ResponseFvk { | ||
const errorCodeData = response.subarray(-2); | ||
const returnCode = errorCodeData[0] * 256 + errorCodeData[1]; | ||
export function processGetFvkResponse(response: ResponsePayload): ResponseFvk { | ||
const keys = response.readBytes(FVKLEN) | ||
|
||
const fvk = Buffer.from(response.subarray(0, FVKLEN)); | ||
response = response.subarray(FVKLEN); | ||
// Extract ak and nullifier_key | ||
const ak = Buffer.from(keys.subarray(0, AK_LEN)) | ||
const nk = Buffer.from(keys.subarray(32, FVKLEN)) | ||
|
||
return { | ||
fvk, | ||
}; | ||
ak, | ||
nk, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
import { INSGeneric } from "@zondax/ledger-js"; | ||
import { INSGeneric } from '@zondax/ledger-js' | ||
|
||
export interface PenumbraIns extends INSGeneric { | ||
GET_VERSION: 0x00; | ||
GET_ADDR: 0x01; | ||
SIGN: 0x02; | ||
FVK: 0x03; | ||
GET_VERSION: 0x00 | ||
GET_ADDR: 0x01 | ||
SIGN: 0x02 | ||
FVK: 0x03 | ||
} | ||
|
||
export interface AddressIndex { | ||
account: number; | ||
randomizer?: Buffer; | ||
account: number | ||
randomizer?: Buffer | ||
} | ||
|
||
export interface ResponseAddress { | ||
address?: Buffer; | ||
address?: Buffer | ||
} | ||
|
||
// The full viewing key consists of two components: | ||
// | ||
// - ak | ||
// - nk | ||
// | ||
export interface ResponseFvk { | ||
fvk?: Buffer; | ||
ak: Buffer | ||
nk: Buffer | ||
} | ||
|
||
export interface ResponseSign { | ||
signature: Buffer; | ||
signature: Buffer | ||
} |