diff --git a/.gitignore b/.gitignore index 31b50576..ef773b4c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ yarn.lock .esm-cache .sessionStorage .localStorage -/types/*.ts -!/types/*.d.ts +/types/**/*.ts +!/types/**/*.d.ts /gun.ts /temp/ diff --git a/types/static.d.ts b/types/static.d.ts index 82e8832b..939647fe 100644 --- a/types/static.d.ts +++ b/types/static.d.ts @@ -1,5 +1,7 @@ import { IGunChainReference } from './chain'; import { IGunConstructorOptions } from './options'; +import { IGunStaticNode } from './static/node'; +import { IGunStaticSEA } from './static/sea'; export interface IGunStatic { /** * @description @@ -11,72 +13,9 @@ export interface IGunStatic { */ (options?: string | string[] | IGunConstructorOptions): IGunChainReference; new (options?: string | string[] | IGunConstructorOptions): IGunChainReference; - node: { - /** Returns true if data is a gun node, otherwise false. */ - is(anything: any): anything is IGunChainReference; - /** - * Returns data's gun ID (instead of manually grabbing its metadata i.e. data["_"]["#"], which is faster but could change in the future) - * - * Returns undefined if data is not correct gun data. - */ - soul(data: IGunChainReference): string; - /** Returns a "gun-ified" variant of the json input by injecting a new gun ID into the metadata field. */ - ify(json: any): any; - }; + node: IGunStaticNode; /** @see https://gun.eco/docs/SEA */ - SEA: { - /** If you want SEA to throw while in development, turn SEA.throw = true on, but please do not use this in production. */ - throw?: boolean; - /** Last known error */ - err?: Error; - /** - * This gives you a Proof of Work (POW) / Hashing of Data - * @param data The data to be hashed, work to be performed on. - * @param pair (salt) You can pass pair of keys to use as salt. Salt will prevent others to pre-compute the work, - * so using your public key is not a good idea. If it is not specified, it will be random, - * which ruins your chance of ever being able to re-derive the work deterministically - * @param callback function to executed upon execution of proof - * @param opt default: {name: 'PBKDF2', encode: 'base64'} - */ - work(data: any, pair?: any, callback?: (data: string | undefined) => void, opt?: Partial<{ - name: 'SHA-256' | 'PBKDF2'; - encode: 'base64' | 'base32' | 'base16'; - /** iterations to use on subtle.deriveBits */ - iterations: number; - salt: any; - hash: string; - length: any; - }>): Promise; - /** - * This generates a cryptographically secure public/private key pair - be careful not to leak the private keys! - * Note: API subject to change we may change the parameters to accept data and work, in addition to generation. - * You will need this for most of SEA's API, see those method's examples. - * The default cryptographic primitives for the asymmetric keys are ECDSA for signing and ECDH for encryption. - */ - pair(cb: (data: CryptoKeyPair) => void, opt?: {}): Promise; - /** - * Adds a signature to a message, for data that you want to prevent attackers tampering with. - * @param data is the content that you want to prove is authorized. - * @param pair is from .pair. - */ - sign(data: any, pair: CryptoKeyPair): Promise; - /** - * Gets the data if and only if the message can be verified as coming from the person you expect. - * @param message is what comes from .sign. - * @param pair from .pair or its public key text (pair.pub). - */ - verify(message: any, pair: CryptoKeyPair | string): Promise; - /** - * Takes some data that you want to keep secret and encrypts it so nobody else can read it. - * @param data is the content that you want to encrypt. - * @param pair from .pair or a passphrase you want to use as a cypher to encrypt with. - */ - encrypt(data: any, pair: CryptoKeyPair | string): Promise; - /** - * Read the secret data, if and only if you are allowed to. - * @param message is what comes from .encrypt. - * @param pair from .pair or the passphrase to decypher the message. - */ - decrypt(message: any, pair: CryptoKeyPair | string): Promise; - }; + SEA: IGunStaticSEA; + version: string; + readonly chain: IGunChainReference; } diff --git a/types/static/node.d.ts b/types/static/node.d.ts new file mode 100644 index 00000000..17c3696f --- /dev/null +++ b/types/static/node.d.ts @@ -0,0 +1,13 @@ +import { IGunChainReference } from '../chain'; +export interface IGunStaticNode { + /** Returns true if data is a gun node, otherwise false. */ + is(anything: any): anything is IGunChainReference; + /** + * Returns data's gun ID (instead of manually grabbing its metadata i.e. data["_"]["#"], which is faster but could change in the future) + * + * Returns undefined if data is not correct gun data. + */ + soul(data: IGunChainReference): string; + /** Returns a "gun-ified" variant of the json input by injecting a new gun ID into the metadata field. */ + ify(json: any): any; +} diff --git a/types/static/sea.d.ts b/types/static/sea.d.ts new file mode 100644 index 00000000..bd183021 --- /dev/null +++ b/types/static/sea.d.ts @@ -0,0 +1,56 @@ +/** @see https://gun.eco/docs/SEA */ +export interface IGunStaticSEA { + /** If you want SEA to throw while in development, turn SEA.throw = true on, but please do not use this in production. */ + throw?: boolean; + /** Last known error */ + err?: Error; + /** + * This gives you a Proof of Work (POW) / Hashing of Data + * @param data The data to be hashed, work to be performed on. + * @param pair (salt) You can pass pair of keys to use as salt. Salt will prevent others to pre-compute the work, + * so using your public key is not a good idea. If it is not specified, it will be random, + * which ruins your chance of ever being able to re-derive the work deterministically + * @param callback function to executed upon execution of proof + * @param opt default: {name: 'PBKDF2', encode: 'base64'} + */ + work(data: any, pair?: any, callback?: (data: string | undefined) => void, opt?: Partial<{ + name: 'SHA-256' | 'PBKDF2'; + encode: 'base64' | 'base32' | 'base16'; + /** iterations to use on subtle.deriveBits */ + iterations: number; + salt: any; + hash: string; + length: any; + }>): Promise; + /** + * This generates a cryptographically secure public/private key pair - be careful not to leak the private keys! + * Note: API subject to change we may change the parameters to accept data and work, in addition to generation. + * You will need this for most of SEA's API, see those method's examples. + * The default cryptographic primitives for the asymmetric keys are ECDSA for signing and ECDH for encryption. + */ + pair(cb: (data: CryptoKeyPair) => void, opt?: {}): Promise; + /** + * Adds a signature to a message, for data that you want to prevent attackers tampering with. + * @param data is the content that you want to prove is authorized. + * @param pair is from .pair. + */ + sign(data: any, pair: CryptoKeyPair): Promise; + /** + * Gets the data if and only if the message can be verified as coming from the person you expect. + * @param message is what comes from .sign. + * @param pair from .pair or its public key text (pair.pub). + */ + verify(message: any, pair: CryptoKeyPair | string): Promise; + /** + * Takes some data that you want to keep secret and encrypts it so nobody else can read it. + * @param data is the content that you want to encrypt. + * @param pair from .pair or a passphrase you want to use as a cypher to encrypt with. + */ + encrypt(data: any, pair: CryptoKeyPair | string): Promise; + /** + * Read the secret data, if and only if you are allowed to. + * @param message is what comes from .encrypt. + * @param pair from .pair or the passphrase to decypher the message. + */ + decrypt(message: any, pair: CryptoKeyPair | string): Promise; +}