-
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.
* add address index * Throw if provided path is incorrect Comment requirement * Remove duplicated code by using our generic ledger js package to handle error response function and improve FVK type definition fix subarray offset --------- Co-authored-by: abenso <[email protected]>
- Loading branch information
Showing
4 changed files
with
111 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
export const APP_KEY = "PENUMBRA"; | ||
export const APP_KEY = 'PENUMBRA' | ||
export const DEFAULT_PATH = "m/44'/6532'/0'" | ||
|
||
export const P2_VALUES = { | ||
DEFAULT: 0x00, | ||
}; | ||
} | ||
|
||
export const PKLEN = 65; | ||
export const ADDRLEN = 80; | ||
export const FVKLEN = 64; | ||
export const SIGRSLEN = 64; | ||
export const PREHASH_LEN = 32; | ||
export const RANDOMIZER_LEN = 12; | ||
export const PKLEN = 65 | ||
export const ADDRLEN = 80 | ||
// Verification key length | ||
export const AK_LEN = 32 | ||
// Nullifier key length | ||
export const NK_LEN = 32 | ||
export const FVKLEN = AK_LEN + NK_LEN | ||
export const SIGRSLEN = 64 | ||
export const PREHASH_LEN = 32 | ||
export const RANDOMIZER_LEN = 12 |
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,23 +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 | ||
} | ||
|
||
export interface ResponseAddress { | ||
// publicKey?: Buffer; | ||
// principal?: Buffer; | ||
address?: Buffer; | ||
// principalText?: string; | ||
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 | ||
} |