{"_id":"@adraffy/punycode-contracts","name":"@adraffy/punycode-contracts","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@adraffy/punycode-contracts","description":"Punycode in Solidity","version":"0.0.1","type":"module","scripts":{"build":"forge build --force","test":"npm run build && forge test && npm run readme && npm run validate","validate":"N=100000 node test/validate.js","validate-all":"N=Infinity node test/validate.js","gas":"node test/gas.js","readme":"forge script Readme"},"devDependencies":{"@adraffy/blocksmith":"^0.0.18","@adraffy/punycode":"^1.2.0"},"repository":{"type":"git","url":"git+https://github.com/adraffy/punycode.sol.git"},"license":"MIT","bugs":{"url":"https://github.com/adraffy/punycode.sol/issues"},"homepage":"https://github.com/adraffy/punycode.sol#readme","author":{"name":"raffy.eth"},"keywords":["solidity","ethereum","punycode"],"_id":"@adraffy/punycode-contracts@0.0.1","gitHead":"eb057dbd84aed8fd07ed852dac9472fb81fbb971","_nodeVersion":"21.4.0","_npmVersion":"10.2.4","dist":{"integrity":"sha512-DBKF3/O03lsB0/Sm4SlyEKo+x5V+RFh2EJjJKS+R+g8sZo1VR0MKBX/pNcDt24okw1zJgIa3oKnQ4/oQJYgywA==","shasum":"3998a54495437f7e86c5f4d211e16b38decdbfb4","tarball":"https://registry.npmjs.org/@adraffy/punycode-contracts/-/punycode-contracts-0.0.1.tgz","fileCount":5,"unpackedSize":14774,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEMDt6GgmDOBjFSFBTodGmICLlQiDKuU06SKdW8PbaeeAiEA5r/3dhCRJg9R9HQej/VJS7M4j2rV9oROZktjYpA4b6s="}]},"_npmUser":{"name":"adraffy","email":"raffy@me.com"},"directories":{},"maintainers":[{"name":"adraffy","email":"raffy@me.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/punycode-contracts_0.0.1_1713642171591_0.14879342729497513"},"_hasShrinkwrap":false}},"time":{"created":"2024-04-20T19:42:51.458Z","0.0.1":"2024-04-20T19:42:51.721Z","modified":"2024-04-20T19:42:51.976Z"},"maintainers":[{"name":"adraffy","email":"raffy@me.com"}],"description":"Punycode in Solidity","homepage":"https://github.com/adraffy/punycode.sol#readme","keywords":["solidity","ethereum","punycode"],"repository":{"type":"git","url":"git+https://github.com/adraffy/punycode.sol.git"},"author":{"name":"raffy.eth"},"bugs":{"url":"https://github.com/adraffy/punycode.sol/issues"},"license":"MIT","readme":"# punycode.sol\n\nSolidity [Punycode](https://datatracker.ietf.org/doc/html/rfc3492) without IDNA.\n* Library: [**Punycode.sol**](./src/Punycode.sol)\n\t* ASCII strings: `~500 gas` (fastpath)\n\t* Unicode strings:\n\t\t* Decode `~1300 gas/codepoint`\n\t\t* Encode `~2500 gas/codepoint`\n* Reference Implementation: [adraffy/**punycode.js**](https://github.com/adraffy/punycode.js/)\n* [**Demo**](https://adraffy.github.io/punycode.sol/test/demo.html) ⭐\n\t*  Deployment: [`base:0xBEfeca057ea022e7aB419670a659d32f125973C1`](https://basescan.org/address/0xBEfeca057ea022e7aB419670a659d32f125973C1#code)\n\n```solidity\nimport {Punycode} from \"https://github.com/adraffy/punycode.sol/blob/main/src/Punycode.sol\";\n\nstring memory unicode = Punycode.decode(\"xn--ls8h\"); // \"💩\"\nstring memory punycode = Punycode.encode(unicode\"💩\"); // \"xn--ls8h\"\n\n// reverts on failure\n// let me know if a tryDecode() is needed\nfunction decode(string memory s) pure returns (string memory) \n\n// never fails\nfunction encode(string memory s) pure returns (string memory)\n```\n\nLower-level functions:\n```solidity\n// src == dst if no encoding required\n// otherwise, (dst-32) is effectively `bytes`\nfunction decode(uint256 src, uint256 src_len) pure returns (uint256 dst, uint256 dst_len)\nfunction encode(uint256 src, uint256 src_len) pure returns (uint256 dst, uint256 dst_len)\n\n// example\nstring memory s = \"abc.xn--ls8h.com\";\nuint256 src;\nassembly { src := add(s, 32) }\n(uint256 dst, uint256 len) = Punycode.decode(src + 4, 8); // \"xn--ls8h\"\nconsole2.log(len); // 4 bytes\nassembly { s := sub(dst, 32) }\nconsole2.log(s); // \"💩\"\nbytes32 h;\nassembly { h := keccak256(dst, len) }\nconsole2.logBytes32(h); // 0xba967c160905ade030f84952644a963994eeaed3881a6b8a4e9c8cbe452ad7a2\n```\n\n## Test\n\n1. `foundryup`\n1. `npm i`\n1. `npm run test` — forge tests + random [validation](./test/test.js)\n1. (optional) `npm run validate-all` — complete [validation](./test/test.js)\n\n### Gas Analysis\n\n* `npm run gas` — [estimate gas](./test/gas.js)\n* `forge script GasEncode` — [estimate gas for `encode()`](./script/GasEncode.s.sol)\n* `forge script GasDecode` — [estimate gas for `decode()`](./script/GasDecode.s.sol)\n","readmeFilename":"README.md"}