UNPKG

@ngraveio/ur-coin-identity

Version:

Provides BC UR type that uniquely identifies a crypto coin.

138 lines (137 loc) 5.43 kB
import { RegistryItemClass } from '@ngraveio/bc-ur'; /** * Elliptic curve types defined by the IANA registry * * https://www.iana.org/assignments/cose/cose.xhtml#elliptic-curves * https://www.rfc-editor.org/rfc/rfc9053.html#name-elliptic-curve-keys * * P256=1 ; NIST P-256 also known as secp256r1 * P384=2 ; NIST P-384 also known as secp384r1 * P521=3 ; EC2 NIST P-521 also known as secp521r1 * X25519=4 ; X25519 for use w/ ECDH only * X448=5 ; X448 for use w/ ECDH only * Ed25519=6 ; Ed25519 for use w/ EdDSA only * Ed448=7 ; Ed448 for use w/ EdDSA only * secp256k1=8 ; SECG secp256k1 curve IESG * */ export declare enum EllipticCurve { P256 = 1,// NIST P-256 also known as secp256r1 P384 = 2,// NIST P-384 also known as secp384r1 P521 = 3,// EC2 NIST P-521 also known as secp521r1 X25519 = 4,// X25519 for use w/ ECDH only X448 = 5,// X448 for use w/ ECDH only Ed25519 = 6,// Ed25519 for use w/ EdDSA only Ed448 = 7,// Ed448 for use w/ EdDSA only secp256k1 = 8 } export declare enum ComparisonMethod { ExactMatch = "==", Parent = ">", Child = "<", NotEqual = "!=", LessThanOrEqual = "<=", GreaterThanOrEqual = ">=" } type hex_string = Uint8Array | string; type sub_type_exp = number | string | hex_string; interface CoinIdentityData { curve: EllipticCurve; type: number; subtype?: sub_type_exp[]; } declare const CoinIdentityBase: RegistryItemClass; /** CDDL * * ; Table should always be updated according to IANA registry * ; https://www.iana.org/assignments/cose/cose.xhtml#elliptic-curves * ; https://www.rfc-editor.org/rfc/rfc9053.html#name-elliptic-curve-keys * * P256=1 ; NIST P-256 also known as secp256r1 * P384=2 ; NIST P-384 also known as secp384r1 * P521=3 ; EC2 NIST P-521 also known as secp521r1 * X25519=4 ; X25519 for use w/ ECDH only * X448=5 ; X448 for use w/ ECDH only * Ed25519=6 ; Ed25519 for use w/ EdDSA only * Ed448=7 ; Ed448 for use w/ EdDSA only * secp256k1=8 ; SECG secp256k1 curve IESG * * elliptic_curve = P256 / P384 / P521 / X25519 / X448 / Ed25519 / Ed448 / secp256k1 * * ; Subtypes specific to some coins (e.g. ChainId for EVM chains) * hex_string = #6.263(bstr) ; byte string is a hexadecimal string no need for decoding * sub_type_exp = uint32 / str / hex_string * * coin-identity = { * curve: elliptic_curve, * type: uint31, ; values from [SLIP44] with high bit turned off, * ? subtype: [ sub_type_exp + ] ; Compatible with the definition of several subtypes if necessary * } * * curve = 1 * type = 2 * subtype = 3 */ export declare class CoinIdentity extends CoinIdentityBase { data: CoinIdentityData; constructor(curve: EllipticCurve, type: number, subtype?: sub_type_exp[]); /** * Static method to create an instance from CBOR data. * It processes the raw CBOR data if needed and returns a new instance of the class. */ static fromCBORData(val: any, tagged?: any): CoinIdentity; getCurve: () => EllipticCurve; getType: () => number; getSubType: () => sub_type_exp[]; /** * Get the parent CoinIdentity of the current CoinIdentity * @returns {CoinIdentity} a new instance of CoinIdentity for the parent if it exists or null if it does not. */ getParent: () => CoinIdentity | null; /** * Create an Iterator that returns all the parents of this CoinIdentity * @returns {Iterable<CoinIdentity>} An iterator for all the parent CoinIdentities of the current CoinIdentity */ getAllParents(): Iterable<CoinIdentity>; /** * Create a url from ths CoinIdentity. The subtypes should be in the correct order. * @returns {string} url representation of the CoinIdentity */ toURL: () => string; /** * Convert a url into a CoinIdentity * @param url url representation of a CoinIdentity * @returns {CoinIdentity} created from the passed url. */ static fromUrl: (url: string) => CoinIdentity; /** * Compare the current id to a given id * @param coinIdentity CoinIdentity to compare the current one with * @param comparison comparison method to check * @returns boolean indicating if the comparison is valid */ compare: (coinIdentity: CoinIdentity, comparison: ComparisonMethod) => boolean; /** * Compare a coin url, generated with '.toUrl()' method, with a different one * @param coinUrl1 first coinIdentity as a url. * @param coinUrl2 second coinIdentity as a url. * @param comparison comparison method. * @returns boolean indicating if the comparison is valid */ static compareCoinIds(coinUrl1: string, coinUrl2: string, comparison: ComparisonMethod): boolean; /** * Creates a dictionary for all comparison methods for two given coin urls, generated with '.toUrl()'. * @param coinUrl1 first coinIdentity as a url. * @param coinUrl2 second coinIdentity as a url. * @returns dictionary indicating which comparison methods are true | false. */ static compareCoinIdsDict(coinUrl1: string, coinUrl2: string): { "==": boolean; "<": boolean; ">": boolean; "!=": boolean; "<=": boolean; ">=": boolean; }; } export {};