{"_id":"@0xflick/crypto-utils","name":"@0xflick/crypto-utils","dist-tags":{"latest":"1.10.3-0xflick.0"},"versions":{"1.10.3-0xflick.0":{"name":"@0xflick/crypto-utils","description":"Simple library for using secp256k1 cryptography.","author":{"name":"Christopher Scott"},"license":"CC-BY-1.0","keywords":["crypto","utils","library"],"version":"1.10.3-0xflick.0","type":"module","main":"./dist/main.cjs","unpkg":"./dist/bundle.min.js","types":"./dist/types/index.d.ts","exports":{"import":"./dist/module.mjs","require":"./dist/main.cjs","types":"./dist/types/index.d.ts"},"repository":{"type":"git","url":"https://github.com/cmdruid/crypto-utils.git"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"scripts":{"build":"rollup -c rollup.config.ts --configPlugin typescript","clean":"rm -rf dist/* coverage .nyc_output","scratch":"node --loader ts-node/esm --no-warnings test/scratch.ts","lint":"eslint . --ext .ts","fix":"eslint --fix . --ext .ts","tape":"node --loader ts-node/esm --no-warnings test/index.test.js","test":"nyc --reporter=lcov --require ts-node/register yarn tape | tap-spec; nyc report ---reporter=text","types":"tsc","release":"yarn clean && yarn test && yarn types && yarn lint && yarn build"},"devDependencies":{"@cmdcode/buff-utils":"^1.7.6","@noble/curves":"^0.9.1","@noble/hashes":"^1.3.0","@rollup/plugin-commonjs":"^23.0.2","@rollup/plugin-node-resolve":"^15.0.1","@rollup/plugin-terser":"^0.4.0","@rollup/plugin-typescript":"^9.0.2","@types/node":"^18.13.0","@types/tape":"^4.13.2","@typescript-eslint/eslint-plugin":"^5.48.0","@typescript-eslint/parser":"^5.52.0","eslint":"^8.31.0","eslint-config-standard-with-typescript":"^26.0.0","eslint-plugin-import":"^2.26.0","eslint-plugin-n":"^15.6.0","eslint-plugin-promise":"^6.1.1","nyc":"^15.1.0","rollup":"^3.2.3","tap-spec":"^5.0.0","tape":"^5.6.1","tiny-secp256k1":"^2.2.1","ts-node":"^10.9.1","typescript":"^4.9.4"},"licenseText":"Creative Commons Legal Code\n\nCC0 1.0 Universal\n\n    CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE\n    LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN\n    ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS\n    INFORMATION ON AN \"AS-IS\" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES\n    REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS\n    PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM\n    THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED\n    HEREUNDER.\n\nStatement of Purpose\n\nThe laws of most jurisdictions throughout the world automatically confer\nexclusive Copyright and Related Rights (defined below) upon the creator\nand subsequent owner(s) (each and all, an \"owner\") of an original work of\nauthorship and/or a database (each, a \"Work\").\n\nCertain owners wish to permanently relinquish those rights to a Work for\nthe purpose of contributing to a commons of creative, cultural and\nscientific works (\"Commons\") that the public can reliably and without fear\nof later claims of infringement build upon, modify, incorporate in other\nworks, reuse and redistribute as freely as possible in any form whatsoever\nand for any purposes, including without limitation commercial purposes.\nThese owners may contribute to the Commons to promote the ideal of a free\nculture and the further production of creative, cultural and scientific\nworks, or to gain reputation or greater distribution for their Work in\npart through the use and efforts of others.\n\nFor these and/or other purposes and motivations, and without any\nexpectation of additional consideration or compensation, the person\nassociating CC0 with a Work (the \"Affirmer\"), to the extent that he or she\nis an owner of Copyright and Related Rights in the Work, voluntarily\nelects to apply CC0 to the Work and publicly distribute the Work under its\nterms, with knowledge of his or her Copyright and Related Rights in the\nWork and the meaning and intended legal effect of CC0 on those rights.\n\n1. Copyright and Related Rights. A Work made available under CC0 may be\nprotected by copyright and related or neighboring rights (\"Copyright and\nRelated Rights\"). Copyright and Related Rights include, but are not\nlimited to, the following:\n\n  i. the right to reproduce, adapt, distribute, perform, display,\n     communicate, and translate a Work;\n ii. moral rights retained by the original author(s) and/or performer(s);\niii. publicity and privacy rights pertaining to a person's image or\n     likeness depicted in a Work;\n iv. rights protecting against unfair competition in regards to a Work,\n     subject to the limitations in paragraph 4(a), below;\n  v. rights protecting the extraction, dissemination, use and reuse of data\n     in a Work;\n vi. database rights (such as those arising under Directive 96/9/EC of the\n     European Parliament and of the Council of 11 March 1996 on the legal\n     protection of databases, and under any national implementation\n     thereof, including any amended or successor version of such\n     directive); and\nvii. other similar, equivalent or corresponding rights throughout the\n     world based on applicable law or treaty, and any national\n     implementations thereof.\n\n2. Waiver. To the greatest extent permitted by, but not in contravention\nof, applicable law, Affirmer hereby overtly, fully, permanently,\nirrevocably and unconditionally waives, abandons, and surrenders all of\nAffirmer's Copyright and Related Rights and associated claims and causes\nof action, whether now known or unknown (including existing as well as\nfuture claims and causes of action), in the Work (i) in all territories\nworldwide, (ii) for the maximum duration provided by applicable law or\ntreaty (including future time extensions), (iii) in any current or future\nmedium and for any number of copies, and (iv) for any purpose whatsoever,\nincluding without limitation commercial, advertising or promotional\npurposes (the \"Waiver\"). Affirmer makes the Waiver for the benefit of each\nmember of the public at large and to the detriment of Affirmer's heirs and\nsuccessors, fully intending that such Waiver shall not be subject to\nrevocation, rescission, cancellation, termination, or any other legal or\nequitable action to disrupt the quiet enjoyment of the Work by the public\nas contemplated by Affirmer's express Statement of Purpose.\n\n3. Public License Fallback. Should any part of the Waiver for any reason\nbe judged legally invalid or ineffective under applicable law, then the\nWaiver shall be preserved to the maximum extent permitted taking into\naccount Affirmer's express Statement of Purpose. In addition, to the\nextent the Waiver is so judged Affirmer hereby grants to each affected\nperson a royalty-free, non transferable, non sublicensable, non exclusive,\nirrevocable and unconditional license to exercise Affirmer's Copyright and\nRelated Rights in the Work (i) in all territories worldwide, (ii) for the\nmaximum duration provided by applicable law or treaty (including future\ntime extensions), (iii) in any current or future medium and for any number\nof copies, and (iv) for any purpose whatsoever, including without\nlimitation commercial, advertising or promotional purposes (the\n\"License\"). The License shall be deemed effective as of the date CC0 was\napplied by Affirmer to the Work. Should any part of the License for any\nreason be judged legally invalid or ineffective under applicable law, such\npartial invalidity or ineffectiveness shall not invalidate the remainder\nof the License, and in such case Affirmer hereby affirms that he or she\nwill not (i) exercise any of his or her remaining Copyright and Related\nRights in the Work or (ii) assert any associated claims and causes of\naction with respect to the Work, in either case contrary to Affirmer's\nexpress Statement of Purpose.\n\n4. Limitations and Disclaimers.\n\n a. No trademark or patent rights held by Affirmer are waived, abandoned,\n    surrendered, licensed or otherwise affected by this document.\n b. Affirmer offers the Work as-is and makes no representations or\n    warranties of any kind concerning the Work, express, implied,\n    statutory or otherwise, including without limitation warranties of\n    title, merchantability, fitness for a particular purpose, non\n    infringement, or the absence of latent or other defects, accuracy, or\n    the present or absence of errors, whether or not discoverable, all to\n    the greatest extent permissible under applicable law.\n c. Affirmer disclaims responsibility for clearing rights of other persons\n    that may apply to the Work or any use thereof, including without\n    limitation any person's Copyright and Related Rights in the Work.\n    Further, Affirmer disclaims responsibility for obtaining any necessary\n    consents, permissions or other rights required for any use of the\n    Work.\n d. Affirmer understands and acknowledges that Creative Commons is not a\n    party to this document and has no duty or obligation with respect to\n    this CC0 or use of the Work.\n","_id":"@0xflick/crypto-utils@1.10.3-0xflick.0","dist":{"shasum":"98de09045b379a8b4ee553decbd1bd2bed0547dd","integrity":"sha512-mqKWTxRvsyPCJ+aq1CUxrWBVbNfNwTdu/ygkjU+etqYrC2I7rs8EGDMANBvr4SsH4p/ENLT/z59gNq9jbk8rgg==","tarball":"https://registry.npmjs.org/@0xflick/crypto-utils/-/crypto-utils-1.10.3-0xflick.0.tgz","fileCount":37,"unpackedSize":1786477,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIESotJs9cCoXG4Ofy72MLnsz6XQ7rZNqwf8iJB5rqvcqAiEA2b6XnIaAb+KCvNX350tPO3nE32u98WWFqz3a8wQwChQ="}]},"_npmUser":{"name":"0xflick","email":"cmdrnft@protonmail.com"},"directories":{},"maintainers":[{"name":"0xflick","email":"cmdrnft@protonmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/crypto-utils_1.10.3-0xflick.0_1688610613007_0.6342004016742384"},"_hasShrinkwrap":false}},"time":{"created":"2023-07-06T02:30:12.901Z","1.10.3-0xflick.0":"2023-07-06T02:30:13.257Z","modified":"2023-07-06T02:30:13.558Z"},"maintainers":[{"name":"0xflick","email":"cmdrnft@protonmail.com"}],"description":"Simple library for using secp256k1 cryptography.","keywords":["crypto","utils","library"],"repository":{"type":"git","url":"https://github.com/cmdruid/crypto-utils.git"},"author":{"name":"Christopher Scott"},"license":"CC-BY-1.0","readme":"# Crypto Utils\n\nWraps the @noble/curves/secp256k1 library and provides a simpler API.\n\nEverything is fully-typed and straight-forward to use. More documentation coming soon!  \n\n## How to Use\n\n### Import\n\nExample import into a browser-based project:\n```html\n<script src=\"https://unpkg.com/@cmdcode/crypto-utils\"></script>\n<script> const { Field, Point, SecretKey, PublicKey } = window.cryptoUtils </script>\n```\nExample import into a commonjs project:\n```ts\nconst { Field, Point, SecretKey, PublicKey } = require('@cmdcode/crypto-utils')\n```\nExample import into an ES module project:\n```ts\nimport { Field, Point, SecretKey, PublicKey } from '@cmdcode/crypto-utils'\n```\n\n### Field / Point\n\n```ts\n// Fields can be created from a variety of types (strings are treated as hex).\ntype FieldValue = string | number | bigint | Uint8Array | Field\n// Points can be created from a variety of types (strings are treated as hex).\ntype PointValue = string | number | bigint | Uint8Array | Point\n\nclass Field extends Uint8Array {\n  // Prime N reference.\n  static N: bigint;\n  // Helper method for efficient modulo operations.\n  static mod(x: bigint, n?: bigint): bigint;\n  // Helper method for efficient power operations.\n  static pow(x: bigint, e: bigint, n?: bigint): bigint;\n  // Normalize input values into bytes.\n  static normalize(num: FieldValue): Uint8Array;\n  // Validate input values (or throw).\n  static validate(num: bigint): boolean;\n\n  // Accepts a variety of inputs.\n  constructor(x : FieldValue);\n\n  // Convert into a variety of formats.\n  get buff()    : Buff;\n  get raw()     : Uint8Array;\n  get big()     : bigint;\n  get hex()     : string;\n\n  // Return point (or x-only point) object.\n  get point()   : Point;\n  get xpoint()  : Point;\n\n  // Helper attributes.\n  get hasOddY() : boolean;\n  get negated() : Field;\n\n  // All basic operations are available.\n  gt(big: FieldValue)  : boolean;\n  lt(big: FieldValue)  : boolean;\n  eq(big: FieldValue)  : boolean;\n  ne(big: FieldValue)  : boolean;\n  add(big: FieldValue) : Field;\n  sub(big: FieldValue) : Field;\n  mul(big: FieldValue) : Field;\n  pow(big: FieldValue) : Field;\n  div(big: FieldValue) : Field;\n  negate()   : Field;\n  generate() : Point;\n}\n\nclass Point {\n  // Prime N reference.\n  static N: bigint;\n\n  // Validate input values (or throw).\n  static validate(x: PointValue): boolean;\n\n  // Normalize input values into bytes.\n  static normalize(x: PointValue): ECPoint;\n  \n  // Generate a point from a field (scalar) value.\n  static generate(value: FieldValue): Point;\n\n  // Helper method for importing coordinates.\n  static import(point: Point | ECPoint): Point;\n\n  // Accepts a varity of x-only and compressed key inputs.\n  // Will also accept coordinate data (as bigint). \n  constructor(x: PointValue, y?: bigint);\n\n  // Convert into a variety of formats.\n  get p()    : ECPoint;\n  get x()    : Buff;\n  get y()    : Buff;\n  get buff() : Buff;       // Returns compressed key.\n  get raw()  : Uint8Array; // Returns compressed key.\n  get hex()  : string;     // Returns compressed key.\n\n  // Helper attributes.\n  get hasEvenY(): boolean;\n  get hasOddY(): boolean;\n\n  // Basic math operations available.\n  eq(value: PointValue): boolean;\n  add(x: PointValue): Point;\n  sub(x: PointValue): Point;\n  mul(value: PointValue): Point;\n  negate(): Point;\n}\n```\n\n### SecretKey / PublicKey\n\n```ts\nclass SecretKey extends Uint8Array {\n  static random(opt?: KeyOptions): SecretKey;\n\n  constructor(secret: Bytes, options?: KeyOptions);\n\n  get buff(): Buff;\n  get raw(): Uint8Array;\n  get hex(): string;\n\n  get field(): Field;\n  get point(): Point;\n\n  get pub(): PublicKey;\n\n  get hasEvenY(): boolean;\n  get hasOddY(): boolean;\n  get xfilter(): SecretKey;\n\n  add(bytes: Bytes): SecretKey;\n  sub(bytes: Bytes): SecretKey;\n  mul(bytes: Bytes): SecretKey;\n  div(bytes: Bytes): SecretKey;\n  pow(bytes: Bytes): SecretKey;\n  negate(): SecretKey;\n\n  sign(message: Bytes, type?: SignatureType): Uint8Array\n  verify(signature: Bytes, message: Bytes, type?: SignatureType): boolean\n\n  toWIF(prefix?: number): string;\n}\n\nclass PublicKey extends Uint8Array {\n  static random(opt: KeyOptions): PublicKey;\n  static fromSecret(bytes: Bytes, opt: KeyOptions): PublicKey;\n\n  constructor(pubkey: Bytes, options?: KeyOptions);\n\n  get buff(): Buff;\n  get raw(): Uint8Array;\n  get hex(): string;\n\n  get point(): Point;\n  get x(): Buff;\n  get y(): Buff;\n\n  get hasEvenY(): boolean;\n  get hasOddY(): boolean;\n\n  add(bytes: Bytes): PublicKey;\n  sub(bytes: Bytes): PublicKey;\n  mul(bytes: Bytes): PublicKey;\n  negate(): PublicKey;\n\n  verify(signature: Bytes, message: Bytes, type?: SignatureType): boolean\n}\n```\n\n## Hash Methods\n\nYou can also import the following hash methods:\n\n```ts\nimport {\n  sha256,\n  sha512,\n  ripe160,\n  hash160,\n  hash256,\n  hmac256,\n  hmac512\n} from '@cmdcode/crypto-utils'\n```\n\n## Development / Testing\n\nThis library uses yarn for package management, tape for writing tests, and rollup for cross-platform releases. Here are a few scripts that are useful for development.\n\n```bash\n## Compiles types and builds release candidates in /dist folder.\nyarn build\n## Run any typescript file using real-time compilation.\nyarn start contrib/example.ts\n## Runs all tests listed in test folder. \nyarn test\n## Full macro script for generating a new release candidate.\nyarn release\n```\n\n## Bugs / Issues\n\nIf you run into any bugs or have any questions, please submit an issue ticket.\n\n## Contribution\n\nFeel free to fork and make contributions. Suggestions are welcome!\n\n## License\n\nUse this library however you want!\n","readmeFilename":"README.md"}