-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add types for the keychain api (#92)
- Loading branch information
1 parent
5151293
commit 701fbeb
Showing
9 changed files
with
108 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import KeyIdentifier from '@exodus/key-identifier' | ||
import BN from 'bn.js' | ||
|
||
type SeedId = string | ||
type KeySource = { seedId: SeedId; keyId: KeyIdentifier } | ||
|
||
type EcOptions = { | ||
canonical?: boolean | ||
} | ||
|
||
type EcSignature = { | ||
r: BN | ||
s: BN | ||
recoveryParam?: number | ||
} | ||
|
||
type PublicKeys = { | ||
publicKey: Buffer | ||
xpub: string | ||
} | ||
|
||
type PrivateKeys = { | ||
privateKey: Buffer | ||
xpriv: string | ||
} | ||
|
||
export interface KeychainApi { | ||
exportKey(params: KeySource): Promise<PublicKeys> | ||
exportKey(params: { exportPrivate: false } & KeySource): Promise<PublicKeys> | ||
exportKey(params: { exportPrivate: true } & KeySource): Promise<PublicKeys & PrivateKeys> | ||
arePrivateKeysLocked(): Promise<boolean> | ||
sodium: { | ||
signDetached(params: { data: Buffer } & KeySource): Promise<Buffer> | ||
getKeysFromSeed( | ||
params: KeySource | ||
): Promise<{ box: { publicKey: Buffer }; sign: { publicKey: Buffer } }> | ||
} | ||
ed25519: { | ||
signBuffer(params: { data: Buffer } & KeySource): Promise<Buffer> | ||
} | ||
secp256k1: { | ||
signBuffer(params: { data: Buffer; ecOptions?: EcOptions } & KeySource): Promise<Buffer> | ||
signBuffer( | ||
params: { data: Buffer; ecOptions?: EcOptions; enc: 'der' } & KeySource | ||
): Promise<Buffer> | ||
signBuffer( | ||
params: { data: Buffer; ecOptions?: EcOptions; enc: 'raw' } & KeySource | ||
): Promise<EcSignature> | ||
} | ||
} | ||
|
||
declare const keychainApiDefinition: { | ||
id: 'keychainApi' | ||
type: 'api' | ||
factory(): { | ||
keychain: KeychainApi | ||
} | ||
} | ||
|
||
export default keychainApiDefinition |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import keychainApiDefinition from './api' | ||
|
||
declare const keychain: () => { | ||
id: 'keychain' | ||
definitions: [{ definition: typeof keychainApiDefinition }] | ||
} | ||
|
||
export default keychain |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["**/*.d.ts"], | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './key-identifier' |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
type ConstructorParams = { | ||
derivationAlgorithm: 'BIP32' | 'SLIP10' | ||
derivationPath: string | ||
assetName?: string | ||
keyType: 'legacy' | 'nacl' | 'secp2561' | ||
} | ||
|
||
type KeyIdentifierLike = Partial<ConstructorParams> | ||
|
||
export default class KeyIdentifier { | ||
derivationAlgorithm: ConstructorParams['derivationAlgorithm'] | ||
derivationPath: ConstructorParams['derivationPath'] | ||
assetName: ConstructorParams['assetName'] | ||
keyType: ConstructorParams['keyType'] | ||
|
||
constructor(params: ConstructorParams) | ||
|
||
static validate(potentialKeyIdentifier: KeyIdentifierLike): boolean | ||
static compare(a: KeyIdentifierLike, b: KeyIdentifierLike): boolean | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["**/*.d.ts"], | ||
} |
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