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

Add typings to Hypersign #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Utility method for creating a random or hashed salt value.
If called with a string the string will be hashed, to a
generic hash of `size` length.

If called without any inputs, or with a number, random
butes of `size` length will be
If called without any inputs, or with a number, random
bytes of `size` length will be returned

#### `sign(value, options)`

Expand All @@ -43,7 +43,7 @@ Options:
#### `signable(value, options)`

Utility method which returns the exact buffer that would be signed in by `sign`. This is only needed when using a salt, otherwise it will return the same `value` passed in. This method is to facilitate out-of-band signing (e.g. hardware signing), do not pass the returned signable value into `sign`, it already uses `signable`.
If you need to sign a value that has already been passed
If you need to sign a value that has already been passed
through `signable`, use `cryptoSign`.

Options:
Expand All @@ -53,7 +53,7 @@ Options:

#### `cryptoSign(msg, keypair)`

Utility method which can be used to create a signature using the `crypto_sign_detached` Sodium method. This only needs to be used
Utility method which can be used to create a signature using the `crypto_sign_detached` Sodium method. This only needs to be used
when you *do not* need to apply encoding to `value`, `salt` and `seq`(e.g. if value and options have already been passed to `signable`).

Options:
Expand Down
29 changes: 29 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
declare function _exports(): Hypersign;
export default _exports;
export { Hypersign }
/** VALUE_MAX_SIZE + packet overhead (i.e. the key etc.) should be less than the network MTU, normally 1400 bytes */
export const VALUE_MAX_SIZE: number;

export declare interface KeyPair {
publicKey:Buffer
secretKey:Buffer
}

declare interface SignOptions {
keypair?: KeyPair
salt?:Buffer
seq?:number
}

declare class Hypersign {
/** Utility method for creating a random or hashed salt value. If called with a string the string will be hashed, to a generic hash of size length. If called without any inputs, or with a number, random býtes of size length will be returned */
salt(str?: string, size?: number): Buffer;
/** Use this method to generate an assymetric keypair. Returns an object with {publicKey, secretKey}. publicKey holds a public key buffer, secretKey holds a private key buffer. */
keypair(): KeyPair
/** Utility method which can be used to create a signature using the crypto_sign_detached Sodium method. This only needs to be used when you do not need to apply encoding to value, salt and seq(e.g. if value and options have already been passed to signable). */
cryptoSign(msg: Buffer, keypair: KeyPair ): Buffer;
/** Utility method which can be used to create a signature. */
sign(value: Buffer, opts: SignOptions): Buffer;
/** Utility method which returns the exact buffer that would be signed in by sign. This is only needed when using a salt, otherwise it will return the same value passed in. */
signable(value: Buffer, opts?: { salt?:Buffer, seq?:number }): Buffer;
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"version": "2.1.0",
"description": "Utility methods related to public key cryptography to be used with distributed mutable storage",
"main": "index.js",
"types":"index.d.ts",
"dependencies": {
"sodium-universal": "^2.0.0"
},
"devDependencies": {
"@types/node": "^13.11.0",
"bencode": "^2.0.1",
"standard": "^13.1.0",
"tap": "^14.5.0"
Expand Down