@reown/appkit-cdn 1.8.15-viem-upgrade.0 → 1.8.15-wc-linking-reset-headless.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ConstantsUtil-CbwdoWl-.js +24 -0
- package/dist/ConstantsUtil-CbwdoWl-.js.map +1 -0
- package/dist/ExchangeController-Dqyc5bBG.js +265 -0
- package/dist/ExchangeController-Dqyc5bBG.js.map +1 -0
- package/dist/HelpersUtil-DU2h_IDh.js +141 -0
- package/dist/HelpersUtil-DU2h_IDh.js.map +1 -0
- package/dist/NavigationUtil-Ci15WS4K.js +9 -0
- package/dist/NavigationUtil-Ci15WS4K.js.map +1 -0
- package/dist/PhArrowCircleDown-B41iUlWV.js +74 -0
- package/dist/PhArrowCircleDown-B41iUlWV.js.map +1 -0
- package/dist/PhArrowClockwise-BY8u5n41.js +74 -0
- package/dist/PhArrowClockwise-BY8u5n41.js.map +1 -0
- package/dist/PhArrowDown-ClD8GZ65.js +74 -0
- package/dist/PhArrowDown-ClD8GZ65.js.map +1 -0
- package/dist/PhArrowLeft-B8MXUz60.js +74 -0
- package/dist/PhArrowLeft-B8MXUz60.js.map +1 -0
- package/dist/PhArrowRight-Cewa_Slb.js +74 -0
- package/dist/PhArrowRight-Cewa_Slb.js.map +1 -0
- package/dist/PhArrowSquareOut-whgWh-lD.js +74 -0
- package/dist/PhArrowSquareOut-whgWh-lD.js.map +1 -0
- package/dist/PhArrowUp-B1HXBxie.js +74 -0
- package/dist/PhArrowUp-B1HXBxie.js.map +1 -0
- package/dist/PhArrowUpRight-CfFYe4FP.js +74 -0
- package/dist/PhArrowUpRight-CfFYe4FP.js.map +1 -0
- package/dist/PhArrowsClockwise-gL1Gkrtx.js +74 -0
- package/dist/PhArrowsClockwise-gL1Gkrtx.js.map +1 -0
- package/dist/PhArrowsDownUp-BqUEdUQr.js +74 -0
- package/dist/PhArrowsDownUp-BqUEdUQr.js.map +1 -0
- package/dist/PhArrowsLeftRight-BlZU63eY.js +74 -0
- package/dist/PhArrowsLeftRight-BlZU63eY.js.map +1 -0
- package/dist/PhBank-gbg_jlI7.js +74 -0
- package/dist/PhBank-gbg_jlI7.js.map +1 -0
- package/dist/PhBrowser-CMlD-YJw.js +74 -0
- package/dist/PhBrowser-CMlD-YJw.js.map +1 -0
- package/dist/PhCaretDown-3agTO8Jp.js +74 -0
- package/dist/PhCaretDown-3agTO8Jp.js.map +1 -0
- package/dist/PhCaretLeft-_MTni7Z5.js +74 -0
- package/dist/PhCaretLeft-_MTni7Z5.js.map +1 -0
- package/dist/PhCaretRight-Ci9fAHPG.js +74 -0
- package/dist/PhCaretRight-Ci9fAHPG.js.map +1 -0
- package/dist/PhCaretUp-vFG4Fame.js +74 -0
- package/dist/PhCaretUp-vFG4Fame.js.map +1 -0
- package/dist/PhCheck-mChGK6K_.js +74 -0
- package/dist/PhCheck-mChGK6K_.js.map +1 -0
- package/dist/PhCircleHalf-DZ7-vfxf.js +74 -0
- package/dist/PhCircleHalf-DZ7-vfxf.js.map +1 -0
- package/dist/PhClock-Bc5XWXb6.js +74 -0
- package/dist/PhClock-Bc5XWXb6.js.map +1 -0
- package/dist/PhCompass-Cu2MB-55.js +74 -0
- package/dist/PhCompass-Cu2MB-55.js.map +1 -0
- package/dist/PhCopy-BGUjyTts.js +74 -0
- package/dist/PhCopy-BGUjyTts.js.map +1 -0
- package/dist/PhCreditCard-vxFWID4B.js +74 -0
- package/dist/PhCreditCard-vxFWID4B.js.map +1 -0
- package/dist/PhCurrencyDollar-BfOoDhJr.js +74 -0
- package/dist/PhCurrencyDollar-BfOoDhJr.js.map +1 -0
- package/dist/PhDesktop-Cq6jwzbS.js +74 -0
- package/dist/PhDesktop-Cq6jwzbS.js.map +1 -0
- package/dist/PhDeviceMobile-BCtTp6jj.js +74 -0
- package/dist/PhDeviceMobile-BCtTp6jj.js.map +1 -0
- package/dist/PhDotsThree-BGgD-WIO.js +74 -0
- package/dist/PhDotsThree-BGgD-WIO.js.map +1 -0
- package/dist/PhEnvelope-CQiV0-zG.js +74 -0
- package/dist/PhEnvelope-CQiV0-zG.js.map +1 -0
- package/dist/PhFunnelSimple-BHGtxTNf.js +74 -0
- package/dist/PhFunnelSimple-BHGtxTNf.js.map +1 -0
- package/dist/PhGlobe-Q8oVkf6X.js +74 -0
- package/dist/PhGlobe-Q8oVkf6X.js.map +1 -0
- package/dist/PhIdentificationCard-Cz9LzvVR.js +74 -0
- package/dist/PhIdentificationCard-Cz9LzvVR.js.map +1 -0
- package/dist/PhImage-CP5_qKk-.js +74 -0
- package/dist/PhImage-CP5_qKk-.js.map +1 -0
- package/dist/PhInfo-CTlE1X9Z.js +74 -0
- package/dist/PhInfo-CTlE1X9Z.js.map +1 -0
- package/dist/PhLightbulb-CcLpnAAb.js +74 -0
- package/dist/PhLightbulb-CcLpnAAb.js.map +1 -0
- package/dist/PhMagnifyingGlass-n58GUAck.js +74 -0
- package/dist/PhMagnifyingGlass-n58GUAck.js.map +1 -0
- package/dist/PhPaperPlaneRight-C0sf2XV8.js +74 -0
- package/dist/PhPaperPlaneRight-C0sf2XV8.js.map +1 -0
- package/dist/PhPlus-BJxvt7Uc.js +74 -0
- package/dist/PhPlus-BJxvt7Uc.js.map +1 -0
- package/dist/PhPower-BvktxO2-.js +74 -0
- package/dist/PhPower-BvktxO2-.js.map +1 -0
- package/dist/PhPuzzlePiece-CDDyUPYo.js +74 -0
- package/dist/PhPuzzlePiece-CDDyUPYo.js.map +1 -0
- package/dist/PhQrCode-BlGI8529.js +74 -0
- package/dist/PhQrCode-BlGI8529.js.map +1 -0
- package/dist/PhQuestion-DGZj6iDZ.js +74 -0
- package/dist/PhQuestion-DGZj6iDZ.js.map +1 -0
- package/dist/PhQuestionMark-CTmeI7MQ.js +74 -0
- package/dist/PhQuestionMark-CTmeI7MQ.js.map +1 -0
- package/dist/PhSealCheck-BSlqkxnH.js +74 -0
- package/dist/PhSealCheck-BSlqkxnH.js.map +1 -0
- package/dist/PhSignOut-CEXxlRk3.js +74 -0
- package/dist/PhSignOut-CEXxlRk3.js.map +1 -0
- package/dist/PhSpinner-Do1pY8fG.js +74 -0
- package/dist/PhSpinner-Do1pY8fG.js.map +1 -0
- package/dist/PhTrash-JNKavmpg.js +74 -0
- package/dist/PhTrash-JNKavmpg.js.map +1 -0
- package/dist/PhUser-BW7E-xYg.js +74 -0
- package/dist/PhUser-BW7E-xYg.js.map +1 -0
- package/dist/PhVault-mzxUgBYN.js +74 -0
- package/dist/PhVault-mzxUgBYN.js.map +1 -0
- package/dist/PhWallet-BR9JThKU.js +74 -0
- package/dist/PhWallet-BR9JThKU.js.map +1 -0
- package/dist/PhWarning-DxuQ70WM.js +74 -0
- package/dist/PhWarning-DxuQ70WM.js.map +1 -0
- package/dist/PhWarningCircle-DCI0JC1F.js +74 -0
- package/dist/PhWarningCircle-DCI0JC1F.js.map +1 -0
- package/dist/PhX-CWNXqpGn.js +74 -0
- package/dist/PhX-CWNXqpGn.js.map +1 -0
- package/dist/SwapController-jMZttK6h.js +684 -0
- package/dist/SwapController-jMZttK6h.js.map +1 -0
- package/dist/WebCryptoP256-BBztc0iu.js +3299 -0
- package/dist/WebCryptoP256-BBztc0iu.js.map +1 -0
- package/dist/add--c4dzQ5a.js +20 -0
- package/dist/add--c4dzQ5a.js.map +1 -0
- package/dist/all-wallets-qDP3dIqp.js +11 -0
- package/dist/all-wallets-qDP3dIqp.js.map +1 -0
- package/dist/app-store-D9l7eF2W.js +22 -0
- package/dist/app-store-D9l7eF2W.js.map +1 -0
- package/dist/appkit-BelUXm_6.js +117838 -0
- package/dist/appkit-BelUXm_6.js.map +1 -0
- package/dist/appkit.js +11 -0
- package/dist/appkit.js.map +1 -0
- package/dist/apple-CpoWHbAl.js +23 -0
- package/dist/apple-CpoWHbAl.js.map +1 -0
- package/dist/arrow-bottom-Duw4wyrB.js +13 -0
- package/dist/arrow-bottom-Duw4wyrB.js.map +1 -0
- package/dist/arrow-bottom-circle-jzrzTJTi.js +16 -0
- package/dist/arrow-bottom-circle-jzrzTJTi.js.map +1 -0
- package/dist/arrow-left-DZ8261mb.js +13 -0
- package/dist/arrow-left-DZ8261mb.js.map +1 -0
- package/dist/arrow-right-BkSWH-o2.js +13 -0
- package/dist/arrow-right-BkSWH-o2.js.map +1 -0
- package/dist/arrow-top-CZ-VhKD6.js +13 -0
- package/dist/arrow-top-CZ-VhKD6.js.map +1 -0
- package/dist/async-directive-DxJWJE9R.js +73 -0
- package/dist/async-directive-DxJWJE9R.js.map +1 -0
- package/dist/bank-Dqp8PTLk.js +19 -0
- package/dist/bank-Dqp8PTLk.js.map +1 -0
- package/dist/basic-DFEi41zA.js +4914 -0
- package/dist/basic-DFEi41zA.js.map +1 -0
- package/dist/browser-5XoTmr4n.js +1991 -0
- package/dist/browser-5XoTmr4n.js.map +1 -0
- package/dist/browser-BPO6XEtY.js +19 -0
- package/dist/browser-BPO6XEtY.js.map +1 -0
- package/dist/card-V3yaUpoc.js +19 -0
- package/dist/card-V3yaUpoc.js.map +1 -0
- package/dist/ccip-BoFoMwtu.js +164 -0
- package/dist/ccip-BoFoMwtu.js.map +1 -0
- package/dist/checkmark-DSiyB22o.js +16 -0
- package/dist/checkmark-DSiyB22o.js.map +1 -0
- package/dist/checkmark-bold-Bv7-ZO8v.js +13 -0
- package/dist/checkmark-bold-Bv7-ZO8v.js.map +1 -0
- package/dist/chevron-bottom-B2TGsNMu.js +13 -0
- package/dist/chevron-bottom-B2TGsNMu.js.map +1 -0
- package/dist/chevron-left-Cwx-XOsq.js +13 -0
- package/dist/chevron-left-Cwx-XOsq.js.map +1 -0
- package/dist/chevron-right-BGnzEWju.js +13 -0
- package/dist/chevron-right-BGnzEWju.js.map +1 -0
- package/dist/chevron-top-C-e2sCE8.js +13 -0
- package/dist/chevron-top-C-e2sCE8.js.map +1 -0
- package/dist/chrome-store-Dk-JjvFO.js +66 -0
- package/dist/chrome-store-Dk-JjvFO.js.map +1 -0
- package/dist/class-map-ZEs4CrSH.js +101 -0
- package/dist/class-map-ZEs4CrSH.js.map +1 -0
- package/dist/clock-DqVZkTjt.js +13 -0
- package/dist/clock-DqVZkTjt.js.map +1 -0
- package/dist/close-iWBWiaHR.js +13 -0
- package/dist/close-iWBWiaHR.js.map +1 -0
- package/dist/clsx.m-D57qXwfE.js +21 -0
- package/dist/clsx.m-D57qXwfE.js.map +1 -0
- package/dist/coinPlaceholder-DamDZh25.js +13 -0
- package/dist/coinPlaceholder-DamDZh25.js.map +1 -0
- package/dist/compass-DK4o4OBL.js +13 -0
- package/dist/compass-DK4o4OBL.js.map +1 -0
- package/dist/copy-eQpimOO_.js +20 -0
- package/dist/copy-eQpimOO_.js.map +1 -0
- package/dist/core-Blm5BnNJ.js +16288 -0
- package/dist/core-Blm5BnNJ.js.map +1 -0
- package/dist/cursor-k5vr3_IY.js +8 -0
- package/dist/cursor-k5vr3_IY.js.map +1 -0
- package/dist/cursor-transparent-C72dSWkl.js +17 -0
- package/dist/cursor-transparent-C72dSWkl.js.map +1 -0
- package/dist/data-capture-BYDXaTJ7.js +549 -0
- package/dist/data-capture-BYDXaTJ7.js.map +1 -0
- package/dist/desktop-BKt6U1LK.js +14 -0
- package/dist/desktop-BKt6U1LK.js.map +1 -0
- package/dist/disconnect-BN2JhgmS.js +13 -0
- package/dist/disconnect-BN2JhgmS.js.map +1 -0
- package/dist/discord-BPXpxniL.js +22 -0
- package/dist/discord-BPXpxniL.js.map +1 -0
- package/dist/email-CNuZeI4u.js +421 -0
- package/dist/email-CNuZeI4u.js.map +1 -0
- package/dist/embedded-wallet-LWvrPF_o.js +952 -0
- package/dist/embedded-wallet-LWvrPF_o.js.map +1 -0
- package/dist/etherscan-DDKRPzA-.js +11 -0
- package/dist/etherscan-DDKRPzA-.js.map +1 -0
- package/dist/exclamation-triangle-D-8fgdY1.js +9 -0
- package/dist/exclamation-triangle-D-8fgdY1.js.map +1 -0
- package/dist/extension-Dxcr6kcX.js +13 -0
- package/dist/extension-Dxcr6kcX.js.map +1 -0
- package/dist/external-link-CAGwU0J9.js +13 -0
- package/dist/external-link-CAGwU0J9.js.map +1 -0
- package/dist/facebook-CLDxOaIb.js +31 -0
- package/dist/facebook-CLDxOaIb.js.map +1 -0
- package/dist/farcaster-Cw3u-UPo.js +17 -0
- package/dist/farcaster-Cw3u-UPo.js.map +1 -0
- package/dist/features-vg2POspn.js +319 -0
- package/dist/features-vg2POspn.js.map +1 -0
- package/dist/filters-COA9syz-.js +13 -0
- package/dist/filters-COA9syz-.js.map +1 -0
- package/dist/github-D7S2v9I4.js +23 -0
- package/dist/github-D7S2v9I4.js.map +1 -0
- package/dist/google-D0CqK5v9.js +23 -0
- package/dist/google-D0CqK5v9.js.map +1 -0
- package/dist/hashTypedData-CSpZpAVZ.js +262 -0
- package/dist/hashTypedData-CSpZpAVZ.js.map +1 -0
- package/dist/help-circle-DUNo_nkC.js +17 -0
- package/dist/help-circle-DUNo_nkC.js.map +1 -0
- package/dist/id-I68XskJD.js +17 -0
- package/dist/id-I68XskJD.js.map +1 -0
- package/dist/if-defined-CZFxJBnA.js +11 -0
- package/dist/if-defined-CZFxJBnA.js.map +1 -0
- package/dist/image-B5cNqRyN.js +9 -0
- package/dist/image-B5cNqRyN.js.map +1 -0
- package/dist/index-104DdYHO.js +985 -0
- package/dist/index-104DdYHO.js.map +1 -0
- package/dist/index-B3zs1e7u.js +181 -0
- package/dist/index-B3zs1e7u.js.map +1 -0
- package/dist/index-B5NSdMiU.js +218 -0
- package/dist/index-B5NSdMiU.js.map +1 -0
- package/dist/index-B6iHFF4h.js +136 -0
- package/dist/index-B6iHFF4h.js.map +1 -0
- package/dist/index-B8jsF--g.js +1582 -0
- package/dist/index-B8jsF--g.js.map +1 -0
- package/dist/index-BB3tQw2Z.js +9350 -0
- package/dist/index-BB3tQw2Z.js.map +1 -0
- package/dist/index-BKk3ruzQ.js +456 -0
- package/dist/index-BKk3ruzQ.js.map +1 -0
- package/dist/index-BLjdKVPF.js +18322 -0
- package/dist/index-BLjdKVPF.js.map +1 -0
- package/dist/index-BOoc_x7l.js +180 -0
- package/dist/index-BOoc_x7l.js.map +1 -0
- package/dist/index-BeheLXdB.js +441 -0
- package/dist/index-BeheLXdB.js.map +1 -0
- package/dist/index-BgqBk_dY.js +147 -0
- package/dist/index-BgqBk_dY.js.map +1 -0
- package/dist/index-Bnorl9_z.js +1372 -0
- package/dist/index-Bnorl9_z.js.map +1 -0
- package/dist/index-C26sVife.js +967 -0
- package/dist/index-C26sVife.js.map +1 -0
- package/dist/index-C32JOlST.js +198 -0
- package/dist/index-C32JOlST.js.map +1 -0
- package/dist/index-C78ZsEMq.js +211 -0
- package/dist/index-C78ZsEMq.js.map +1 -0
- package/dist/index-C8oew4P6.js +153 -0
- package/dist/index-C8oew4P6.js.map +1 -0
- package/dist/index-CNlrW5cy.js +126 -0
- package/dist/index-CNlrW5cy.js.map +1 -0
- package/dist/index-CWtAW9yD.js +70 -0
- package/dist/index-CWtAW9yD.js.map +1 -0
- package/dist/index-CZYTg7wq.js +7258 -0
- package/dist/index-CZYTg7wq.js.map +1 -0
- package/dist/index-CcLQYms1.js +109 -0
- package/dist/index-CcLQYms1.js.map +1 -0
- package/dist/index-Cmdv-EKc.js +3987 -0
- package/dist/index-Cmdv-EKc.js.map +1 -0
- package/dist/index-D0jIxjP5.js +611 -0
- package/dist/index-D0jIxjP5.js.map +1 -0
- package/dist/index-D1RMkx4Z.js +73 -0
- package/dist/index-D1RMkx4Z.js.map +1 -0
- package/dist/index-D80ztMVu.js +7481 -0
- package/dist/index-D80ztMVu.js.map +1 -0
- package/dist/index-D9I51xNN.js +124 -0
- package/dist/index-D9I51xNN.js.map +1 -0
- package/dist/index-DC3uHGx5.js +281 -0
- package/dist/index-DC3uHGx5.js.map +1 -0
- package/dist/index-DKaSbFmS.js +62 -0
- package/dist/index-DKaSbFmS.js.map +1 -0
- package/dist/index-DMfKX7xa.js +52 -0
- package/dist/index-DMfKX7xa.js.map +1 -0
- package/dist/index-DRONCFaf.js +521 -0
- package/dist/index-DRONCFaf.js.map +1 -0
- package/dist/index-DWU2cJP9.js +984 -0
- package/dist/index-DWU2cJP9.js.map +1 -0
- package/dist/index-Dk1HiwFn.js +110 -0
- package/dist/index-Dk1HiwFn.js.map +1 -0
- package/dist/index-DoDZtBzt.js +257 -0
- package/dist/index-DoDZtBzt.js.map +1 -0
- package/dist/index-DrMicDEk.js +8825 -0
- package/dist/index-DrMicDEk.js.map +1 -0
- package/dist/index-DwCIGVjJ.js +2277 -0
- package/dist/index-DwCIGVjJ.js.map +1 -0
- package/dist/index-G39WAG_u.js +249 -0
- package/dist/index-G39WAG_u.js.map +1 -0
- package/dist/index-LKmHdTip.js +120 -0
- package/dist/index-LKmHdTip.js.map +1 -0
- package/dist/index-Q4ByiA8h.js +92 -0
- package/dist/index-Q4ByiA8h.js.map +1 -0
- package/dist/index-WWBlLBf0.js +286 -0
- package/dist/index-WWBlLBf0.js.map +1 -0
- package/dist/index-YriocA8k.js +542 -0
- package/dist/index-YriocA8k.js.map +1 -0
- package/dist/index-iZY344lJ.js +131 -0
- package/dist/index-iZY344lJ.js.map +1 -0
- package/dist/index-jvpHgQNC.js +1178 -0
- package/dist/index-jvpHgQNC.js.map +1 -0
- package/dist/index-l79JdXA-.js +198 -0
- package/dist/index-l79JdXA-.js.map +1 -0
- package/dist/index-ln8WeuTF.js +520 -0
- package/dist/index-ln8WeuTF.js.map +1 -0
- package/dist/index-qKPbj0fN.js +147 -0
- package/dist/index-qKPbj0fN.js.map +1 -0
- package/dist/index-vbfIJzga.js +182 -0
- package/dist/index-vbfIJzga.js.map +1 -0
- package/dist/index-ydt0zLSU.js +716 -0
- package/dist/index-ydt0zLSU.js.map +1 -0
- package/dist/index.es-DRqDW831.js +8503 -0
- package/dist/index.es-DRqDW831.js.map +1 -0
- package/dist/info-2WDwQZjB.js +8 -0
- package/dist/info-2WDwQZjB.js.map +1 -0
- package/dist/info-circle-CtSQ1Thr.js +17 -0
- package/dist/info-circle-CtSQ1Thr.js.map +1 -0
- package/dist/jsxRuntime.module-xbg0Y-2w.js +14 -0
- package/dist/jsxRuntime.module-xbg0Y-2w.js.map +1 -0
- package/dist/lightbulb-BSt44yHY.js +8 -0
- package/dist/lightbulb-BSt44yHY.js.map +1 -0
- package/dist/localBatchGatewayRequest-BfhYO3yz.js +103 -0
- package/dist/localBatchGatewayRequest-BfhYO3yz.js.map +1 -0
- package/dist/mail-BrPzu8JI.js +13 -0
- package/dist/mail-BrPzu8JI.js.map +1 -0
- package/dist/metamask-sdk-BH2upH2a.js +16699 -0
- package/dist/metamask-sdk-BH2upH2a.js.map +1 -0
- package/dist/mobile-qOQzY1mQ.js +14 -0
- package/dist/mobile-qOQzY1mQ.js.map +1 -0
- package/dist/more-Q55BhoHR.js +16 -0
- package/dist/more-Q55BhoHR.js.map +1 -0
- package/dist/native-NhO1oTAz.js +17 -0
- package/dist/native-NhO1oTAz.js.map +1 -0
- package/dist/network-placeholder-CNNFAqAN.js +19 -0
- package/dist/network-placeholder-CNNFAqAN.js.map +1 -0
- package/dist/nftPlaceholder-XepUac1F.js +13 -0
- package/dist/nftPlaceholder-XepUac1F.js.map +1 -0
- package/dist/off-B5pFs_h0.js +13 -0
- package/dist/off-B5pFs_h0.js.map +1 -0
- package/dist/onramp-Cmf4-Qlj.js +979 -0
- package/dist/onramp-Cmf4-Qlj.js.map +1 -0
- package/dist/parseAbiParameters-DfJcIE_w.js +757 -0
- package/dist/parseAbiParameters-DfJcIE_w.js.map +1 -0
- package/dist/parseSignature-DLIuU8h-.js +4690 -0
- package/dist/parseSignature-DLIuU8h-.js.map +1 -0
- package/dist/pay-with-exchange-BiRfWQtt.js +603 -0
- package/dist/pay-with-exchange-BiRfWQtt.js.map +1 -0
- package/dist/play-store-CHMgTh6o.js +37 -0
- package/dist/play-store-CHMgTh6o.js.map +1 -0
- package/dist/plus-DAYpNXcX.js +18 -0
- package/dist/plus-DAYpNXcX.js.map +1 -0
- package/dist/property-8UcTqffH.js +623 -0
- package/dist/property-8UcTqffH.js.map +1 -0
- package/dist/qr-code-5EvgAs5C.js +11 -0
- package/dist/qr-code-5EvgAs5C.js.map +1 -0
- package/dist/receive-oh6JkMzT.js +262 -0
- package/dist/receive-oh6JkMzT.js.map +1 -0
- package/dist/recycle-horizontal-C0EVYvdu.js +14 -0
- package/dist/recycle-horizontal-C0EVYvdu.js.map +1 -0
- package/dist/ref-DYqCwuKj.js +43 -0
- package/dist/ref-DYqCwuKj.js.map +1 -0
- package/dist/refresh-Tz7Hx6xG.js +13 -0
- package/dist/refresh-Tz7Hx6xG.js.map +1 -0
- package/dist/reown-logo-DKFEGfm5.js +17 -0
- package/dist/reown-logo-DKFEGfm5.js.map +1 -0
- package/dist/search-DJmD5Dmk.js +13 -0
- package/dist/search-DJmD5Dmk.js.map +1 -0
- package/dist/secp256k1-ZaBTFi_B.js +2031 -0
- package/dist/secp256k1-ZaBTFi_B.js.map +1 -0
- package/dist/send-CkjE5TE2.js +1365 -0
- package/dist/send-CkjE5TE2.js.map +1 -0
- package/dist/send-DcwwYxtP.js +20 -0
- package/dist/send-DcwwYxtP.js.map +1 -0
- package/dist/socials-TnAlgPAE.js +796 -0
- package/dist/socials-TnAlgPAE.js.map +1 -0
- package/dist/swapHorizontal-Zswl5rJe.js +13 -0
- package/dist/swapHorizontal-Zswl5rJe.js.map +1 -0
- package/dist/swapHorizontalBold-NXydKsqQ.js +13 -0
- package/dist/swapHorizontalBold-NXydKsqQ.js.map +1 -0
- package/dist/swapHorizontalMedium-HEMBHJa5.js +21 -0
- package/dist/swapHorizontalMedium-HEMBHJa5.js.map +1 -0
- package/dist/swapHorizontalRoundedBold-fNHd25RU.js +13 -0
- package/dist/swapHorizontalRoundedBold-fNHd25RU.js.map +1 -0
- package/dist/swapVertical-BcCPonRa.js +13 -0
- package/dist/swapVertical-BcCPonRa.js.map +1 -0
- package/dist/swaps-Cz2XSX5K.js +2121 -0
- package/dist/swaps-Cz2XSX5K.js.map +1 -0
- package/dist/telegram-CRGTc0Vs.js +21 -0
- package/dist/telegram-CRGTc0Vs.js.map +1 -0
- package/dist/three-dots-CprpVKTn.js +10 -0
- package/dist/three-dots-CprpVKTn.js.map +1 -0
- package/dist/transactions-ItRrEBwI.js +38 -0
- package/dist/transactions-ItRrEBwI.js.map +1 -0
- package/dist/twitch-vWuHTtgh.js +23 -0
- package/dist/twitch-vWuHTtgh.js.map +1 -0
- package/dist/twitterIcon-Bo4HL4oD.js +11 -0
- package/dist/twitterIcon-Bo4HL4oD.js.map +1 -0
- package/dist/vanilla-CgG5xMJO.js +448 -0
- package/dist/vanilla-CgG5xMJO.js.map +1 -0
- package/dist/verify-PpZz6LN4.js +13 -0
- package/dist/verify-PpZz6LN4.js.map +1 -0
- package/dist/verify-filled-CUpk2g5N.js +13 -0
- package/dist/verify-filled-CUpk2g5N.js.map +1 -0
- package/dist/w3m-modal-BZQIOBsI.js +1725 -0
- package/dist/w3m-modal-BZQIOBsI.js.map +1 -0
- package/dist/w3m-modal-D5sYObzl.js +2008 -0
- package/dist/w3m-modal-D5sYObzl.js.map +1 -0
- package/dist/wallet-Blc0Swur.js +13 -0
- package/dist/wallet-Blc0Swur.js.map +1 -0
- package/dist/wallet-placeholder-DkGnPkjp.js +19 -0
- package/dist/wallet-placeholder-DkGnPkjp.js.map +1 -0
- package/dist/wallet-standard-CDzUhZ2i.js +523 -0
- package/dist/wallet-standard-CDzUhZ2i.js.map +1 -0
- package/dist/walletconnect-CfJMuRWG.js +39 -0
- package/dist/walletconnect-CfJMuRWG.js.map +1 -0
- package/dist/warning-circle-BW2kbw7R.js +17 -0
- package/dist/warning-circle-BW2kbw7R.js.map +1 -0
- package/dist/x-CT_VClTi.js +17 -0
- package/dist/x-CT_VClTi.js.map +1 -0
- package/package.json +10 -10
|
@@ -0,0 +1,2031 @@
|
|
|
1
|
+
import { H as Hash, c as createView, a as aexists, t as toBytes, b as aoutput, w as wrapConstructor, r as rotr, d as ahash, e as abytes$1, f as randomBytes, g as concatBytes$1 } from "./index.es-DRqDW831.js";
|
|
2
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
|
3
|
+
if (typeof view.setBigUint64 === "function")
|
|
4
|
+
return view.setBigUint64(byteOffset, value, isLE);
|
|
5
|
+
const _32n = BigInt(32);
|
|
6
|
+
const _u32_max = BigInt(4294967295);
|
|
7
|
+
const wh = Number(value >> _32n & _u32_max);
|
|
8
|
+
const wl = Number(value & _u32_max);
|
|
9
|
+
const h = isLE ? 4 : 0;
|
|
10
|
+
const l = isLE ? 0 : 4;
|
|
11
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
|
12
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
13
|
+
}
|
|
14
|
+
function Chi(a, b, c) {
|
|
15
|
+
return a & b ^ ~a & c;
|
|
16
|
+
}
|
|
17
|
+
function Maj(a, b, c) {
|
|
18
|
+
return a & b ^ a & c ^ b & c;
|
|
19
|
+
}
|
|
20
|
+
class HashMD extends Hash {
|
|
21
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
22
|
+
super();
|
|
23
|
+
this.blockLen = blockLen;
|
|
24
|
+
this.outputLen = outputLen;
|
|
25
|
+
this.padOffset = padOffset;
|
|
26
|
+
this.isLE = isLE;
|
|
27
|
+
this.finished = false;
|
|
28
|
+
this.length = 0;
|
|
29
|
+
this.pos = 0;
|
|
30
|
+
this.destroyed = false;
|
|
31
|
+
this.buffer = new Uint8Array(blockLen);
|
|
32
|
+
this.view = createView(this.buffer);
|
|
33
|
+
}
|
|
34
|
+
update(data) {
|
|
35
|
+
aexists(this);
|
|
36
|
+
const { view, buffer, blockLen } = this;
|
|
37
|
+
data = toBytes(data);
|
|
38
|
+
const len = data.length;
|
|
39
|
+
for (let pos = 0; pos < len; ) {
|
|
40
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
41
|
+
if (take === blockLen) {
|
|
42
|
+
const dataView = createView(data);
|
|
43
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
44
|
+
this.process(dataView, pos);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
48
|
+
this.pos += take;
|
|
49
|
+
pos += take;
|
|
50
|
+
if (this.pos === blockLen) {
|
|
51
|
+
this.process(view, 0);
|
|
52
|
+
this.pos = 0;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
this.length += data.length;
|
|
56
|
+
this.roundClean();
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
digestInto(out) {
|
|
60
|
+
aexists(this);
|
|
61
|
+
aoutput(out, this);
|
|
62
|
+
this.finished = true;
|
|
63
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
64
|
+
let { pos } = this;
|
|
65
|
+
buffer[pos++] = 128;
|
|
66
|
+
this.buffer.subarray(pos).fill(0);
|
|
67
|
+
if (this.padOffset > blockLen - pos) {
|
|
68
|
+
this.process(view, 0);
|
|
69
|
+
pos = 0;
|
|
70
|
+
}
|
|
71
|
+
for (let i = pos; i < blockLen; i++)
|
|
72
|
+
buffer[i] = 0;
|
|
73
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
74
|
+
this.process(view, 0);
|
|
75
|
+
const oview = createView(out);
|
|
76
|
+
const len = this.outputLen;
|
|
77
|
+
if (len % 4)
|
|
78
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
79
|
+
const outLen = len / 4;
|
|
80
|
+
const state = this.get();
|
|
81
|
+
if (outLen > state.length)
|
|
82
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
83
|
+
for (let i = 0; i < outLen; i++)
|
|
84
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
85
|
+
}
|
|
86
|
+
digest() {
|
|
87
|
+
const { buffer, outputLen } = this;
|
|
88
|
+
this.digestInto(buffer);
|
|
89
|
+
const res = buffer.slice(0, outputLen);
|
|
90
|
+
this.destroy();
|
|
91
|
+
return res;
|
|
92
|
+
}
|
|
93
|
+
_cloneInto(to) {
|
|
94
|
+
to || (to = new this.constructor());
|
|
95
|
+
to.set(...this.get());
|
|
96
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
97
|
+
to.length = length;
|
|
98
|
+
to.pos = pos;
|
|
99
|
+
to.finished = finished;
|
|
100
|
+
to.destroyed = destroyed;
|
|
101
|
+
if (length % blockLen)
|
|
102
|
+
to.buffer.set(buffer);
|
|
103
|
+
return to;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
107
|
+
1116352408,
|
|
108
|
+
1899447441,
|
|
109
|
+
3049323471,
|
|
110
|
+
3921009573,
|
|
111
|
+
961987163,
|
|
112
|
+
1508970993,
|
|
113
|
+
2453635748,
|
|
114
|
+
2870763221,
|
|
115
|
+
3624381080,
|
|
116
|
+
310598401,
|
|
117
|
+
607225278,
|
|
118
|
+
1426881987,
|
|
119
|
+
1925078388,
|
|
120
|
+
2162078206,
|
|
121
|
+
2614888103,
|
|
122
|
+
3248222580,
|
|
123
|
+
3835390401,
|
|
124
|
+
4022224774,
|
|
125
|
+
264347078,
|
|
126
|
+
604807628,
|
|
127
|
+
770255983,
|
|
128
|
+
1249150122,
|
|
129
|
+
1555081692,
|
|
130
|
+
1996064986,
|
|
131
|
+
2554220882,
|
|
132
|
+
2821834349,
|
|
133
|
+
2952996808,
|
|
134
|
+
3210313671,
|
|
135
|
+
3336571891,
|
|
136
|
+
3584528711,
|
|
137
|
+
113926993,
|
|
138
|
+
338241895,
|
|
139
|
+
666307205,
|
|
140
|
+
773529912,
|
|
141
|
+
1294757372,
|
|
142
|
+
1396182291,
|
|
143
|
+
1695183700,
|
|
144
|
+
1986661051,
|
|
145
|
+
2177026350,
|
|
146
|
+
2456956037,
|
|
147
|
+
2730485921,
|
|
148
|
+
2820302411,
|
|
149
|
+
3259730800,
|
|
150
|
+
3345764771,
|
|
151
|
+
3516065817,
|
|
152
|
+
3600352804,
|
|
153
|
+
4094571909,
|
|
154
|
+
275423344,
|
|
155
|
+
430227734,
|
|
156
|
+
506948616,
|
|
157
|
+
659060556,
|
|
158
|
+
883997877,
|
|
159
|
+
958139571,
|
|
160
|
+
1322822218,
|
|
161
|
+
1537002063,
|
|
162
|
+
1747873779,
|
|
163
|
+
1955562222,
|
|
164
|
+
2024104815,
|
|
165
|
+
2227730452,
|
|
166
|
+
2361852424,
|
|
167
|
+
2428436474,
|
|
168
|
+
2756734187,
|
|
169
|
+
3204031479,
|
|
170
|
+
3329325298
|
|
171
|
+
]);
|
|
172
|
+
const SHA256_IV = /* @__PURE__ */ new Uint32Array([
|
|
173
|
+
1779033703,
|
|
174
|
+
3144134277,
|
|
175
|
+
1013904242,
|
|
176
|
+
2773480762,
|
|
177
|
+
1359893119,
|
|
178
|
+
2600822924,
|
|
179
|
+
528734635,
|
|
180
|
+
1541459225
|
|
181
|
+
]);
|
|
182
|
+
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
183
|
+
class SHA256 extends HashMD {
|
|
184
|
+
constructor() {
|
|
185
|
+
super(64, 32, 8, false);
|
|
186
|
+
this.A = SHA256_IV[0] | 0;
|
|
187
|
+
this.B = SHA256_IV[1] | 0;
|
|
188
|
+
this.C = SHA256_IV[2] | 0;
|
|
189
|
+
this.D = SHA256_IV[3] | 0;
|
|
190
|
+
this.E = SHA256_IV[4] | 0;
|
|
191
|
+
this.F = SHA256_IV[5] | 0;
|
|
192
|
+
this.G = SHA256_IV[6] | 0;
|
|
193
|
+
this.H = SHA256_IV[7] | 0;
|
|
194
|
+
}
|
|
195
|
+
get() {
|
|
196
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
197
|
+
return [A, B, C, D, E, F, G, H];
|
|
198
|
+
}
|
|
199
|
+
// prettier-ignore
|
|
200
|
+
set(A, B, C, D, E, F, G, H) {
|
|
201
|
+
this.A = A | 0;
|
|
202
|
+
this.B = B | 0;
|
|
203
|
+
this.C = C | 0;
|
|
204
|
+
this.D = D | 0;
|
|
205
|
+
this.E = E | 0;
|
|
206
|
+
this.F = F | 0;
|
|
207
|
+
this.G = G | 0;
|
|
208
|
+
this.H = H | 0;
|
|
209
|
+
}
|
|
210
|
+
process(view, offset) {
|
|
211
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
212
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
|
213
|
+
for (let i = 16; i < 64; i++) {
|
|
214
|
+
const W15 = SHA256_W[i - 15];
|
|
215
|
+
const W2 = SHA256_W[i - 2];
|
|
216
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
217
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
218
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
219
|
+
}
|
|
220
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
221
|
+
for (let i = 0; i < 64; i++) {
|
|
222
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
223
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
224
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
225
|
+
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
226
|
+
H = G;
|
|
227
|
+
G = F;
|
|
228
|
+
F = E;
|
|
229
|
+
E = D + T1 | 0;
|
|
230
|
+
D = C;
|
|
231
|
+
C = B;
|
|
232
|
+
B = A;
|
|
233
|
+
A = T1 + T2 | 0;
|
|
234
|
+
}
|
|
235
|
+
A = A + this.A | 0;
|
|
236
|
+
B = B + this.B | 0;
|
|
237
|
+
C = C + this.C | 0;
|
|
238
|
+
D = D + this.D | 0;
|
|
239
|
+
E = E + this.E | 0;
|
|
240
|
+
F = F + this.F | 0;
|
|
241
|
+
G = G + this.G | 0;
|
|
242
|
+
H = H + this.H | 0;
|
|
243
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
244
|
+
}
|
|
245
|
+
roundClean() {
|
|
246
|
+
SHA256_W.fill(0);
|
|
247
|
+
}
|
|
248
|
+
destroy() {
|
|
249
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
250
|
+
this.buffer.fill(0);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
|
254
|
+
class HMAC extends Hash {
|
|
255
|
+
constructor(hash, _key) {
|
|
256
|
+
super();
|
|
257
|
+
this.finished = false;
|
|
258
|
+
this.destroyed = false;
|
|
259
|
+
ahash(hash);
|
|
260
|
+
const key = toBytes(_key);
|
|
261
|
+
this.iHash = hash.create();
|
|
262
|
+
if (typeof this.iHash.update !== "function")
|
|
263
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
264
|
+
this.blockLen = this.iHash.blockLen;
|
|
265
|
+
this.outputLen = this.iHash.outputLen;
|
|
266
|
+
const blockLen = this.blockLen;
|
|
267
|
+
const pad = new Uint8Array(blockLen);
|
|
268
|
+
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
269
|
+
for (let i = 0; i < pad.length; i++)
|
|
270
|
+
pad[i] ^= 54;
|
|
271
|
+
this.iHash.update(pad);
|
|
272
|
+
this.oHash = hash.create();
|
|
273
|
+
for (let i = 0; i < pad.length; i++)
|
|
274
|
+
pad[i] ^= 54 ^ 92;
|
|
275
|
+
this.oHash.update(pad);
|
|
276
|
+
pad.fill(0);
|
|
277
|
+
}
|
|
278
|
+
update(buf) {
|
|
279
|
+
aexists(this);
|
|
280
|
+
this.iHash.update(buf);
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
283
|
+
digestInto(out) {
|
|
284
|
+
aexists(this);
|
|
285
|
+
abytes$1(out, this.outputLen);
|
|
286
|
+
this.finished = true;
|
|
287
|
+
this.iHash.digestInto(out);
|
|
288
|
+
this.oHash.update(out);
|
|
289
|
+
this.oHash.digestInto(out);
|
|
290
|
+
this.destroy();
|
|
291
|
+
}
|
|
292
|
+
digest() {
|
|
293
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
294
|
+
this.digestInto(out);
|
|
295
|
+
return out;
|
|
296
|
+
}
|
|
297
|
+
_cloneInto(to) {
|
|
298
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
299
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
300
|
+
to = to;
|
|
301
|
+
to.finished = finished;
|
|
302
|
+
to.destroyed = destroyed;
|
|
303
|
+
to.blockLen = blockLen;
|
|
304
|
+
to.outputLen = outputLen;
|
|
305
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
306
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
307
|
+
return to;
|
|
308
|
+
}
|
|
309
|
+
destroy() {
|
|
310
|
+
this.destroyed = true;
|
|
311
|
+
this.oHash.destroy();
|
|
312
|
+
this.iHash.destroy();
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
const hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
316
|
+
hmac.create = (hash, key) => new HMAC(hash, key);
|
|
317
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
318
|
+
const _0n$3 = /* @__PURE__ */ BigInt(0);
|
|
319
|
+
const _1n$4 = /* @__PURE__ */ BigInt(1);
|
|
320
|
+
const _2n$2 = /* @__PURE__ */ BigInt(2);
|
|
321
|
+
function isBytes(a) {
|
|
322
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
323
|
+
}
|
|
324
|
+
function abytes(item) {
|
|
325
|
+
if (!isBytes(item))
|
|
326
|
+
throw new Error("Uint8Array expected");
|
|
327
|
+
}
|
|
328
|
+
function abool(title, value) {
|
|
329
|
+
if (typeof value !== "boolean")
|
|
330
|
+
throw new Error(title + " boolean expected, got " + value);
|
|
331
|
+
}
|
|
332
|
+
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
333
|
+
function bytesToHex(bytes) {
|
|
334
|
+
abytes(bytes);
|
|
335
|
+
let hex = "";
|
|
336
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
337
|
+
hex += hexes[bytes[i]];
|
|
338
|
+
}
|
|
339
|
+
return hex;
|
|
340
|
+
}
|
|
341
|
+
function numberToHexUnpadded(num) {
|
|
342
|
+
const hex = num.toString(16);
|
|
343
|
+
return hex.length & 1 ? "0" + hex : hex;
|
|
344
|
+
}
|
|
345
|
+
function hexToNumber(hex) {
|
|
346
|
+
if (typeof hex !== "string")
|
|
347
|
+
throw new Error("hex string expected, got " + typeof hex);
|
|
348
|
+
return hex === "" ? _0n$3 : BigInt("0x" + hex);
|
|
349
|
+
}
|
|
350
|
+
const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
351
|
+
function asciiToBase16(ch) {
|
|
352
|
+
if (ch >= asciis._0 && ch <= asciis._9)
|
|
353
|
+
return ch - asciis._0;
|
|
354
|
+
if (ch >= asciis.A && ch <= asciis.F)
|
|
355
|
+
return ch - (asciis.A - 10);
|
|
356
|
+
if (ch >= asciis.a && ch <= asciis.f)
|
|
357
|
+
return ch - (asciis.a - 10);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
function hexToBytes(hex) {
|
|
361
|
+
if (typeof hex !== "string")
|
|
362
|
+
throw new Error("hex string expected, got " + typeof hex);
|
|
363
|
+
const hl = hex.length;
|
|
364
|
+
const al = hl / 2;
|
|
365
|
+
if (hl % 2)
|
|
366
|
+
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
367
|
+
const array = new Uint8Array(al);
|
|
368
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
369
|
+
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
370
|
+
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
371
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
372
|
+
const char = hex[hi] + hex[hi + 1];
|
|
373
|
+
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
374
|
+
}
|
|
375
|
+
array[ai] = n1 * 16 + n2;
|
|
376
|
+
}
|
|
377
|
+
return array;
|
|
378
|
+
}
|
|
379
|
+
function bytesToNumberBE(bytes) {
|
|
380
|
+
return hexToNumber(bytesToHex(bytes));
|
|
381
|
+
}
|
|
382
|
+
function bytesToNumberLE(bytes) {
|
|
383
|
+
abytes(bytes);
|
|
384
|
+
return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
|
|
385
|
+
}
|
|
386
|
+
function numberToBytesBE(n, len) {
|
|
387
|
+
return hexToBytes(n.toString(16).padStart(len * 2, "0"));
|
|
388
|
+
}
|
|
389
|
+
function numberToBytesLE(n, len) {
|
|
390
|
+
return numberToBytesBE(n, len).reverse();
|
|
391
|
+
}
|
|
392
|
+
function numberToVarBytesBE(n) {
|
|
393
|
+
return hexToBytes(numberToHexUnpadded(n));
|
|
394
|
+
}
|
|
395
|
+
function ensureBytes(title, hex, expectedLength) {
|
|
396
|
+
let res;
|
|
397
|
+
if (typeof hex === "string") {
|
|
398
|
+
try {
|
|
399
|
+
res = hexToBytes(hex);
|
|
400
|
+
} catch (e) {
|
|
401
|
+
throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
|
|
402
|
+
}
|
|
403
|
+
} else if (isBytes(hex)) {
|
|
404
|
+
res = Uint8Array.from(hex);
|
|
405
|
+
} else {
|
|
406
|
+
throw new Error(title + " must be hex string or Uint8Array");
|
|
407
|
+
}
|
|
408
|
+
const len = res.length;
|
|
409
|
+
if (typeof expectedLength === "number" && len !== expectedLength)
|
|
410
|
+
throw new Error(title + " of length " + expectedLength + " expected, got " + len);
|
|
411
|
+
return res;
|
|
412
|
+
}
|
|
413
|
+
function concatBytes(...arrays) {
|
|
414
|
+
let sum = 0;
|
|
415
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
416
|
+
const a = arrays[i];
|
|
417
|
+
abytes(a);
|
|
418
|
+
sum += a.length;
|
|
419
|
+
}
|
|
420
|
+
const res = new Uint8Array(sum);
|
|
421
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
422
|
+
const a = arrays[i];
|
|
423
|
+
res.set(a, pad);
|
|
424
|
+
pad += a.length;
|
|
425
|
+
}
|
|
426
|
+
return res;
|
|
427
|
+
}
|
|
428
|
+
function equalBytes(a, b) {
|
|
429
|
+
if (a.length !== b.length)
|
|
430
|
+
return false;
|
|
431
|
+
let diff = 0;
|
|
432
|
+
for (let i = 0; i < a.length; i++)
|
|
433
|
+
diff |= a[i] ^ b[i];
|
|
434
|
+
return diff === 0;
|
|
435
|
+
}
|
|
436
|
+
function utf8ToBytes(str) {
|
|
437
|
+
if (typeof str !== "string")
|
|
438
|
+
throw new Error("string expected");
|
|
439
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
440
|
+
}
|
|
441
|
+
const isPosBig = (n) => typeof n === "bigint" && _0n$3 <= n;
|
|
442
|
+
function inRange(n, min, max) {
|
|
443
|
+
return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
|
|
444
|
+
}
|
|
445
|
+
function aInRange(title, n, min, max) {
|
|
446
|
+
if (!inRange(n, min, max))
|
|
447
|
+
throw new Error("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n);
|
|
448
|
+
}
|
|
449
|
+
function bitLen(n) {
|
|
450
|
+
let len;
|
|
451
|
+
for (len = 0; n > _0n$3; n >>= _1n$4, len += 1)
|
|
452
|
+
;
|
|
453
|
+
return len;
|
|
454
|
+
}
|
|
455
|
+
function bitGet(n, pos) {
|
|
456
|
+
return n >> BigInt(pos) & _1n$4;
|
|
457
|
+
}
|
|
458
|
+
function bitSet(n, pos, value) {
|
|
459
|
+
return n | (value ? _1n$4 : _0n$3) << BigInt(pos);
|
|
460
|
+
}
|
|
461
|
+
const bitMask = (n) => (_2n$2 << BigInt(n - 1)) - _1n$4;
|
|
462
|
+
const u8n = (data) => new Uint8Array(data);
|
|
463
|
+
const u8fr = (arr) => Uint8Array.from(arr);
|
|
464
|
+
function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
465
|
+
if (typeof hashLen !== "number" || hashLen < 2)
|
|
466
|
+
throw new Error("hashLen must be a number");
|
|
467
|
+
if (typeof qByteLen !== "number" || qByteLen < 2)
|
|
468
|
+
throw new Error("qByteLen must be a number");
|
|
469
|
+
if (typeof hmacFn !== "function")
|
|
470
|
+
throw new Error("hmacFn must be a function");
|
|
471
|
+
let v = u8n(hashLen);
|
|
472
|
+
let k = u8n(hashLen);
|
|
473
|
+
let i = 0;
|
|
474
|
+
const reset = () => {
|
|
475
|
+
v.fill(1);
|
|
476
|
+
k.fill(0);
|
|
477
|
+
i = 0;
|
|
478
|
+
};
|
|
479
|
+
const h = (...b) => hmacFn(k, v, ...b);
|
|
480
|
+
const reseed = (seed = u8n()) => {
|
|
481
|
+
k = h(u8fr([0]), seed);
|
|
482
|
+
v = h();
|
|
483
|
+
if (seed.length === 0)
|
|
484
|
+
return;
|
|
485
|
+
k = h(u8fr([1]), seed);
|
|
486
|
+
v = h();
|
|
487
|
+
};
|
|
488
|
+
const gen = () => {
|
|
489
|
+
if (i++ >= 1e3)
|
|
490
|
+
throw new Error("drbg: tried 1000 values");
|
|
491
|
+
let len = 0;
|
|
492
|
+
const out = [];
|
|
493
|
+
while (len < qByteLen) {
|
|
494
|
+
v = h();
|
|
495
|
+
const sl = v.slice();
|
|
496
|
+
out.push(sl);
|
|
497
|
+
len += v.length;
|
|
498
|
+
}
|
|
499
|
+
return concatBytes(...out);
|
|
500
|
+
};
|
|
501
|
+
const genUntil = (seed, pred) => {
|
|
502
|
+
reset();
|
|
503
|
+
reseed(seed);
|
|
504
|
+
let res = void 0;
|
|
505
|
+
while (!(res = pred(gen())))
|
|
506
|
+
reseed();
|
|
507
|
+
reset();
|
|
508
|
+
return res;
|
|
509
|
+
};
|
|
510
|
+
return genUntil;
|
|
511
|
+
}
|
|
512
|
+
const validatorFns = {
|
|
513
|
+
bigint: (val) => typeof val === "bigint",
|
|
514
|
+
function: (val) => typeof val === "function",
|
|
515
|
+
boolean: (val) => typeof val === "boolean",
|
|
516
|
+
string: (val) => typeof val === "string",
|
|
517
|
+
stringOrUint8Array: (val) => typeof val === "string" || isBytes(val),
|
|
518
|
+
isSafeInteger: (val) => Number.isSafeInteger(val),
|
|
519
|
+
array: (val) => Array.isArray(val),
|
|
520
|
+
field: (val, object) => object.Fp.isValid(val),
|
|
521
|
+
hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
|
|
522
|
+
};
|
|
523
|
+
function validateObject(object, validators, optValidators = {}) {
|
|
524
|
+
const checkField = (fieldName, type, isOptional) => {
|
|
525
|
+
const checkVal = validatorFns[type];
|
|
526
|
+
if (typeof checkVal !== "function")
|
|
527
|
+
throw new Error("invalid validator function");
|
|
528
|
+
const val = object[fieldName];
|
|
529
|
+
if (isOptional && val === void 0)
|
|
530
|
+
return;
|
|
531
|
+
if (!checkVal(val, object)) {
|
|
532
|
+
throw new Error("param " + String(fieldName) + " is invalid. Expected " + type + ", got " + val);
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
for (const [fieldName, type] of Object.entries(validators))
|
|
536
|
+
checkField(fieldName, type, false);
|
|
537
|
+
for (const [fieldName, type] of Object.entries(optValidators))
|
|
538
|
+
checkField(fieldName, type, true);
|
|
539
|
+
return object;
|
|
540
|
+
}
|
|
541
|
+
const notImplemented = () => {
|
|
542
|
+
throw new Error("not implemented");
|
|
543
|
+
};
|
|
544
|
+
function memoized(fn) {
|
|
545
|
+
const map = /* @__PURE__ */ new WeakMap();
|
|
546
|
+
return (arg, ...args) => {
|
|
547
|
+
const val = map.get(arg);
|
|
548
|
+
if (val !== void 0)
|
|
549
|
+
return val;
|
|
550
|
+
const computed = fn(arg, ...args);
|
|
551
|
+
map.set(arg, computed);
|
|
552
|
+
return computed;
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
const ut = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
556
|
+
__proto__: null,
|
|
557
|
+
aInRange,
|
|
558
|
+
abool,
|
|
559
|
+
abytes,
|
|
560
|
+
bitGet,
|
|
561
|
+
bitLen,
|
|
562
|
+
bitMask,
|
|
563
|
+
bitSet,
|
|
564
|
+
bytesToHex,
|
|
565
|
+
bytesToNumberBE,
|
|
566
|
+
bytesToNumberLE,
|
|
567
|
+
concatBytes,
|
|
568
|
+
createHmacDrbg,
|
|
569
|
+
ensureBytes,
|
|
570
|
+
equalBytes,
|
|
571
|
+
hexToBytes,
|
|
572
|
+
hexToNumber,
|
|
573
|
+
inRange,
|
|
574
|
+
isBytes,
|
|
575
|
+
memoized,
|
|
576
|
+
notImplemented,
|
|
577
|
+
numberToBytesBE,
|
|
578
|
+
numberToBytesLE,
|
|
579
|
+
numberToHexUnpadded,
|
|
580
|
+
numberToVarBytesBE,
|
|
581
|
+
utf8ToBytes,
|
|
582
|
+
validateObject
|
|
583
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
584
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
585
|
+
const _0n$2 = BigInt(0), _1n$3 = BigInt(1), _2n$1 = /* @__PURE__ */ BigInt(2), _3n$1 = /* @__PURE__ */ BigInt(3);
|
|
586
|
+
const _4n = /* @__PURE__ */ BigInt(4), _5n = /* @__PURE__ */ BigInt(5), _8n = /* @__PURE__ */ BigInt(8);
|
|
587
|
+
function mod(a, b) {
|
|
588
|
+
const result = a % b;
|
|
589
|
+
return result >= _0n$2 ? result : b + result;
|
|
590
|
+
}
|
|
591
|
+
function pow(num, power, modulo) {
|
|
592
|
+
if (power < _0n$2)
|
|
593
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
594
|
+
if (modulo <= _0n$2)
|
|
595
|
+
throw new Error("invalid modulus");
|
|
596
|
+
if (modulo === _1n$3)
|
|
597
|
+
return _0n$2;
|
|
598
|
+
let res = _1n$3;
|
|
599
|
+
while (power > _0n$2) {
|
|
600
|
+
if (power & _1n$3)
|
|
601
|
+
res = res * num % modulo;
|
|
602
|
+
num = num * num % modulo;
|
|
603
|
+
power >>= _1n$3;
|
|
604
|
+
}
|
|
605
|
+
return res;
|
|
606
|
+
}
|
|
607
|
+
function pow2(x, power, modulo) {
|
|
608
|
+
let res = x;
|
|
609
|
+
while (power-- > _0n$2) {
|
|
610
|
+
res *= res;
|
|
611
|
+
res %= modulo;
|
|
612
|
+
}
|
|
613
|
+
return res;
|
|
614
|
+
}
|
|
615
|
+
function invert(number, modulo) {
|
|
616
|
+
if (number === _0n$2)
|
|
617
|
+
throw new Error("invert: expected non-zero number");
|
|
618
|
+
if (modulo <= _0n$2)
|
|
619
|
+
throw new Error("invert: expected positive modulus, got " + modulo);
|
|
620
|
+
let a = mod(number, modulo);
|
|
621
|
+
let b = modulo;
|
|
622
|
+
let x = _0n$2, u = _1n$3;
|
|
623
|
+
while (a !== _0n$2) {
|
|
624
|
+
const q = b / a;
|
|
625
|
+
const r = b % a;
|
|
626
|
+
const m = x - u * q;
|
|
627
|
+
b = a, a = r, x = u, u = m;
|
|
628
|
+
}
|
|
629
|
+
const gcd = b;
|
|
630
|
+
if (gcd !== _1n$3)
|
|
631
|
+
throw new Error("invert: does not exist");
|
|
632
|
+
return mod(x, modulo);
|
|
633
|
+
}
|
|
634
|
+
function tonelliShanks(P) {
|
|
635
|
+
const legendreC = (P - _1n$3) / _2n$1;
|
|
636
|
+
let Q, S, Z;
|
|
637
|
+
for (Q = P - _1n$3, S = 0; Q % _2n$1 === _0n$2; Q /= _2n$1, S++)
|
|
638
|
+
;
|
|
639
|
+
for (Z = _2n$1; Z < P && pow(Z, legendreC, P) !== P - _1n$3; Z++) {
|
|
640
|
+
if (Z > 1e3)
|
|
641
|
+
throw new Error("Cannot find square root: likely non-prime P");
|
|
642
|
+
}
|
|
643
|
+
if (S === 1) {
|
|
644
|
+
const p1div4 = (P + _1n$3) / _4n;
|
|
645
|
+
return function tonelliFast(Fp, n) {
|
|
646
|
+
const root = Fp.pow(n, p1div4);
|
|
647
|
+
if (!Fp.eql(Fp.sqr(root), n))
|
|
648
|
+
throw new Error("Cannot find square root");
|
|
649
|
+
return root;
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
const Q1div2 = (Q + _1n$3) / _2n$1;
|
|
653
|
+
return function tonelliSlow(Fp, n) {
|
|
654
|
+
if (Fp.pow(n, legendreC) === Fp.neg(Fp.ONE))
|
|
655
|
+
throw new Error("Cannot find square root");
|
|
656
|
+
let r = S;
|
|
657
|
+
let g = Fp.pow(Fp.mul(Fp.ONE, Z), Q);
|
|
658
|
+
let x = Fp.pow(n, Q1div2);
|
|
659
|
+
let b = Fp.pow(n, Q);
|
|
660
|
+
while (!Fp.eql(b, Fp.ONE)) {
|
|
661
|
+
if (Fp.eql(b, Fp.ZERO))
|
|
662
|
+
return Fp.ZERO;
|
|
663
|
+
let m = 1;
|
|
664
|
+
for (let t2 = Fp.sqr(b); m < r; m++) {
|
|
665
|
+
if (Fp.eql(t2, Fp.ONE))
|
|
666
|
+
break;
|
|
667
|
+
t2 = Fp.sqr(t2);
|
|
668
|
+
}
|
|
669
|
+
const ge = Fp.pow(g, _1n$3 << BigInt(r - m - 1));
|
|
670
|
+
g = Fp.sqr(ge);
|
|
671
|
+
x = Fp.mul(x, ge);
|
|
672
|
+
b = Fp.mul(b, g);
|
|
673
|
+
r = m;
|
|
674
|
+
}
|
|
675
|
+
return x;
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
function FpSqrt(P) {
|
|
679
|
+
if (P % _4n === _3n$1) {
|
|
680
|
+
const p1div4 = (P + _1n$3) / _4n;
|
|
681
|
+
return function sqrt3mod4(Fp, n) {
|
|
682
|
+
const root = Fp.pow(n, p1div4);
|
|
683
|
+
if (!Fp.eql(Fp.sqr(root), n))
|
|
684
|
+
throw new Error("Cannot find square root");
|
|
685
|
+
return root;
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
if (P % _8n === _5n) {
|
|
689
|
+
const c1 = (P - _5n) / _8n;
|
|
690
|
+
return function sqrt5mod8(Fp, n) {
|
|
691
|
+
const n2 = Fp.mul(n, _2n$1);
|
|
692
|
+
const v = Fp.pow(n2, c1);
|
|
693
|
+
const nv = Fp.mul(n, v);
|
|
694
|
+
const i = Fp.mul(Fp.mul(nv, _2n$1), v);
|
|
695
|
+
const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
|
|
696
|
+
if (!Fp.eql(Fp.sqr(root), n))
|
|
697
|
+
throw new Error("Cannot find square root");
|
|
698
|
+
return root;
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
return tonelliShanks(P);
|
|
702
|
+
}
|
|
703
|
+
const FIELD_FIELDS = [
|
|
704
|
+
"create",
|
|
705
|
+
"isValid",
|
|
706
|
+
"is0",
|
|
707
|
+
"neg",
|
|
708
|
+
"inv",
|
|
709
|
+
"sqrt",
|
|
710
|
+
"sqr",
|
|
711
|
+
"eql",
|
|
712
|
+
"add",
|
|
713
|
+
"sub",
|
|
714
|
+
"mul",
|
|
715
|
+
"pow",
|
|
716
|
+
"div",
|
|
717
|
+
"addN",
|
|
718
|
+
"subN",
|
|
719
|
+
"mulN",
|
|
720
|
+
"sqrN"
|
|
721
|
+
];
|
|
722
|
+
function validateField(field) {
|
|
723
|
+
const initial = {
|
|
724
|
+
ORDER: "bigint",
|
|
725
|
+
MASK: "bigint",
|
|
726
|
+
BYTES: "isSafeInteger",
|
|
727
|
+
BITS: "isSafeInteger"
|
|
728
|
+
};
|
|
729
|
+
const opts = FIELD_FIELDS.reduce((map, val) => {
|
|
730
|
+
map[val] = "function";
|
|
731
|
+
return map;
|
|
732
|
+
}, initial);
|
|
733
|
+
return validateObject(field, opts);
|
|
734
|
+
}
|
|
735
|
+
function FpPow(f, num, power) {
|
|
736
|
+
if (power < _0n$2)
|
|
737
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
738
|
+
if (power === _0n$2)
|
|
739
|
+
return f.ONE;
|
|
740
|
+
if (power === _1n$3)
|
|
741
|
+
return num;
|
|
742
|
+
let p = f.ONE;
|
|
743
|
+
let d = num;
|
|
744
|
+
while (power > _0n$2) {
|
|
745
|
+
if (power & _1n$3)
|
|
746
|
+
p = f.mul(p, d);
|
|
747
|
+
d = f.sqr(d);
|
|
748
|
+
power >>= _1n$3;
|
|
749
|
+
}
|
|
750
|
+
return p;
|
|
751
|
+
}
|
|
752
|
+
function FpInvertBatch(f, nums) {
|
|
753
|
+
const tmp = new Array(nums.length);
|
|
754
|
+
const lastMultiplied = nums.reduce((acc, num, i) => {
|
|
755
|
+
if (f.is0(num))
|
|
756
|
+
return acc;
|
|
757
|
+
tmp[i] = acc;
|
|
758
|
+
return f.mul(acc, num);
|
|
759
|
+
}, f.ONE);
|
|
760
|
+
const inverted = f.inv(lastMultiplied);
|
|
761
|
+
nums.reduceRight((acc, num, i) => {
|
|
762
|
+
if (f.is0(num))
|
|
763
|
+
return acc;
|
|
764
|
+
tmp[i] = f.mul(acc, tmp[i]);
|
|
765
|
+
return f.mul(acc, num);
|
|
766
|
+
}, inverted);
|
|
767
|
+
return tmp;
|
|
768
|
+
}
|
|
769
|
+
function nLength(n, nBitLength) {
|
|
770
|
+
const _nBitLength = nBitLength !== void 0 ? nBitLength : n.toString(2).length;
|
|
771
|
+
const nByteLength = Math.ceil(_nBitLength / 8);
|
|
772
|
+
return { nBitLength: _nBitLength, nByteLength };
|
|
773
|
+
}
|
|
774
|
+
function Field(ORDER, bitLen2, isLE = false, redef = {}) {
|
|
775
|
+
if (ORDER <= _0n$2)
|
|
776
|
+
throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
|
|
777
|
+
const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
|
|
778
|
+
if (BYTES > 2048)
|
|
779
|
+
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
780
|
+
let sqrtP;
|
|
781
|
+
const f = Object.freeze({
|
|
782
|
+
ORDER,
|
|
783
|
+
isLE,
|
|
784
|
+
BITS,
|
|
785
|
+
BYTES,
|
|
786
|
+
MASK: bitMask(BITS),
|
|
787
|
+
ZERO: _0n$2,
|
|
788
|
+
ONE: _1n$3,
|
|
789
|
+
create: (num) => mod(num, ORDER),
|
|
790
|
+
isValid: (num) => {
|
|
791
|
+
if (typeof num !== "bigint")
|
|
792
|
+
throw new Error("invalid field element: expected bigint, got " + typeof num);
|
|
793
|
+
return _0n$2 <= num && num < ORDER;
|
|
794
|
+
},
|
|
795
|
+
is0: (num) => num === _0n$2,
|
|
796
|
+
isOdd: (num) => (num & _1n$3) === _1n$3,
|
|
797
|
+
neg: (num) => mod(-num, ORDER),
|
|
798
|
+
eql: (lhs, rhs) => lhs === rhs,
|
|
799
|
+
sqr: (num) => mod(num * num, ORDER),
|
|
800
|
+
add: (lhs, rhs) => mod(lhs + rhs, ORDER),
|
|
801
|
+
sub: (lhs, rhs) => mod(lhs - rhs, ORDER),
|
|
802
|
+
mul: (lhs, rhs) => mod(lhs * rhs, ORDER),
|
|
803
|
+
pow: (num, power) => FpPow(f, num, power),
|
|
804
|
+
div: (lhs, rhs) => mod(lhs * invert(rhs, ORDER), ORDER),
|
|
805
|
+
// Same as above, but doesn't normalize
|
|
806
|
+
sqrN: (num) => num * num,
|
|
807
|
+
addN: (lhs, rhs) => lhs + rhs,
|
|
808
|
+
subN: (lhs, rhs) => lhs - rhs,
|
|
809
|
+
mulN: (lhs, rhs) => lhs * rhs,
|
|
810
|
+
inv: (num) => invert(num, ORDER),
|
|
811
|
+
sqrt: redef.sqrt || ((n) => {
|
|
812
|
+
if (!sqrtP)
|
|
813
|
+
sqrtP = FpSqrt(ORDER);
|
|
814
|
+
return sqrtP(f, n);
|
|
815
|
+
}),
|
|
816
|
+
invertBatch: (lst) => FpInvertBatch(f, lst),
|
|
817
|
+
// TODO: do we really need constant cmov?
|
|
818
|
+
// We don't have const-time bigints anyway, so probably will be not very useful
|
|
819
|
+
cmov: (a, b, c) => c ? b : a,
|
|
820
|
+
toBytes: (num) => isLE ? numberToBytesLE(num, BYTES) : numberToBytesBE(num, BYTES),
|
|
821
|
+
fromBytes: (bytes) => {
|
|
822
|
+
if (bytes.length !== BYTES)
|
|
823
|
+
throw new Error("Field.fromBytes: expected " + BYTES + " bytes, got " + bytes.length);
|
|
824
|
+
return isLE ? bytesToNumberLE(bytes) : bytesToNumberBE(bytes);
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
return Object.freeze(f);
|
|
828
|
+
}
|
|
829
|
+
function getFieldBytesLength(fieldOrder) {
|
|
830
|
+
if (typeof fieldOrder !== "bigint")
|
|
831
|
+
throw new Error("field order must be bigint");
|
|
832
|
+
const bitLength = fieldOrder.toString(2).length;
|
|
833
|
+
return Math.ceil(bitLength / 8);
|
|
834
|
+
}
|
|
835
|
+
function getMinHashLength(fieldOrder) {
|
|
836
|
+
const length = getFieldBytesLength(fieldOrder);
|
|
837
|
+
return length + Math.ceil(length / 2);
|
|
838
|
+
}
|
|
839
|
+
function mapHashToField(key, fieldOrder, isLE = false) {
|
|
840
|
+
const len = key.length;
|
|
841
|
+
const fieldLen = getFieldBytesLength(fieldOrder);
|
|
842
|
+
const minLen = getMinHashLength(fieldOrder);
|
|
843
|
+
if (len < 16 || len < minLen || len > 1024)
|
|
844
|
+
throw new Error("expected " + minLen + "-1024 bytes of input, got " + len);
|
|
845
|
+
const num = isLE ? bytesToNumberLE(key) : bytesToNumberBE(key);
|
|
846
|
+
const reduced = mod(num, fieldOrder - _1n$3) + _1n$3;
|
|
847
|
+
return isLE ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
|
|
848
|
+
}
|
|
849
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
850
|
+
const _0n$1 = BigInt(0);
|
|
851
|
+
const _1n$2 = BigInt(1);
|
|
852
|
+
function constTimeNegate(condition, item) {
|
|
853
|
+
const neg = item.negate();
|
|
854
|
+
return condition ? neg : item;
|
|
855
|
+
}
|
|
856
|
+
function validateW(W, bits) {
|
|
857
|
+
if (!Number.isSafeInteger(W) || W <= 0 || W > bits)
|
|
858
|
+
throw new Error("invalid window size, expected [1.." + bits + "], got W=" + W);
|
|
859
|
+
}
|
|
860
|
+
function calcWOpts(W, bits) {
|
|
861
|
+
validateW(W, bits);
|
|
862
|
+
const windows = Math.ceil(bits / W) + 1;
|
|
863
|
+
const windowSize = 2 ** (W - 1);
|
|
864
|
+
return { windows, windowSize };
|
|
865
|
+
}
|
|
866
|
+
function validateMSMPoints(points, c) {
|
|
867
|
+
if (!Array.isArray(points))
|
|
868
|
+
throw new Error("array expected");
|
|
869
|
+
points.forEach((p, i) => {
|
|
870
|
+
if (!(p instanceof c))
|
|
871
|
+
throw new Error("invalid point at index " + i);
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
function validateMSMScalars(scalars, field) {
|
|
875
|
+
if (!Array.isArray(scalars))
|
|
876
|
+
throw new Error("array of scalars expected");
|
|
877
|
+
scalars.forEach((s, i) => {
|
|
878
|
+
if (!field.isValid(s))
|
|
879
|
+
throw new Error("invalid scalar at index " + i);
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
const pointPrecomputes = /* @__PURE__ */ new WeakMap();
|
|
883
|
+
const pointWindowSizes = /* @__PURE__ */ new WeakMap();
|
|
884
|
+
function getW(P) {
|
|
885
|
+
return pointWindowSizes.get(P) || 1;
|
|
886
|
+
}
|
|
887
|
+
function wNAF(c, bits) {
|
|
888
|
+
return {
|
|
889
|
+
constTimeNegate,
|
|
890
|
+
hasPrecomputes(elm) {
|
|
891
|
+
return getW(elm) !== 1;
|
|
892
|
+
},
|
|
893
|
+
// non-const time multiplication ladder
|
|
894
|
+
unsafeLadder(elm, n, p = c.ZERO) {
|
|
895
|
+
let d = elm;
|
|
896
|
+
while (n > _0n$1) {
|
|
897
|
+
if (n & _1n$2)
|
|
898
|
+
p = p.add(d);
|
|
899
|
+
d = d.double();
|
|
900
|
+
n >>= _1n$2;
|
|
901
|
+
}
|
|
902
|
+
return p;
|
|
903
|
+
},
|
|
904
|
+
/**
|
|
905
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
906
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
907
|
+
* Number of precomputed points depends on the curve size:
|
|
908
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
909
|
+
* - 𝑊 is the window size
|
|
910
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
911
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
912
|
+
* @param elm Point instance
|
|
913
|
+
* @param W window size
|
|
914
|
+
* @returns precomputed point tables flattened to a single array
|
|
915
|
+
*/
|
|
916
|
+
precomputeWindow(elm, W) {
|
|
917
|
+
const { windows, windowSize } = calcWOpts(W, bits);
|
|
918
|
+
const points = [];
|
|
919
|
+
let p = elm;
|
|
920
|
+
let base = p;
|
|
921
|
+
for (let window = 0; window < windows; window++) {
|
|
922
|
+
base = p;
|
|
923
|
+
points.push(base);
|
|
924
|
+
for (let i = 1; i < windowSize; i++) {
|
|
925
|
+
base = base.add(p);
|
|
926
|
+
points.push(base);
|
|
927
|
+
}
|
|
928
|
+
p = base.double();
|
|
929
|
+
}
|
|
930
|
+
return points;
|
|
931
|
+
},
|
|
932
|
+
/**
|
|
933
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
934
|
+
* @param W window size
|
|
935
|
+
* @param precomputes precomputed tables
|
|
936
|
+
* @param n scalar (we don't check here, but should be less than curve order)
|
|
937
|
+
* @returns real and fake (for const-time) points
|
|
938
|
+
*/
|
|
939
|
+
wNAF(W, precomputes, n) {
|
|
940
|
+
const { windows, windowSize } = calcWOpts(W, bits);
|
|
941
|
+
let p = c.ZERO;
|
|
942
|
+
let f = c.BASE;
|
|
943
|
+
const mask = BigInt(2 ** W - 1);
|
|
944
|
+
const maxNumber = 2 ** W;
|
|
945
|
+
const shiftBy = BigInt(W);
|
|
946
|
+
for (let window = 0; window < windows; window++) {
|
|
947
|
+
const offset = window * windowSize;
|
|
948
|
+
let wbits = Number(n & mask);
|
|
949
|
+
n >>= shiftBy;
|
|
950
|
+
if (wbits > windowSize) {
|
|
951
|
+
wbits -= maxNumber;
|
|
952
|
+
n += _1n$2;
|
|
953
|
+
}
|
|
954
|
+
const offset1 = offset;
|
|
955
|
+
const offset2 = offset + Math.abs(wbits) - 1;
|
|
956
|
+
const cond1 = window % 2 !== 0;
|
|
957
|
+
const cond2 = wbits < 0;
|
|
958
|
+
if (wbits === 0) {
|
|
959
|
+
f = f.add(constTimeNegate(cond1, precomputes[offset1]));
|
|
960
|
+
} else {
|
|
961
|
+
p = p.add(constTimeNegate(cond2, precomputes[offset2]));
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
return { p, f };
|
|
965
|
+
},
|
|
966
|
+
/**
|
|
967
|
+
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
968
|
+
* @param W window size
|
|
969
|
+
* @param precomputes precomputed tables
|
|
970
|
+
* @param n scalar (we don't check here, but should be less than curve order)
|
|
971
|
+
* @param acc accumulator point to add result of multiplication
|
|
972
|
+
* @returns point
|
|
973
|
+
*/
|
|
974
|
+
wNAFUnsafe(W, precomputes, n, acc = c.ZERO) {
|
|
975
|
+
const { windows, windowSize } = calcWOpts(W, bits);
|
|
976
|
+
const mask = BigInt(2 ** W - 1);
|
|
977
|
+
const maxNumber = 2 ** W;
|
|
978
|
+
const shiftBy = BigInt(W);
|
|
979
|
+
for (let window = 0; window < windows; window++) {
|
|
980
|
+
const offset = window * windowSize;
|
|
981
|
+
if (n === _0n$1)
|
|
982
|
+
break;
|
|
983
|
+
let wbits = Number(n & mask);
|
|
984
|
+
n >>= shiftBy;
|
|
985
|
+
if (wbits > windowSize) {
|
|
986
|
+
wbits -= maxNumber;
|
|
987
|
+
n += _1n$2;
|
|
988
|
+
}
|
|
989
|
+
if (wbits === 0)
|
|
990
|
+
continue;
|
|
991
|
+
let curr = precomputes[offset + Math.abs(wbits) - 1];
|
|
992
|
+
if (wbits < 0)
|
|
993
|
+
curr = curr.negate();
|
|
994
|
+
acc = acc.add(curr);
|
|
995
|
+
}
|
|
996
|
+
return acc;
|
|
997
|
+
},
|
|
998
|
+
getPrecomputes(W, P, transform) {
|
|
999
|
+
let comp = pointPrecomputes.get(P);
|
|
1000
|
+
if (!comp) {
|
|
1001
|
+
comp = this.precomputeWindow(P, W);
|
|
1002
|
+
if (W !== 1)
|
|
1003
|
+
pointPrecomputes.set(P, transform(comp));
|
|
1004
|
+
}
|
|
1005
|
+
return comp;
|
|
1006
|
+
},
|
|
1007
|
+
wNAFCached(P, n, transform) {
|
|
1008
|
+
const W = getW(P);
|
|
1009
|
+
return this.wNAF(W, this.getPrecomputes(W, P, transform), n);
|
|
1010
|
+
},
|
|
1011
|
+
wNAFCachedUnsafe(P, n, transform, prev) {
|
|
1012
|
+
const W = getW(P);
|
|
1013
|
+
if (W === 1)
|
|
1014
|
+
return this.unsafeLadder(P, n, prev);
|
|
1015
|
+
return this.wNAFUnsafe(W, this.getPrecomputes(W, P, transform), n, prev);
|
|
1016
|
+
},
|
|
1017
|
+
// We calculate precomputes for elliptic curve point multiplication
|
|
1018
|
+
// using windowed method. This specifies window size and
|
|
1019
|
+
// stores precomputed values. Usually only base point would be precomputed.
|
|
1020
|
+
setWindowSize(P, W) {
|
|
1021
|
+
validateW(W, bits);
|
|
1022
|
+
pointWindowSizes.set(P, W);
|
|
1023
|
+
pointPrecomputes.delete(P);
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
function pippenger(c, fieldN, points, scalars) {
|
|
1028
|
+
validateMSMPoints(points, c);
|
|
1029
|
+
validateMSMScalars(scalars, fieldN);
|
|
1030
|
+
if (points.length !== scalars.length)
|
|
1031
|
+
throw new Error("arrays of points and scalars must have equal length");
|
|
1032
|
+
const zero = c.ZERO;
|
|
1033
|
+
const wbits = bitLen(BigInt(points.length));
|
|
1034
|
+
const windowSize = wbits > 12 ? wbits - 3 : wbits > 4 ? wbits - 2 : wbits ? 2 : 1;
|
|
1035
|
+
const MASK = (1 << windowSize) - 1;
|
|
1036
|
+
const buckets = new Array(MASK + 1).fill(zero);
|
|
1037
|
+
const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
|
|
1038
|
+
let sum = zero;
|
|
1039
|
+
for (let i = lastBits; i >= 0; i -= windowSize) {
|
|
1040
|
+
buckets.fill(zero);
|
|
1041
|
+
for (let j = 0; j < scalars.length; j++) {
|
|
1042
|
+
const scalar = scalars[j];
|
|
1043
|
+
const wbits2 = Number(scalar >> BigInt(i) & BigInt(MASK));
|
|
1044
|
+
buckets[wbits2] = buckets[wbits2].add(points[j]);
|
|
1045
|
+
}
|
|
1046
|
+
let resI = zero;
|
|
1047
|
+
for (let j = buckets.length - 1, sumI = zero; j > 0; j--) {
|
|
1048
|
+
sumI = sumI.add(buckets[j]);
|
|
1049
|
+
resI = resI.add(sumI);
|
|
1050
|
+
}
|
|
1051
|
+
sum = sum.add(resI);
|
|
1052
|
+
if (i !== 0)
|
|
1053
|
+
for (let j = 0; j < windowSize; j++)
|
|
1054
|
+
sum = sum.double();
|
|
1055
|
+
}
|
|
1056
|
+
return sum;
|
|
1057
|
+
}
|
|
1058
|
+
function validateBasic(curve) {
|
|
1059
|
+
validateField(curve.Fp);
|
|
1060
|
+
validateObject(curve, {
|
|
1061
|
+
n: "bigint",
|
|
1062
|
+
h: "bigint",
|
|
1063
|
+
Gx: "field",
|
|
1064
|
+
Gy: "field"
|
|
1065
|
+
}, {
|
|
1066
|
+
nBitLength: "isSafeInteger",
|
|
1067
|
+
nByteLength: "isSafeInteger"
|
|
1068
|
+
});
|
|
1069
|
+
return Object.freeze({
|
|
1070
|
+
...nLength(curve.n, curve.nBitLength),
|
|
1071
|
+
...curve,
|
|
1072
|
+
...{ p: curve.Fp.ORDER }
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1076
|
+
function validateSigVerOpts(opts) {
|
|
1077
|
+
if (opts.lowS !== void 0)
|
|
1078
|
+
abool("lowS", opts.lowS);
|
|
1079
|
+
if (opts.prehash !== void 0)
|
|
1080
|
+
abool("prehash", opts.prehash);
|
|
1081
|
+
}
|
|
1082
|
+
function validatePointOpts(curve) {
|
|
1083
|
+
const opts = validateBasic(curve);
|
|
1084
|
+
validateObject(opts, {
|
|
1085
|
+
a: "field",
|
|
1086
|
+
b: "field"
|
|
1087
|
+
}, {
|
|
1088
|
+
allowedPrivateKeyLengths: "array",
|
|
1089
|
+
wrapPrivateKey: "boolean",
|
|
1090
|
+
isTorsionFree: "function",
|
|
1091
|
+
clearCofactor: "function",
|
|
1092
|
+
allowInfinityPoint: "boolean",
|
|
1093
|
+
fromBytes: "function",
|
|
1094
|
+
toBytes: "function"
|
|
1095
|
+
});
|
|
1096
|
+
const { endo, Fp, a } = opts;
|
|
1097
|
+
if (endo) {
|
|
1098
|
+
if (!Fp.eql(a, Fp.ZERO)) {
|
|
1099
|
+
throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");
|
|
1100
|
+
}
|
|
1101
|
+
if (typeof endo !== "object" || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
|
|
1102
|
+
throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function");
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
return Object.freeze({ ...opts });
|
|
1106
|
+
}
|
|
1107
|
+
const { bytesToNumberBE: b2n, hexToBytes: h2b } = ut;
|
|
1108
|
+
class DERErr extends Error {
|
|
1109
|
+
constructor(m = "") {
|
|
1110
|
+
super(m);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
const DER = {
|
|
1114
|
+
// asn.1 DER encoding utils
|
|
1115
|
+
Err: DERErr,
|
|
1116
|
+
// Basic building block is TLV (Tag-Length-Value)
|
|
1117
|
+
_tlv: {
|
|
1118
|
+
encode: (tag, data) => {
|
|
1119
|
+
const { Err: E } = DER;
|
|
1120
|
+
if (tag < 0 || tag > 256)
|
|
1121
|
+
throw new E("tlv.encode: wrong tag");
|
|
1122
|
+
if (data.length & 1)
|
|
1123
|
+
throw new E("tlv.encode: unpadded data");
|
|
1124
|
+
const dataLen = data.length / 2;
|
|
1125
|
+
const len = numberToHexUnpadded(dataLen);
|
|
1126
|
+
if (len.length / 2 & 128)
|
|
1127
|
+
throw new E("tlv.encode: long form length too big");
|
|
1128
|
+
const lenLen = dataLen > 127 ? numberToHexUnpadded(len.length / 2 | 128) : "";
|
|
1129
|
+
const t = numberToHexUnpadded(tag);
|
|
1130
|
+
return t + lenLen + len + data;
|
|
1131
|
+
},
|
|
1132
|
+
// v - value, l - left bytes (unparsed)
|
|
1133
|
+
decode(tag, data) {
|
|
1134
|
+
const { Err: E } = DER;
|
|
1135
|
+
let pos = 0;
|
|
1136
|
+
if (tag < 0 || tag > 256)
|
|
1137
|
+
throw new E("tlv.encode: wrong tag");
|
|
1138
|
+
if (data.length < 2 || data[pos++] !== tag)
|
|
1139
|
+
throw new E("tlv.decode: wrong tlv");
|
|
1140
|
+
const first = data[pos++];
|
|
1141
|
+
const isLong = !!(first & 128);
|
|
1142
|
+
let length = 0;
|
|
1143
|
+
if (!isLong)
|
|
1144
|
+
length = first;
|
|
1145
|
+
else {
|
|
1146
|
+
const lenLen = first & 127;
|
|
1147
|
+
if (!lenLen)
|
|
1148
|
+
throw new E("tlv.decode(long): indefinite length not supported");
|
|
1149
|
+
if (lenLen > 4)
|
|
1150
|
+
throw new E("tlv.decode(long): byte length is too big");
|
|
1151
|
+
const lengthBytes = data.subarray(pos, pos + lenLen);
|
|
1152
|
+
if (lengthBytes.length !== lenLen)
|
|
1153
|
+
throw new E("tlv.decode: length bytes not complete");
|
|
1154
|
+
if (lengthBytes[0] === 0)
|
|
1155
|
+
throw new E("tlv.decode(long): zero leftmost byte");
|
|
1156
|
+
for (const b of lengthBytes)
|
|
1157
|
+
length = length << 8 | b;
|
|
1158
|
+
pos += lenLen;
|
|
1159
|
+
if (length < 128)
|
|
1160
|
+
throw new E("tlv.decode(long): not minimal encoding");
|
|
1161
|
+
}
|
|
1162
|
+
const v = data.subarray(pos, pos + length);
|
|
1163
|
+
if (v.length !== length)
|
|
1164
|
+
throw new E("tlv.decode: wrong value length");
|
|
1165
|
+
return { v, l: data.subarray(pos + length) };
|
|
1166
|
+
}
|
|
1167
|
+
},
|
|
1168
|
+
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
1169
|
+
// since we always use positive integers here. It must always be empty:
|
|
1170
|
+
// - add zero byte if exists
|
|
1171
|
+
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
1172
|
+
_int: {
|
|
1173
|
+
encode(num) {
|
|
1174
|
+
const { Err: E } = DER;
|
|
1175
|
+
if (num < _0n)
|
|
1176
|
+
throw new E("integer: negative integers are not allowed");
|
|
1177
|
+
let hex = numberToHexUnpadded(num);
|
|
1178
|
+
if (Number.parseInt(hex[0], 16) & 8)
|
|
1179
|
+
hex = "00" + hex;
|
|
1180
|
+
if (hex.length & 1)
|
|
1181
|
+
throw new E("unexpected DER parsing assertion: unpadded hex");
|
|
1182
|
+
return hex;
|
|
1183
|
+
},
|
|
1184
|
+
decode(data) {
|
|
1185
|
+
const { Err: E } = DER;
|
|
1186
|
+
if (data[0] & 128)
|
|
1187
|
+
throw new E("invalid signature integer: negative");
|
|
1188
|
+
if (data[0] === 0 && !(data[1] & 128))
|
|
1189
|
+
throw new E("invalid signature integer: unnecessary leading zero");
|
|
1190
|
+
return b2n(data);
|
|
1191
|
+
}
|
|
1192
|
+
},
|
|
1193
|
+
toSig(hex) {
|
|
1194
|
+
const { Err: E, _int: int, _tlv: tlv } = DER;
|
|
1195
|
+
const data = typeof hex === "string" ? h2b(hex) : hex;
|
|
1196
|
+
abytes(data);
|
|
1197
|
+
const { v: seqBytes, l: seqLeftBytes } = tlv.decode(48, data);
|
|
1198
|
+
if (seqLeftBytes.length)
|
|
1199
|
+
throw new E("invalid signature: left bytes after parsing");
|
|
1200
|
+
const { v: rBytes, l: rLeftBytes } = tlv.decode(2, seqBytes);
|
|
1201
|
+
const { v: sBytes, l: sLeftBytes } = tlv.decode(2, rLeftBytes);
|
|
1202
|
+
if (sLeftBytes.length)
|
|
1203
|
+
throw new E("invalid signature: left bytes after parsing");
|
|
1204
|
+
return { r: int.decode(rBytes), s: int.decode(sBytes) };
|
|
1205
|
+
},
|
|
1206
|
+
hexFromSig(sig) {
|
|
1207
|
+
const { _tlv: tlv, _int: int } = DER;
|
|
1208
|
+
const rs = tlv.encode(2, int.encode(sig.r));
|
|
1209
|
+
const ss = tlv.encode(2, int.encode(sig.s));
|
|
1210
|
+
const seq = rs + ss;
|
|
1211
|
+
return tlv.encode(48, seq);
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
const _0n = BigInt(0), _1n$1 = BigInt(1);
|
|
1215
|
+
BigInt(2);
|
|
1216
|
+
const _3n = BigInt(3);
|
|
1217
|
+
BigInt(4);
|
|
1218
|
+
function weierstrassPoints(opts) {
|
|
1219
|
+
const CURVE = validatePointOpts(opts);
|
|
1220
|
+
const { Fp } = CURVE;
|
|
1221
|
+
const Fn = Field(CURVE.n, CURVE.nBitLength);
|
|
1222
|
+
const toBytes2 = CURVE.toBytes || ((_c, point, _isCompressed) => {
|
|
1223
|
+
const a = point.toAffine();
|
|
1224
|
+
return concatBytes(Uint8Array.from([4]), Fp.toBytes(a.x), Fp.toBytes(a.y));
|
|
1225
|
+
});
|
|
1226
|
+
const fromBytes = CURVE.fromBytes || ((bytes) => {
|
|
1227
|
+
const tail = bytes.subarray(1);
|
|
1228
|
+
const x = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
|
|
1229
|
+
const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
|
|
1230
|
+
return { x, y };
|
|
1231
|
+
});
|
|
1232
|
+
function weierstrassEquation(x) {
|
|
1233
|
+
const { a, b } = CURVE;
|
|
1234
|
+
const x2 = Fp.sqr(x);
|
|
1235
|
+
const x3 = Fp.mul(x2, x);
|
|
1236
|
+
return Fp.add(Fp.add(x3, Fp.mul(x, a)), b);
|
|
1237
|
+
}
|
|
1238
|
+
if (!Fp.eql(Fp.sqr(CURVE.Gy), weierstrassEquation(CURVE.Gx)))
|
|
1239
|
+
throw new Error("bad generator point: equation left != right");
|
|
1240
|
+
function isWithinCurveOrder(num) {
|
|
1241
|
+
return inRange(num, _1n$1, CURVE.n);
|
|
1242
|
+
}
|
|
1243
|
+
function normPrivateKeyToScalar(key) {
|
|
1244
|
+
const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n: N } = CURVE;
|
|
1245
|
+
if (lengths && typeof key !== "bigint") {
|
|
1246
|
+
if (isBytes(key))
|
|
1247
|
+
key = bytesToHex(key);
|
|
1248
|
+
if (typeof key !== "string" || !lengths.includes(key.length))
|
|
1249
|
+
throw new Error("invalid private key");
|
|
1250
|
+
key = key.padStart(nByteLength * 2, "0");
|
|
1251
|
+
}
|
|
1252
|
+
let num;
|
|
1253
|
+
try {
|
|
1254
|
+
num = typeof key === "bigint" ? key : bytesToNumberBE(ensureBytes("private key", key, nByteLength));
|
|
1255
|
+
} catch (error) {
|
|
1256
|
+
throw new Error("invalid private key, expected hex or " + nByteLength + " bytes, got " + typeof key);
|
|
1257
|
+
}
|
|
1258
|
+
if (wrapPrivateKey)
|
|
1259
|
+
num = mod(num, N);
|
|
1260
|
+
aInRange("private key", num, _1n$1, N);
|
|
1261
|
+
return num;
|
|
1262
|
+
}
|
|
1263
|
+
function assertPrjPoint(other) {
|
|
1264
|
+
if (!(other instanceof Point))
|
|
1265
|
+
throw new Error("ProjectivePoint expected");
|
|
1266
|
+
}
|
|
1267
|
+
const toAffineMemo = memoized((p, iz) => {
|
|
1268
|
+
const { px: x, py: y, pz: z } = p;
|
|
1269
|
+
if (Fp.eql(z, Fp.ONE))
|
|
1270
|
+
return { x, y };
|
|
1271
|
+
const is0 = p.is0();
|
|
1272
|
+
if (iz == null)
|
|
1273
|
+
iz = is0 ? Fp.ONE : Fp.inv(z);
|
|
1274
|
+
const ax = Fp.mul(x, iz);
|
|
1275
|
+
const ay = Fp.mul(y, iz);
|
|
1276
|
+
const zz = Fp.mul(z, iz);
|
|
1277
|
+
if (is0)
|
|
1278
|
+
return { x: Fp.ZERO, y: Fp.ZERO };
|
|
1279
|
+
if (!Fp.eql(zz, Fp.ONE))
|
|
1280
|
+
throw new Error("invZ was invalid");
|
|
1281
|
+
return { x: ax, y: ay };
|
|
1282
|
+
});
|
|
1283
|
+
const assertValidMemo = memoized((p) => {
|
|
1284
|
+
if (p.is0()) {
|
|
1285
|
+
if (CURVE.allowInfinityPoint && !Fp.is0(p.py))
|
|
1286
|
+
return;
|
|
1287
|
+
throw new Error("bad point: ZERO");
|
|
1288
|
+
}
|
|
1289
|
+
const { x, y } = p.toAffine();
|
|
1290
|
+
if (!Fp.isValid(x) || !Fp.isValid(y))
|
|
1291
|
+
throw new Error("bad point: x or y not FE");
|
|
1292
|
+
const left = Fp.sqr(y);
|
|
1293
|
+
const right = weierstrassEquation(x);
|
|
1294
|
+
if (!Fp.eql(left, right))
|
|
1295
|
+
throw new Error("bad point: equation left != right");
|
|
1296
|
+
if (!p.isTorsionFree())
|
|
1297
|
+
throw new Error("bad point: not in prime-order subgroup");
|
|
1298
|
+
return true;
|
|
1299
|
+
});
|
|
1300
|
+
class Point {
|
|
1301
|
+
constructor(px, py, pz) {
|
|
1302
|
+
this.px = px;
|
|
1303
|
+
this.py = py;
|
|
1304
|
+
this.pz = pz;
|
|
1305
|
+
if (px == null || !Fp.isValid(px))
|
|
1306
|
+
throw new Error("x required");
|
|
1307
|
+
if (py == null || !Fp.isValid(py))
|
|
1308
|
+
throw new Error("y required");
|
|
1309
|
+
if (pz == null || !Fp.isValid(pz))
|
|
1310
|
+
throw new Error("z required");
|
|
1311
|
+
Object.freeze(this);
|
|
1312
|
+
}
|
|
1313
|
+
// Does not validate if the point is on-curve.
|
|
1314
|
+
// Use fromHex instead, or call assertValidity() later.
|
|
1315
|
+
static fromAffine(p) {
|
|
1316
|
+
const { x, y } = p || {};
|
|
1317
|
+
if (!p || !Fp.isValid(x) || !Fp.isValid(y))
|
|
1318
|
+
throw new Error("invalid affine point");
|
|
1319
|
+
if (p instanceof Point)
|
|
1320
|
+
throw new Error("projective point not allowed");
|
|
1321
|
+
const is0 = (i) => Fp.eql(i, Fp.ZERO);
|
|
1322
|
+
if (is0(x) && is0(y))
|
|
1323
|
+
return Point.ZERO;
|
|
1324
|
+
return new Point(x, y, Fp.ONE);
|
|
1325
|
+
}
|
|
1326
|
+
get x() {
|
|
1327
|
+
return this.toAffine().x;
|
|
1328
|
+
}
|
|
1329
|
+
get y() {
|
|
1330
|
+
return this.toAffine().y;
|
|
1331
|
+
}
|
|
1332
|
+
/**
|
|
1333
|
+
* Takes a bunch of Projective Points but executes only one
|
|
1334
|
+
* inversion on all of them. Inversion is very slow operation,
|
|
1335
|
+
* so this improves performance massively.
|
|
1336
|
+
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
|
1337
|
+
*/
|
|
1338
|
+
static normalizeZ(points) {
|
|
1339
|
+
const toInv = Fp.invertBatch(points.map((p) => p.pz));
|
|
1340
|
+
return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* Converts hash string or Uint8Array to Point.
|
|
1344
|
+
* @param hex short/long ECDSA hex
|
|
1345
|
+
*/
|
|
1346
|
+
static fromHex(hex) {
|
|
1347
|
+
const P = Point.fromAffine(fromBytes(ensureBytes("pointHex", hex)));
|
|
1348
|
+
P.assertValidity();
|
|
1349
|
+
return P;
|
|
1350
|
+
}
|
|
1351
|
+
// Multiplies generator point by privateKey.
|
|
1352
|
+
static fromPrivateKey(privateKey) {
|
|
1353
|
+
return Point.BASE.multiply(normPrivateKeyToScalar(privateKey));
|
|
1354
|
+
}
|
|
1355
|
+
// Multiscalar Multiplication
|
|
1356
|
+
static msm(points, scalars) {
|
|
1357
|
+
return pippenger(Point, Fn, points, scalars);
|
|
1358
|
+
}
|
|
1359
|
+
// "Private method", don't use it directly
|
|
1360
|
+
_setWindowSize(windowSize) {
|
|
1361
|
+
wnaf.setWindowSize(this, windowSize);
|
|
1362
|
+
}
|
|
1363
|
+
// A point on curve is valid if it conforms to equation.
|
|
1364
|
+
assertValidity() {
|
|
1365
|
+
assertValidMemo(this);
|
|
1366
|
+
}
|
|
1367
|
+
hasEvenY() {
|
|
1368
|
+
const { y } = this.toAffine();
|
|
1369
|
+
if (Fp.isOdd)
|
|
1370
|
+
return !Fp.isOdd(y);
|
|
1371
|
+
throw new Error("Field doesn't support isOdd");
|
|
1372
|
+
}
|
|
1373
|
+
/**
|
|
1374
|
+
* Compare one point to another.
|
|
1375
|
+
*/
|
|
1376
|
+
equals(other) {
|
|
1377
|
+
assertPrjPoint(other);
|
|
1378
|
+
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
1379
|
+
const { px: X2, py: Y2, pz: Z2 } = other;
|
|
1380
|
+
const U1 = Fp.eql(Fp.mul(X1, Z2), Fp.mul(X2, Z1));
|
|
1381
|
+
const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
|
|
1382
|
+
return U1 && U2;
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Flips point to one corresponding to (x, -y) in Affine coordinates.
|
|
1386
|
+
*/
|
|
1387
|
+
negate() {
|
|
1388
|
+
return new Point(this.px, Fp.neg(this.py), this.pz);
|
|
1389
|
+
}
|
|
1390
|
+
// Renes-Costello-Batina exception-free doubling formula.
|
|
1391
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
1392
|
+
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
1393
|
+
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
1394
|
+
double() {
|
|
1395
|
+
const { a, b } = CURVE;
|
|
1396
|
+
const b3 = Fp.mul(b, _3n);
|
|
1397
|
+
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
1398
|
+
let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
|
|
1399
|
+
let t0 = Fp.mul(X1, X1);
|
|
1400
|
+
let t1 = Fp.mul(Y1, Y1);
|
|
1401
|
+
let t2 = Fp.mul(Z1, Z1);
|
|
1402
|
+
let t3 = Fp.mul(X1, Y1);
|
|
1403
|
+
t3 = Fp.add(t3, t3);
|
|
1404
|
+
Z3 = Fp.mul(X1, Z1);
|
|
1405
|
+
Z3 = Fp.add(Z3, Z3);
|
|
1406
|
+
X3 = Fp.mul(a, Z3);
|
|
1407
|
+
Y3 = Fp.mul(b3, t2);
|
|
1408
|
+
Y3 = Fp.add(X3, Y3);
|
|
1409
|
+
X3 = Fp.sub(t1, Y3);
|
|
1410
|
+
Y3 = Fp.add(t1, Y3);
|
|
1411
|
+
Y3 = Fp.mul(X3, Y3);
|
|
1412
|
+
X3 = Fp.mul(t3, X3);
|
|
1413
|
+
Z3 = Fp.mul(b3, Z3);
|
|
1414
|
+
t2 = Fp.mul(a, t2);
|
|
1415
|
+
t3 = Fp.sub(t0, t2);
|
|
1416
|
+
t3 = Fp.mul(a, t3);
|
|
1417
|
+
t3 = Fp.add(t3, Z3);
|
|
1418
|
+
Z3 = Fp.add(t0, t0);
|
|
1419
|
+
t0 = Fp.add(Z3, t0);
|
|
1420
|
+
t0 = Fp.add(t0, t2);
|
|
1421
|
+
t0 = Fp.mul(t0, t3);
|
|
1422
|
+
Y3 = Fp.add(Y3, t0);
|
|
1423
|
+
t2 = Fp.mul(Y1, Z1);
|
|
1424
|
+
t2 = Fp.add(t2, t2);
|
|
1425
|
+
t0 = Fp.mul(t2, t3);
|
|
1426
|
+
X3 = Fp.sub(X3, t0);
|
|
1427
|
+
Z3 = Fp.mul(t2, t1);
|
|
1428
|
+
Z3 = Fp.add(Z3, Z3);
|
|
1429
|
+
Z3 = Fp.add(Z3, Z3);
|
|
1430
|
+
return new Point(X3, Y3, Z3);
|
|
1431
|
+
}
|
|
1432
|
+
// Renes-Costello-Batina exception-free addition formula.
|
|
1433
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
1434
|
+
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
1435
|
+
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
1436
|
+
add(other) {
|
|
1437
|
+
assertPrjPoint(other);
|
|
1438
|
+
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
1439
|
+
const { px: X2, py: Y2, pz: Z2 } = other;
|
|
1440
|
+
let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
|
|
1441
|
+
const a = CURVE.a;
|
|
1442
|
+
const b3 = Fp.mul(CURVE.b, _3n);
|
|
1443
|
+
let t0 = Fp.mul(X1, X2);
|
|
1444
|
+
let t1 = Fp.mul(Y1, Y2);
|
|
1445
|
+
let t2 = Fp.mul(Z1, Z2);
|
|
1446
|
+
let t3 = Fp.add(X1, Y1);
|
|
1447
|
+
let t4 = Fp.add(X2, Y2);
|
|
1448
|
+
t3 = Fp.mul(t3, t4);
|
|
1449
|
+
t4 = Fp.add(t0, t1);
|
|
1450
|
+
t3 = Fp.sub(t3, t4);
|
|
1451
|
+
t4 = Fp.add(X1, Z1);
|
|
1452
|
+
let t5 = Fp.add(X2, Z2);
|
|
1453
|
+
t4 = Fp.mul(t4, t5);
|
|
1454
|
+
t5 = Fp.add(t0, t2);
|
|
1455
|
+
t4 = Fp.sub(t4, t5);
|
|
1456
|
+
t5 = Fp.add(Y1, Z1);
|
|
1457
|
+
X3 = Fp.add(Y2, Z2);
|
|
1458
|
+
t5 = Fp.mul(t5, X3);
|
|
1459
|
+
X3 = Fp.add(t1, t2);
|
|
1460
|
+
t5 = Fp.sub(t5, X3);
|
|
1461
|
+
Z3 = Fp.mul(a, t4);
|
|
1462
|
+
X3 = Fp.mul(b3, t2);
|
|
1463
|
+
Z3 = Fp.add(X3, Z3);
|
|
1464
|
+
X3 = Fp.sub(t1, Z3);
|
|
1465
|
+
Z3 = Fp.add(t1, Z3);
|
|
1466
|
+
Y3 = Fp.mul(X3, Z3);
|
|
1467
|
+
t1 = Fp.add(t0, t0);
|
|
1468
|
+
t1 = Fp.add(t1, t0);
|
|
1469
|
+
t2 = Fp.mul(a, t2);
|
|
1470
|
+
t4 = Fp.mul(b3, t4);
|
|
1471
|
+
t1 = Fp.add(t1, t2);
|
|
1472
|
+
t2 = Fp.sub(t0, t2);
|
|
1473
|
+
t2 = Fp.mul(a, t2);
|
|
1474
|
+
t4 = Fp.add(t4, t2);
|
|
1475
|
+
t0 = Fp.mul(t1, t4);
|
|
1476
|
+
Y3 = Fp.add(Y3, t0);
|
|
1477
|
+
t0 = Fp.mul(t5, t4);
|
|
1478
|
+
X3 = Fp.mul(t3, X3);
|
|
1479
|
+
X3 = Fp.sub(X3, t0);
|
|
1480
|
+
t0 = Fp.mul(t3, t1);
|
|
1481
|
+
Z3 = Fp.mul(t5, Z3);
|
|
1482
|
+
Z3 = Fp.add(Z3, t0);
|
|
1483
|
+
return new Point(X3, Y3, Z3);
|
|
1484
|
+
}
|
|
1485
|
+
subtract(other) {
|
|
1486
|
+
return this.add(other.negate());
|
|
1487
|
+
}
|
|
1488
|
+
is0() {
|
|
1489
|
+
return this.equals(Point.ZERO);
|
|
1490
|
+
}
|
|
1491
|
+
wNAF(n) {
|
|
1492
|
+
return wnaf.wNAFCached(this, n, Point.normalizeZ);
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
1496
|
+
* It's faster, but should only be used when you don't care about
|
|
1497
|
+
* an exposed private key e.g. sig verification, which works over *public* keys.
|
|
1498
|
+
*/
|
|
1499
|
+
multiplyUnsafe(sc) {
|
|
1500
|
+
const { endo, n: N } = CURVE;
|
|
1501
|
+
aInRange("scalar", sc, _0n, N);
|
|
1502
|
+
const I = Point.ZERO;
|
|
1503
|
+
if (sc === _0n)
|
|
1504
|
+
return I;
|
|
1505
|
+
if (this.is0() || sc === _1n$1)
|
|
1506
|
+
return this;
|
|
1507
|
+
if (!endo || wnaf.hasPrecomputes(this))
|
|
1508
|
+
return wnaf.wNAFCachedUnsafe(this, sc, Point.normalizeZ);
|
|
1509
|
+
let { k1neg, k1, k2neg, k2 } = endo.splitScalar(sc);
|
|
1510
|
+
let k1p = I;
|
|
1511
|
+
let k2p = I;
|
|
1512
|
+
let d = this;
|
|
1513
|
+
while (k1 > _0n || k2 > _0n) {
|
|
1514
|
+
if (k1 & _1n$1)
|
|
1515
|
+
k1p = k1p.add(d);
|
|
1516
|
+
if (k2 & _1n$1)
|
|
1517
|
+
k2p = k2p.add(d);
|
|
1518
|
+
d = d.double();
|
|
1519
|
+
k1 >>= _1n$1;
|
|
1520
|
+
k2 >>= _1n$1;
|
|
1521
|
+
}
|
|
1522
|
+
if (k1neg)
|
|
1523
|
+
k1p = k1p.negate();
|
|
1524
|
+
if (k2neg)
|
|
1525
|
+
k2p = k2p.negate();
|
|
1526
|
+
k2p = new Point(Fp.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
|
|
1527
|
+
return k1p.add(k2p);
|
|
1528
|
+
}
|
|
1529
|
+
/**
|
|
1530
|
+
* Constant time multiplication.
|
|
1531
|
+
* Uses wNAF method. Windowed method may be 10% faster,
|
|
1532
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
|
1533
|
+
* Uses precomputes when available.
|
|
1534
|
+
* Uses endomorphism for Koblitz curves.
|
|
1535
|
+
* @param scalar by which the point would be multiplied
|
|
1536
|
+
* @returns New point
|
|
1537
|
+
*/
|
|
1538
|
+
multiply(scalar) {
|
|
1539
|
+
const { endo, n: N } = CURVE;
|
|
1540
|
+
aInRange("scalar", scalar, _1n$1, N);
|
|
1541
|
+
let point, fake;
|
|
1542
|
+
if (endo) {
|
|
1543
|
+
const { k1neg, k1, k2neg, k2 } = endo.splitScalar(scalar);
|
|
1544
|
+
let { p: k1p, f: f1p } = this.wNAF(k1);
|
|
1545
|
+
let { p: k2p, f: f2p } = this.wNAF(k2);
|
|
1546
|
+
k1p = wnaf.constTimeNegate(k1neg, k1p);
|
|
1547
|
+
k2p = wnaf.constTimeNegate(k2neg, k2p);
|
|
1548
|
+
k2p = new Point(Fp.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
|
|
1549
|
+
point = k1p.add(k2p);
|
|
1550
|
+
fake = f1p.add(f2p);
|
|
1551
|
+
} else {
|
|
1552
|
+
const { p, f } = this.wNAF(scalar);
|
|
1553
|
+
point = p;
|
|
1554
|
+
fake = f;
|
|
1555
|
+
}
|
|
1556
|
+
return Point.normalizeZ([point, fake])[0];
|
|
1557
|
+
}
|
|
1558
|
+
/**
|
|
1559
|
+
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
1560
|
+
* Not using Strauss-Shamir trick: precomputation tables are faster.
|
|
1561
|
+
* The trick could be useful if both P and Q are not G (not in our case).
|
|
1562
|
+
* @returns non-zero affine point
|
|
1563
|
+
*/
|
|
1564
|
+
multiplyAndAddUnsafe(Q, a, b) {
|
|
1565
|
+
const G = Point.BASE;
|
|
1566
|
+
const mul = (P, a2) => a2 === _0n || a2 === _1n$1 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
|
|
1567
|
+
const sum = mul(this, a).add(mul(Q, b));
|
|
1568
|
+
return sum.is0() ? void 0 : sum;
|
|
1569
|
+
}
|
|
1570
|
+
// Converts Projective point to affine (x, y) coordinates.
|
|
1571
|
+
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
1572
|
+
// (x, y, z) ∋ (x=x/z, y=y/z)
|
|
1573
|
+
toAffine(iz) {
|
|
1574
|
+
return toAffineMemo(this, iz);
|
|
1575
|
+
}
|
|
1576
|
+
isTorsionFree() {
|
|
1577
|
+
const { h: cofactor, isTorsionFree } = CURVE;
|
|
1578
|
+
if (cofactor === _1n$1)
|
|
1579
|
+
return true;
|
|
1580
|
+
if (isTorsionFree)
|
|
1581
|
+
return isTorsionFree(Point, this);
|
|
1582
|
+
throw new Error("isTorsionFree() has not been declared for the elliptic curve");
|
|
1583
|
+
}
|
|
1584
|
+
clearCofactor() {
|
|
1585
|
+
const { h: cofactor, clearCofactor } = CURVE;
|
|
1586
|
+
if (cofactor === _1n$1)
|
|
1587
|
+
return this;
|
|
1588
|
+
if (clearCofactor)
|
|
1589
|
+
return clearCofactor(Point, this);
|
|
1590
|
+
return this.multiplyUnsafe(CURVE.h);
|
|
1591
|
+
}
|
|
1592
|
+
toRawBytes(isCompressed = true) {
|
|
1593
|
+
abool("isCompressed", isCompressed);
|
|
1594
|
+
this.assertValidity();
|
|
1595
|
+
return toBytes2(Point, this, isCompressed);
|
|
1596
|
+
}
|
|
1597
|
+
toHex(isCompressed = true) {
|
|
1598
|
+
abool("isCompressed", isCompressed);
|
|
1599
|
+
return bytesToHex(this.toRawBytes(isCompressed));
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
Point.BASE = new Point(CURVE.Gx, CURVE.Gy, Fp.ONE);
|
|
1603
|
+
Point.ZERO = new Point(Fp.ZERO, Fp.ONE, Fp.ZERO);
|
|
1604
|
+
const _bits = CURVE.nBitLength;
|
|
1605
|
+
const wnaf = wNAF(Point, CURVE.endo ? Math.ceil(_bits / 2) : _bits);
|
|
1606
|
+
return {
|
|
1607
|
+
CURVE,
|
|
1608
|
+
ProjectivePoint: Point,
|
|
1609
|
+
normPrivateKeyToScalar,
|
|
1610
|
+
weierstrassEquation,
|
|
1611
|
+
isWithinCurveOrder
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
function validateOpts(curve) {
|
|
1615
|
+
const opts = validateBasic(curve);
|
|
1616
|
+
validateObject(opts, {
|
|
1617
|
+
hash: "hash",
|
|
1618
|
+
hmac: "function",
|
|
1619
|
+
randomBytes: "function"
|
|
1620
|
+
}, {
|
|
1621
|
+
bits2int: "function",
|
|
1622
|
+
bits2int_modN: "function",
|
|
1623
|
+
lowS: "boolean"
|
|
1624
|
+
});
|
|
1625
|
+
return Object.freeze({ lowS: true, ...opts });
|
|
1626
|
+
}
|
|
1627
|
+
function weierstrass(curveDef) {
|
|
1628
|
+
const CURVE = validateOpts(curveDef);
|
|
1629
|
+
const { Fp, n: CURVE_ORDER } = CURVE;
|
|
1630
|
+
const compressedLen = Fp.BYTES + 1;
|
|
1631
|
+
const uncompressedLen = 2 * Fp.BYTES + 1;
|
|
1632
|
+
function modN(a) {
|
|
1633
|
+
return mod(a, CURVE_ORDER);
|
|
1634
|
+
}
|
|
1635
|
+
function invN(a) {
|
|
1636
|
+
return invert(a, CURVE_ORDER);
|
|
1637
|
+
}
|
|
1638
|
+
const { ProjectivePoint: Point, normPrivateKeyToScalar, weierstrassEquation, isWithinCurveOrder } = weierstrassPoints({
|
|
1639
|
+
...CURVE,
|
|
1640
|
+
toBytes(_c, point, isCompressed) {
|
|
1641
|
+
const a = point.toAffine();
|
|
1642
|
+
const x = Fp.toBytes(a.x);
|
|
1643
|
+
const cat = concatBytes;
|
|
1644
|
+
abool("isCompressed", isCompressed);
|
|
1645
|
+
if (isCompressed) {
|
|
1646
|
+
return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x);
|
|
1647
|
+
} else {
|
|
1648
|
+
return cat(Uint8Array.from([4]), x, Fp.toBytes(a.y));
|
|
1649
|
+
}
|
|
1650
|
+
},
|
|
1651
|
+
fromBytes(bytes) {
|
|
1652
|
+
const len = bytes.length;
|
|
1653
|
+
const head = bytes[0];
|
|
1654
|
+
const tail = bytes.subarray(1);
|
|
1655
|
+
if (len === compressedLen && (head === 2 || head === 3)) {
|
|
1656
|
+
const x = bytesToNumberBE(tail);
|
|
1657
|
+
if (!inRange(x, _1n$1, Fp.ORDER))
|
|
1658
|
+
throw new Error("Point is not on curve");
|
|
1659
|
+
const y2 = weierstrassEquation(x);
|
|
1660
|
+
let y;
|
|
1661
|
+
try {
|
|
1662
|
+
y = Fp.sqrt(y2);
|
|
1663
|
+
} catch (sqrtError) {
|
|
1664
|
+
const suffix = sqrtError instanceof Error ? ": " + sqrtError.message : "";
|
|
1665
|
+
throw new Error("Point is not on curve" + suffix);
|
|
1666
|
+
}
|
|
1667
|
+
const isYOdd = (y & _1n$1) === _1n$1;
|
|
1668
|
+
const isHeadOdd = (head & 1) === 1;
|
|
1669
|
+
if (isHeadOdd !== isYOdd)
|
|
1670
|
+
y = Fp.neg(y);
|
|
1671
|
+
return { x, y };
|
|
1672
|
+
} else if (len === uncompressedLen && head === 4) {
|
|
1673
|
+
const x = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
|
|
1674
|
+
const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
|
|
1675
|
+
return { x, y };
|
|
1676
|
+
} else {
|
|
1677
|
+
const cl = compressedLen;
|
|
1678
|
+
const ul = uncompressedLen;
|
|
1679
|
+
throw new Error("invalid Point, expected length of " + cl + ", or uncompressed " + ul + ", got " + len);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
});
|
|
1683
|
+
const numToNByteStr = (num) => bytesToHex(numberToBytesBE(num, CURVE.nByteLength));
|
|
1684
|
+
function isBiggerThanHalfOrder(number) {
|
|
1685
|
+
const HALF = CURVE_ORDER >> _1n$1;
|
|
1686
|
+
return number > HALF;
|
|
1687
|
+
}
|
|
1688
|
+
function normalizeS(s) {
|
|
1689
|
+
return isBiggerThanHalfOrder(s) ? modN(-s) : s;
|
|
1690
|
+
}
|
|
1691
|
+
const slcNum = (b, from, to) => bytesToNumberBE(b.slice(from, to));
|
|
1692
|
+
class Signature {
|
|
1693
|
+
constructor(r, s, recovery) {
|
|
1694
|
+
this.r = r;
|
|
1695
|
+
this.s = s;
|
|
1696
|
+
this.recovery = recovery;
|
|
1697
|
+
this.assertValidity();
|
|
1698
|
+
}
|
|
1699
|
+
// pair (bytes of r, bytes of s)
|
|
1700
|
+
static fromCompact(hex) {
|
|
1701
|
+
const l = CURVE.nByteLength;
|
|
1702
|
+
hex = ensureBytes("compactSignature", hex, l * 2);
|
|
1703
|
+
return new Signature(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
|
|
1704
|
+
}
|
|
1705
|
+
// DER encoded ECDSA signature
|
|
1706
|
+
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
1707
|
+
static fromDER(hex) {
|
|
1708
|
+
const { r, s } = DER.toSig(ensureBytes("DER", hex));
|
|
1709
|
+
return new Signature(r, s);
|
|
1710
|
+
}
|
|
1711
|
+
assertValidity() {
|
|
1712
|
+
aInRange("r", this.r, _1n$1, CURVE_ORDER);
|
|
1713
|
+
aInRange("s", this.s, _1n$1, CURVE_ORDER);
|
|
1714
|
+
}
|
|
1715
|
+
addRecoveryBit(recovery) {
|
|
1716
|
+
return new Signature(this.r, this.s, recovery);
|
|
1717
|
+
}
|
|
1718
|
+
recoverPublicKey(msgHash) {
|
|
1719
|
+
const { r, s, recovery: rec } = this;
|
|
1720
|
+
const h = bits2int_modN(ensureBytes("msgHash", msgHash));
|
|
1721
|
+
if (rec == null || ![0, 1, 2, 3].includes(rec))
|
|
1722
|
+
throw new Error("recovery id invalid");
|
|
1723
|
+
const radj = rec === 2 || rec === 3 ? r + CURVE.n : r;
|
|
1724
|
+
if (radj >= Fp.ORDER)
|
|
1725
|
+
throw new Error("recovery id 2 or 3 invalid");
|
|
1726
|
+
const prefix = (rec & 1) === 0 ? "02" : "03";
|
|
1727
|
+
const R = Point.fromHex(prefix + numToNByteStr(radj));
|
|
1728
|
+
const ir = invN(radj);
|
|
1729
|
+
const u1 = modN(-h * ir);
|
|
1730
|
+
const u2 = modN(s * ir);
|
|
1731
|
+
const Q = Point.BASE.multiplyAndAddUnsafe(R, u1, u2);
|
|
1732
|
+
if (!Q)
|
|
1733
|
+
throw new Error("point at infinify");
|
|
1734
|
+
Q.assertValidity();
|
|
1735
|
+
return Q;
|
|
1736
|
+
}
|
|
1737
|
+
// Signatures should be low-s, to prevent malleability.
|
|
1738
|
+
hasHighS() {
|
|
1739
|
+
return isBiggerThanHalfOrder(this.s);
|
|
1740
|
+
}
|
|
1741
|
+
normalizeS() {
|
|
1742
|
+
return this.hasHighS() ? new Signature(this.r, modN(-this.s), this.recovery) : this;
|
|
1743
|
+
}
|
|
1744
|
+
// DER-encoded
|
|
1745
|
+
toDERRawBytes() {
|
|
1746
|
+
return hexToBytes(this.toDERHex());
|
|
1747
|
+
}
|
|
1748
|
+
toDERHex() {
|
|
1749
|
+
return DER.hexFromSig({ r: this.r, s: this.s });
|
|
1750
|
+
}
|
|
1751
|
+
// padded bytes of r, then padded bytes of s
|
|
1752
|
+
toCompactRawBytes() {
|
|
1753
|
+
return hexToBytes(this.toCompactHex());
|
|
1754
|
+
}
|
|
1755
|
+
toCompactHex() {
|
|
1756
|
+
return numToNByteStr(this.r) + numToNByteStr(this.s);
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
const utils = {
|
|
1760
|
+
isValidPrivateKey(privateKey) {
|
|
1761
|
+
try {
|
|
1762
|
+
normPrivateKeyToScalar(privateKey);
|
|
1763
|
+
return true;
|
|
1764
|
+
} catch (error) {
|
|
1765
|
+
return false;
|
|
1766
|
+
}
|
|
1767
|
+
},
|
|
1768
|
+
normPrivateKeyToScalar,
|
|
1769
|
+
/**
|
|
1770
|
+
* Produces cryptographically secure private key from random of size
|
|
1771
|
+
* (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
|
|
1772
|
+
*/
|
|
1773
|
+
randomPrivateKey: () => {
|
|
1774
|
+
const length = getMinHashLength(CURVE.n);
|
|
1775
|
+
return mapHashToField(CURVE.randomBytes(length), CURVE.n);
|
|
1776
|
+
},
|
|
1777
|
+
/**
|
|
1778
|
+
* Creates precompute table for an arbitrary EC point. Makes point "cached".
|
|
1779
|
+
* Allows to massively speed-up `point.multiply(scalar)`.
|
|
1780
|
+
* @returns cached point
|
|
1781
|
+
* @example
|
|
1782
|
+
* const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
|
|
1783
|
+
* fast.multiply(privKey); // much faster ECDH now
|
|
1784
|
+
*/
|
|
1785
|
+
precompute(windowSize = 8, point = Point.BASE) {
|
|
1786
|
+
point._setWindowSize(windowSize);
|
|
1787
|
+
point.multiply(BigInt(3));
|
|
1788
|
+
return point;
|
|
1789
|
+
}
|
|
1790
|
+
};
|
|
1791
|
+
function getPublicKey(privateKey, isCompressed = true) {
|
|
1792
|
+
return Point.fromPrivateKey(privateKey).toRawBytes(isCompressed);
|
|
1793
|
+
}
|
|
1794
|
+
function isProbPub(item) {
|
|
1795
|
+
const arr = isBytes(item);
|
|
1796
|
+
const str = typeof item === "string";
|
|
1797
|
+
const len = (arr || str) && item.length;
|
|
1798
|
+
if (arr)
|
|
1799
|
+
return len === compressedLen || len === uncompressedLen;
|
|
1800
|
+
if (str)
|
|
1801
|
+
return len === 2 * compressedLen || len === 2 * uncompressedLen;
|
|
1802
|
+
if (item instanceof Point)
|
|
1803
|
+
return true;
|
|
1804
|
+
return false;
|
|
1805
|
+
}
|
|
1806
|
+
function getSharedSecret(privateA, publicB, isCompressed = true) {
|
|
1807
|
+
if (isProbPub(privateA))
|
|
1808
|
+
throw new Error("first arg must be private key");
|
|
1809
|
+
if (!isProbPub(publicB))
|
|
1810
|
+
throw new Error("second arg must be public key");
|
|
1811
|
+
const b = Point.fromHex(publicB);
|
|
1812
|
+
return b.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
|
|
1813
|
+
}
|
|
1814
|
+
const bits2int = CURVE.bits2int || function(bytes) {
|
|
1815
|
+
if (bytes.length > 8192)
|
|
1816
|
+
throw new Error("input is too large");
|
|
1817
|
+
const num = bytesToNumberBE(bytes);
|
|
1818
|
+
const delta = bytes.length * 8 - CURVE.nBitLength;
|
|
1819
|
+
return delta > 0 ? num >> BigInt(delta) : num;
|
|
1820
|
+
};
|
|
1821
|
+
const bits2int_modN = CURVE.bits2int_modN || function(bytes) {
|
|
1822
|
+
return modN(bits2int(bytes));
|
|
1823
|
+
};
|
|
1824
|
+
const ORDER_MASK = bitMask(CURVE.nBitLength);
|
|
1825
|
+
function int2octets(num) {
|
|
1826
|
+
aInRange("num < 2^" + CURVE.nBitLength, num, _0n, ORDER_MASK);
|
|
1827
|
+
return numberToBytesBE(num, CURVE.nByteLength);
|
|
1828
|
+
}
|
|
1829
|
+
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
1830
|
+
if (["recovered", "canonical"].some((k) => k in opts))
|
|
1831
|
+
throw new Error("sign() legacy options not supported");
|
|
1832
|
+
const { hash, randomBytes: randomBytes2 } = CURVE;
|
|
1833
|
+
let { lowS, prehash, extraEntropy: ent } = opts;
|
|
1834
|
+
if (lowS == null)
|
|
1835
|
+
lowS = true;
|
|
1836
|
+
msgHash = ensureBytes("msgHash", msgHash);
|
|
1837
|
+
validateSigVerOpts(opts);
|
|
1838
|
+
if (prehash)
|
|
1839
|
+
msgHash = ensureBytes("prehashed msgHash", hash(msgHash));
|
|
1840
|
+
const h1int = bits2int_modN(msgHash);
|
|
1841
|
+
const d = normPrivateKeyToScalar(privateKey);
|
|
1842
|
+
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
1843
|
+
if (ent != null && ent !== false) {
|
|
1844
|
+
const e = ent === true ? randomBytes2(Fp.BYTES) : ent;
|
|
1845
|
+
seedArgs.push(ensureBytes("extraEntropy", e));
|
|
1846
|
+
}
|
|
1847
|
+
const seed = concatBytes(...seedArgs);
|
|
1848
|
+
const m = h1int;
|
|
1849
|
+
function k2sig(kBytes) {
|
|
1850
|
+
const k = bits2int(kBytes);
|
|
1851
|
+
if (!isWithinCurveOrder(k))
|
|
1852
|
+
return;
|
|
1853
|
+
const ik = invN(k);
|
|
1854
|
+
const q = Point.BASE.multiply(k).toAffine();
|
|
1855
|
+
const r = modN(q.x);
|
|
1856
|
+
if (r === _0n)
|
|
1857
|
+
return;
|
|
1858
|
+
const s = modN(ik * modN(m + r * d));
|
|
1859
|
+
if (s === _0n)
|
|
1860
|
+
return;
|
|
1861
|
+
let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n$1);
|
|
1862
|
+
let normS = s;
|
|
1863
|
+
if (lowS && isBiggerThanHalfOrder(s)) {
|
|
1864
|
+
normS = normalizeS(s);
|
|
1865
|
+
recovery ^= 1;
|
|
1866
|
+
}
|
|
1867
|
+
return new Signature(r, normS, recovery);
|
|
1868
|
+
}
|
|
1869
|
+
return { seed, k2sig };
|
|
1870
|
+
}
|
|
1871
|
+
const defaultSigOpts = { lowS: CURVE.lowS, prehash: false };
|
|
1872
|
+
const defaultVerOpts = { lowS: CURVE.lowS, prehash: false };
|
|
1873
|
+
function sign(msgHash, privKey, opts = defaultSigOpts) {
|
|
1874
|
+
const { seed, k2sig } = prepSig(msgHash, privKey, opts);
|
|
1875
|
+
const C = CURVE;
|
|
1876
|
+
const drbg = createHmacDrbg(C.hash.outputLen, C.nByteLength, C.hmac);
|
|
1877
|
+
return drbg(seed, k2sig);
|
|
1878
|
+
}
|
|
1879
|
+
Point.BASE._setWindowSize(8);
|
|
1880
|
+
function verify(signature, msgHash, publicKey, opts = defaultVerOpts) {
|
|
1881
|
+
var _a;
|
|
1882
|
+
const sg = signature;
|
|
1883
|
+
msgHash = ensureBytes("msgHash", msgHash);
|
|
1884
|
+
publicKey = ensureBytes("publicKey", publicKey);
|
|
1885
|
+
const { lowS, prehash, format } = opts;
|
|
1886
|
+
validateSigVerOpts(opts);
|
|
1887
|
+
if ("strict" in opts)
|
|
1888
|
+
throw new Error("options.strict was renamed to lowS");
|
|
1889
|
+
if (format !== void 0 && format !== "compact" && format !== "der")
|
|
1890
|
+
throw new Error("format must be compact or der");
|
|
1891
|
+
const isHex = typeof sg === "string" || isBytes(sg);
|
|
1892
|
+
const isObj = !isHex && !format && typeof sg === "object" && sg !== null && typeof sg.r === "bigint" && typeof sg.s === "bigint";
|
|
1893
|
+
if (!isHex && !isObj)
|
|
1894
|
+
throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
1895
|
+
let _sig = void 0;
|
|
1896
|
+
let P;
|
|
1897
|
+
try {
|
|
1898
|
+
if (isObj)
|
|
1899
|
+
_sig = new Signature(sg.r, sg.s);
|
|
1900
|
+
if (isHex) {
|
|
1901
|
+
try {
|
|
1902
|
+
if (format !== "compact")
|
|
1903
|
+
_sig = Signature.fromDER(sg);
|
|
1904
|
+
} catch (derError) {
|
|
1905
|
+
if (!(derError instanceof DER.Err))
|
|
1906
|
+
throw derError;
|
|
1907
|
+
}
|
|
1908
|
+
if (!_sig && format !== "der")
|
|
1909
|
+
_sig = Signature.fromCompact(sg);
|
|
1910
|
+
}
|
|
1911
|
+
P = Point.fromHex(publicKey);
|
|
1912
|
+
} catch (error) {
|
|
1913
|
+
return false;
|
|
1914
|
+
}
|
|
1915
|
+
if (!_sig)
|
|
1916
|
+
return false;
|
|
1917
|
+
if (lowS && _sig.hasHighS())
|
|
1918
|
+
return false;
|
|
1919
|
+
if (prehash)
|
|
1920
|
+
msgHash = CURVE.hash(msgHash);
|
|
1921
|
+
const { r, s } = _sig;
|
|
1922
|
+
const h = bits2int_modN(msgHash);
|
|
1923
|
+
const is = invN(s);
|
|
1924
|
+
const u1 = modN(h * is);
|
|
1925
|
+
const u2 = modN(r * is);
|
|
1926
|
+
const R = (_a = Point.BASE.multiplyAndAddUnsafe(P, u1, u2)) == null ? void 0 : _a.toAffine();
|
|
1927
|
+
if (!R)
|
|
1928
|
+
return false;
|
|
1929
|
+
const v = modN(R.x);
|
|
1930
|
+
return v === r;
|
|
1931
|
+
}
|
|
1932
|
+
return {
|
|
1933
|
+
CURVE,
|
|
1934
|
+
getPublicKey,
|
|
1935
|
+
getSharedSecret,
|
|
1936
|
+
sign,
|
|
1937
|
+
verify,
|
|
1938
|
+
ProjectivePoint: Point,
|
|
1939
|
+
Signature,
|
|
1940
|
+
utils
|
|
1941
|
+
};
|
|
1942
|
+
}
|
|
1943
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1944
|
+
function getHash(hash) {
|
|
1945
|
+
return {
|
|
1946
|
+
hash,
|
|
1947
|
+
hmac: (key, ...msgs) => hmac(hash, key, concatBytes$1(...msgs)),
|
|
1948
|
+
randomBytes
|
|
1949
|
+
};
|
|
1950
|
+
}
|
|
1951
|
+
function createCurve(curveDef, defHash) {
|
|
1952
|
+
const create = (hash) => weierstrass({ ...curveDef, ...getHash(hash) });
|
|
1953
|
+
return { ...create(defHash), create };
|
|
1954
|
+
}
|
|
1955
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1956
|
+
const secp256k1P = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f");
|
|
1957
|
+
const secp256k1N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
|
|
1958
|
+
const _1n = BigInt(1);
|
|
1959
|
+
const _2n = BigInt(2);
|
|
1960
|
+
const divNearest = (a, b) => (a + b / _2n) / b;
|
|
1961
|
+
function sqrtMod(y) {
|
|
1962
|
+
const P = secp256k1P;
|
|
1963
|
+
const _3n2 = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
|
|
1964
|
+
const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
|
|
1965
|
+
const b2 = y * y * y % P;
|
|
1966
|
+
const b3 = b2 * b2 * y % P;
|
|
1967
|
+
const b6 = pow2(b3, _3n2, P) * b3 % P;
|
|
1968
|
+
const b9 = pow2(b6, _3n2, P) * b3 % P;
|
|
1969
|
+
const b11 = pow2(b9, _2n, P) * b2 % P;
|
|
1970
|
+
const b22 = pow2(b11, _11n, P) * b11 % P;
|
|
1971
|
+
const b44 = pow2(b22, _22n, P) * b22 % P;
|
|
1972
|
+
const b88 = pow2(b44, _44n, P) * b44 % P;
|
|
1973
|
+
const b176 = pow2(b88, _88n, P) * b88 % P;
|
|
1974
|
+
const b220 = pow2(b176, _44n, P) * b44 % P;
|
|
1975
|
+
const b223 = pow2(b220, _3n2, P) * b3 % P;
|
|
1976
|
+
const t1 = pow2(b223, _23n, P) * b22 % P;
|
|
1977
|
+
const t2 = pow2(t1, _6n, P) * b2 % P;
|
|
1978
|
+
const root = pow2(t2, _2n, P);
|
|
1979
|
+
if (!Fpk1.eql(Fpk1.sqr(root), y))
|
|
1980
|
+
throw new Error("Cannot find square root");
|
|
1981
|
+
return root;
|
|
1982
|
+
}
|
|
1983
|
+
const Fpk1 = Field(secp256k1P, void 0, void 0, { sqrt: sqrtMod });
|
|
1984
|
+
const secp256k1 = createCurve({
|
|
1985
|
+
a: BigInt(0),
|
|
1986
|
+
// equation params: a, b
|
|
1987
|
+
b: BigInt(7),
|
|
1988
|
+
Fp: Fpk1,
|
|
1989
|
+
// Field's prime: 2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n
|
|
1990
|
+
n: secp256k1N,
|
|
1991
|
+
// Curve order, total count of valid points in the field
|
|
1992
|
+
// Base point (x, y) aka generator point
|
|
1993
|
+
Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
|
|
1994
|
+
Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
|
|
1995
|
+
h: BigInt(1),
|
|
1996
|
+
// Cofactor
|
|
1997
|
+
lowS: true,
|
|
1998
|
+
// Allow only low-S signatures by default in sign() and verify()
|
|
1999
|
+
endo: {
|
|
2000
|
+
// Endomorphism, see above
|
|
2001
|
+
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
2002
|
+
splitScalar: (k) => {
|
|
2003
|
+
const n = secp256k1N;
|
|
2004
|
+
const a1 = BigInt("0x3086d221a7d46bcde86c90e49284eb15");
|
|
2005
|
+
const b1 = -_1n * BigInt("0xe4437ed6010e88286f547fa90abfe4c3");
|
|
2006
|
+
const a2 = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8");
|
|
2007
|
+
const b2 = a1;
|
|
2008
|
+
const POW_2_128 = BigInt("0x100000000000000000000000000000000");
|
|
2009
|
+
const c1 = divNearest(b2 * k, n);
|
|
2010
|
+
const c2 = divNearest(-b1 * k, n);
|
|
2011
|
+
let k1 = mod(k - c1 * a1 - c2 * a2, n);
|
|
2012
|
+
let k2 = mod(-c1 * b1 - c2 * b2, n);
|
|
2013
|
+
const k1neg = k1 > POW_2_128;
|
|
2014
|
+
const k2neg = k2 > POW_2_128;
|
|
2015
|
+
if (k1neg)
|
|
2016
|
+
k1 = n - k1;
|
|
2017
|
+
if (k2neg)
|
|
2018
|
+
k2 = n - k2;
|
|
2019
|
+
if (k1 > POW_2_128 || k2 > POW_2_128) {
|
|
2020
|
+
throw new Error("splitScalar: Endomorphism failed, k=" + k);
|
|
2021
|
+
}
|
|
2022
|
+
return { k1neg, k1, k2neg, k2 };
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
}, sha256);
|
|
2026
|
+
BigInt(0);
|
|
2027
|
+
secp256k1.ProjectivePoint;
|
|
2028
|
+
export {
|
|
2029
|
+
secp256k1
|
|
2030
|
+
};
|
|
2031
|
+
//# sourceMappingURL=secp256k1-ZaBTFi_B.js.map
|