{"_id":"@confluxfans/cip-23","_rev":"1-4e98ab7b7cf19e1388292121f45aaeb2","name":"@confluxfans/cip-23","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@confluxfans/cip-23","version":"0.1.0","description":"Tiny library with utility functions that can help with signing and verifying CIP-23 based messages","author":{"name":"Pana"},"repository":{"type":"git","url":"git+https://github.com/conflux-fans/cip-23.git"},"bugs":{"url":"https://github.com/conflux-fans/cip-23/issues"},"keywords":["conflux","cip23"],"license":"MIT","main":"lib/cjs/index.js","module":"lib/es/index.js","typings":"typings/index.d.ts","sideEffects":false,"engines":{"node":">=10"},"scripts":{"clean":"rimraf lib","build":"yarn run clean && yarn run build:source && yarn run build:declarations","build:source":"yarn run build:source:cjs && yarn run build:source:es","build:source:cjs":"cross-env NODE_ENV=production BABEL_ENV=cjs babel src --extensions '.ts' --source-maps --out-dir lib/cjs","build:source:es":"cross-env NODE_ENV=production BABEL_ENV=es babel src --extensions '.ts' --source-maps --out-dir lib/es","build:declarations":"tsc -p tsconfig.build.json","test":"jest","lint":"yarn run lint:tsc && yarn run lint:eslint && yarn run lint:prettier && yarn run lint:lockfile","lint:tsc":"tsc --noEmit","lint:eslint":"eslint . --ignore-path .gitignore --ext .ts,.tsx,.js,.jsx","lint:prettier":"prettier --check --ignore-path .gitignore '**/*.{ts,tsx,js,json}'","lint:lockfile":"lockfile-lint --type yarn --path yarn.lock --allowed-hosts yarn --validate-https --validate-checksum --validate-integrity","prettier":"prettier --write --ignore-path .gitignore '**/*.{ts,tsx,js,json}'","prepare":"yarn run build"},"dependencies":{"@findeth/abi":"^0.3.0","keccak":"^3.0.1","superstruct":"^0.10.12"},"devDependencies":{"@babel/cli":"^7.10.5","@babel/core":"^7.11.4","@babel/plugin-transform-modules-commonjs":"^7.10.4","@babel/preset-env":"^7.11.0","@babel/preset-typescript":"^7.10.4","@types/jest":"^26.0.10","@types/keccak":"^3.0.1","@typescript-eslint/eslint-plugin":"^3.10.1","@typescript-eslint/parser":"^3.10.1","babel-jest":"^26.3.0","codecov":"^3.7.2","cross-env":"^7.0.2","eslint":"^7.7.0","eslint-config-prettier":"^6.11.0","eslint-plugin-import":"^2.22.0","eslint-plugin-jest":"^23.20.0","ethereumjs-util":"^7.0.4","ethers":"^5.0.9","husky":"^4.2.5","jest":"^26.4.2","lint-staged":"^10.2.13","lockfile-lint":"^4.3.7","prettier":"^2.1.1","rimraf":"^3.0.2","ts-node":"^9.0.0","typescript":"^4.0.2"},"lint-staged":{"*.{ts,tsx}":["prettier --write","eslint --fix"],"*.{js,json}":["prettier --write"]},"husky":{"hooks":{"pre-commit":"lint-staged"}},"gitHead":"5da6085faa6e617f993a5b2c2314d9633cdbb5ed","homepage":"https://github.com/conflux-fans/cip-23#readme","_id":"@confluxfans/cip-23@0.1.0","_nodeVersion":"14.15.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-9QkTQtvZSdhsfMGLG9bHT3sN1eTnkGyXJSs6y9XCUy4t9gu1oY/UoGr55XhxpUwm0breKBHR+poq+iOdhdGMiQ==","shasum":"97918e5432b11a077ca72fb57d3d0cfd949b5ccf","tarball":"https://registry.npmjs.org/@confluxfans/cip-23/-/cip-23-0.1.0.tgz","fileCount":61,"unpackedSize":120428,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhA2S+CRA9TVsSAnZWagAAjUIQAKNrXKEDw17x1iWKaMZA\n+yhNwbG+zNUaTn+OWpUoENgd4ZesReoYZ77ZIucPiL0OY2yS961Wd5Ii+98D\njFqKv+7gB/0KeLOT7BmudLqvi33cCDeJQIRInJWH22anRwsNWvdeNzVLWk0j\n+twBAcgQzrKCXhGRhQ3HNE61OSZzYzuYtVi1aJWUV4dNsbvO1wMloIYPiYU5\nSlDZIaCugc31sEiz9BWBI1pNoJwdSK91awC7DB5+y8ZygsU80VUCMGTNOxal\nP7UkcETLNuaFT3+28o2/Ow7/sMntDdm42dxVnDuyVoqBM+KT5Z2qC9c/RUVr\n5ZuksjyNbRCqppKb7cceLEo7KOBn+inX5Mcs+TcImFJCrAMg6tiRBm7teril\n6oXqjE3FRC/shVGBwiqZSdw1ELcy3NIYXjYig6p75V/aA9nIIGzDgJdnS6uV\nqHVyqptZPvA5nkKmog+GsKl6lrkaDPyDKeoSWMtGyAw5BG9JEBmUH4V6z8Kp\nGSzlLIruv2gSem7m9OQ7NblYrjbNGcXPNg1/e13pdytXLv7XNQFu8SkjKZfA\nSJhQYR/T+aP3Yl46ztHSvGPQarKySzghlIpoScNT2V+1M13v7v/CretRSa4M\nGo1uHuBK2EfDsZLESYhlqYACmJ8OxaAkOMTNsKotIQpXzyyaS9dbLMDGvPqi\n+uKN\r\n=yTiI\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHd4S3a/JTHaypdpSON7ZFKDS/tbQxhLPFKVIhRq2dXLAiACuAVxuFOW4HDCtSLvQYEIfo317ga+1YeK9u+PZagnBg=="}]},"_npmUser":{"name":"pana","email":"pana.wang@outlook.com"},"directories":{},"maintainers":[{"name":"pana","email":"pana.wang@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cip-23_0.1.0_1627612349827_0.9402710612300231"},"_hasShrinkwrap":false}},"time":{"created":"2021-07-30T02:32:29.772Z","0.1.0":"2021-07-30T02:32:30.024Z","modified":"2022-04-05T00:54:19.732Z"},"maintainers":[{"name":"pana","email":"pana.wang@outlook.com"}],"description":"Tiny library with utility functions that can help with signing and verifying CIP-23 based messages","homepage":"https://github.com/conflux-fans/cip-23#readme","keywords":["conflux","cip23"],"repository":{"type":"git","url":"git+https://github.com/conflux-fans/cip-23.git"},"author":{"name":"Pana"},"bugs":{"url":"https://github.com/conflux-fans/cip-23/issues"},"license":"MIT","readme":"# `cip-23`\n\n![Version](https://img.shields.io/npm/v/cip-23) \n![License](https://img.shields.io/github/license/conflux-fans/cip-23) \n[![Actions Status](https://github.com/conflux-fans/cip-23/workflows/CI/badge.svg)](https://github.com/conflux-fans/cip-23/actions) \n[![codecov](https://codecov.io/gh/conflux-fans/cip-23/branch/master/graph/badge.svg)](https://codecov.io/gh/conflux-fans/cip-23)\n\nThis is a library for Node.js and web browsers with some utility functions that can help with signing and verifying [EIP-712](https://eips.ethereum.org/EIPS/eip-712) based messages. It is fully written in TypeScript, and is currently only compatible with the latest specification of EIP-712 ([eth_signTypedData_v4](https://docs.metamask.io/guide/signing-data.html#sign-typed-data-v4)).\n\nhttps://eips.ethereum.org/EIPS/eip-712\n\nNote that this library currently does not handle the signing itself. For this, you can use something like Ethers.js or ethereumjs-util. For examples, please see the [`examples`](https://github.com/conflux-fans/cip-23/blob/master/examples) folder.\n\n## Installation\n\nYou can install this library with Yarn or NPM:\n\n```\n$ yarn add cip-23\n```\n\n```\n$ npm install cip-23\n```\n\nThere is a CommonJS version as well as an ES6 version available. Most tools should automatically pick the right version (e.g. Node.js, Webpack).\n\n### Getting Started\n\nFirst, define your typed data as a JSON object, according to the JSON schema specified by cip-23. For example:\n\n```json\n{\n  \"types\": {\n    \"CIP23Domain\": [\n      { \"name\": \"name\", \"type\": \"string\" },\n      { \"name\": \"version\", \"type\": \"string\" },\n      { \"name\": \"chainId\", \"type\": \"uint256\" },\n      { \"name\": \"verifyingContract\", \"type\": \"address\" }\n    ],\n    \"Person\": [\n      { \"name\": \"name\", \"type\": \"string\" },\n      { \"name\": \"wallet\", \"type\": \"address\" }\n    ],\n    \"Mail\": [\n      { \"name\": \"from\", \"type\": \"Person\" },\n      { \"name\": \"to\", \"type\": \"Person\" },\n      { \"name\": \"contents\", \"type\": \"string\" }\n    ]\n  },\n  \"primaryType\": \"Mail\",\n  \"domain\": {\n    \"name\": \"Ether Mail\",\n    \"version\": \"1\",\n    \"chainId\": 1,\n    \"verifyingContract\": \"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC\"\n  },\n  \"message\": {\n    \"from\": {\n      \"name\": \"Cow\",\n      \"wallet\": \"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826\"\n    },\n    \"to\": {\n      \"name\": \"Bob\",\n      \"wallet\": \"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB\"\n    },\n    \"contents\": \"Hello, Bob!\"\n  }\n}\n```\n\n### Functions\n\nHere is a brief description of the functions available in this library. For more detailed examples, you can refer to [`src/cip-23.test.ts`](https://github.com/conflux-fans/cip-23/blob/master/src/cip-23.test.ts), or to the examples in the [`examples`](https://github.com/conflux-fans/cip-23/blob/master/examples) folder.\n\n#### `getMessage(typedData, hash?)`\n\nThis function will return the full EIP-191 encoded message to be signed as Buffer, for the typed data specified. If `hash` is enabled, the message will be hashed using Keccak256.\n\n```js\nimport { getMessage } from 'cip-23';\n\nconst typedData = { /*...*/ };\nconsole.log(getMessage(typedData).toString('hex')); // 1901f2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090fc52c0ee5d84264471806290a3f2c4cecfc5490626bf912d01f240d7a274b371e\nconsole.log(getMessage(typedData, true).toString('hex')); // be609aee343fb3c4b28e1df9e632fca64fcfaede20f02e86244efddf30957bd2\n```\n\n#### `asArray(typedData)`\n\nThis function returns the typed data as an array. This can be useful for encoding typed data as ABI.\n\n```js\nimport { asArray } from 'cip-23';\n\nconst typedData = { /*...*/ };\nconsole.log(asArray(typedData)); // [ ['Cow', '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826'], ['Bob', '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB'], 'Hello, Bob!' ]\n```\n\n#### `getStructHash(typedData, type, data)`\n\nThis function returns a Keccak-256 hash for a single struct type (e.g. cip-23, Person or Mail).\n\n```js\nimport { getStructHash } from 'cip-23';\n\nconst typedData = { /*...*/ };\nconsole.log(getStructHash(typedData, 'cip-23', typedData.domain).toString('hex')); // f2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f\n```\n\n#### `encodeData(typedData, type, data)`\n\nThis function returns the raw ABI encoded data for the struct type.\n\n```js\nimport { encodeData } from 'cip-23';\n\nconst typedData = { /*...*/ };\nconsole.log(encodeData(typedData, 'CIP23Domain', typedData.domain).toString('hex')); // 8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400fc70ef06638535b4881fafcac8287e210e3769ff1a8e91f1b95d6246e61e4d3c6c89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc60000000000000000000000000000000000000000000000000000000000000001000000000000000000000000cccccccccccccccccccccccccccccccccccccccc\n```\n\n#### `getTypeHash(typedData, type)`\n\nThis function returns the type hash for a struct type. This is the same as `Keccak256(CIP23Domain(string name,string version,uint256 chainId,address verifyingContract))`, with optional sub-types automatically included too.\n\n```js\nimport { getTypeHash } from 'cip-23';\n\nconst typedData = { /*...*/ };\nconsole.log(getTypeHash(typedData, 'CIP23Domain').toString('hex')); // 8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f\n```\n\n#### `encodeType(typedData, type)`\n\nThis function returns the type before hashing it, e.g. `CIP23Domain(string name,string version,uint256 chainId,address verifyingContract)`, with optional sub-types automatically included too.\n\n```js\nimport { encodeType } from 'cip-23';\n\nconst typedData = { /*...*/ };\nconsole.log(encodeType(typedData, 'CIP23Domain')); // CIP23Domain(string name,string version,uint256 chainId,address verifyingContract)\n```\n\n#### `getDependencies(typedData, type)`\n\nThis function returns all sub-types used by a struct as a string array. If the struct has no sub-types (like `CIP23Domain`), an array with only the type itself is returned.\n\n```js\nimport { getDependencies } from 'cip-23';\n\nconst typedData = { /*...*/ };\nconsole.log(getDependencies(typedData, 'CIP23Domain')); // ['CIP23Domain']\nconsole.log(getDependencies(typedData, 'Mail')); // ['Mail', 'Person']\n```\n","readmeFilename":"README.md"}