@layerswap/widget 0.1.4 → 0.1.14
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/README.md +78 -3
- package/dist/Models/Theme.d.ts +7 -6
- package/dist/Models/Theme.js +7 -7
- package/dist/Models/WalletProvider.d.ts +0 -4
- package/dist/Models/WalletProvider.js +2 -0
- package/dist/components/Buttons/copyButton.js +4 -3
- package/dist/components/ColorSchema.js +79 -45
- package/dist/components/Common/AddressIcon.js +1 -0
- package/dist/components/Common/AverageCompletionTime.js +1 -1
- package/dist/components/Common/CountDownTimer.js +2 -2
- package/dist/components/Common/FormattedAverageCompletionTime.js +1 -1
- package/dist/components/HeaderWithMenu/index.js +1 -8
- package/dist/components/Input/Address/AddressNote.js +3 -2
- package/dist/components/Input/Address/AddressPicker/AddressWithIcon.js +2 -2
- package/dist/components/Input/Address/AddressPicker/ConnectedWallets/ConnectWalletButton.js +12 -5
- package/dist/components/Input/Address/AddressPicker/ExchangeNote.d.ts +1 -1
- package/dist/components/Input/Address/AddressPicker/ExchangeNote.js +1 -1
- package/dist/components/Input/RouteIcon.js +1 -1
- package/dist/components/LayerswapMenu/MenuList.js +2 -56
- package/dist/components/Pages/404/index.js +1 -0
- package/dist/components/Pages/Auth/Steps/CodeStep/VerifyEmailCode.js +1 -0
- package/dist/components/Pages/Auth/index.d.ts +1 -1
- package/dist/components/Pages/Auth/index.js +3 -2
- package/dist/components/Pages/Campaigns/Details/Leaderboard.js +1 -0
- package/dist/components/Pages/Campaigns/Details/index.d.ts +1 -1
- package/dist/components/Pages/Campaigns/Details/index.js +3 -2
- package/dist/components/Pages/Campaigns/index.d.ts +1 -1
- package/dist/components/Pages/Campaigns/index.js +3 -2
- package/dist/components/Pages/Maintanance/index.js +1 -0
- package/dist/components/Pages/NoCookies/index.js +1 -0
- package/dist/components/Pages/SwapHistory/History.js +1 -2
- package/dist/components/Pages/SwapHistory/index.d.ts +1 -1
- package/dist/components/Pages/SwapHistory/index.js +4 -3
- package/dist/components/Pages/SwapPages/Form/FeeDetails/Campaign.js +1 -0
- package/dist/components/Pages/SwapPages/Form/Form.js +1 -4
- package/dist/components/Pages/SwapPages/Form/SecondaryComponents/ValidationError.js +1 -1
- package/dist/components/Pages/SwapPages/Form/Select/Popover/PopoverSelect.js +1 -1
- package/dist/components/Pages/SwapPages/Form/index.js +1 -0
- package/dist/components/Pages/SwapPages/Withdraw/Coinbase/Carousel.js +8 -6
- package/dist/components/Pages/SwapPages/Withdraw/Processing/Processing.js +2 -2
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/FuelWalletWithdrawal.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/FuelWalletWithdrawal.js +159 -125
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/ImtblxWalletWithdrawStep.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/ImtblxWalletWithdrawStep.js +69 -51
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/ActivationTokentPicker.d.ts +0 -8
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/ActivationTokentPicker.js +87 -45
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/hooks.d.ts +0 -40
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/hooks.js +73 -46
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/index.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/index.js +175 -128
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/index.d.ts +0 -7
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/index.js +138 -116
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/transactionSender.d.ts +0 -8
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/transactionSender.js +96 -75
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/SophonWalletWithdraw.js +2 -2
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/StarknetWalletWithdraw.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/StarknetWalletWithdraw.js +88 -71
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/TonWalletWithdraw.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/TonWalletWithdraw.js +146 -136
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/TronWalletWithdraw.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/TronWalletWithdraw.js +120 -99
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/TransferToken.js +3 -3
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/buttons.js +1 -0
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/index.js +1 -1
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/transactionMessage.js +2 -2
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransferContent.js +101 -33
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Evm.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Evm.js +60 -55
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Starknet.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Starknet.js +71 -55
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/buttons.js +1 -0
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/index.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/index.js +56 -52
- package/dist/components/Pages/SwapPages/Withdraw/index.d.ts +1 -1
- package/dist/components/Pages/SwapPages/Withdraw/index.js +3 -2
- package/dist/components/Wallet/WalletModal/Connector.js +1 -1
- package/dist/components/Wallet/WalletProviders/FuelProvider.d.ts +0 -5
- package/dist/components/Wallet/WalletProviders/FuelProvider.js +25 -20
- package/dist/components/Wallet/WalletProviders/ImtblPassportProvider.d.ts +0 -5
- package/dist/components/Wallet/WalletProviders/ImtblPassportProvider.js +39 -36
- package/dist/components/Wallet/WalletProviders/SolanaProvider.d.ts +0 -5
- package/dist/components/Wallet/WalletProviders/SolanaProvider.js +49 -38
- package/dist/components/Wallet/WalletProviders/StarknetProvider.d.ts +0 -5
- package/dist/components/Wallet/WalletProviders/StarknetProvider.js +112 -117
- package/dist/components/Wallet/WalletProviders/TonConnectProvider.d.ts +0 -6
- package/dist/components/Wallet/WalletProviders/TonConnectProvider.js +58 -50
- package/dist/components/Wallet/WalletProviders/TronProvider.d.ts +0 -3
- package/dist/components/Wallet/WalletProviders/TronProvider.js +23 -15
- package/dist/components/Wallet/WalletProviders/Wagmi.d.ts +1 -1
- package/dist/components/Wallet/WalletProviders/Wagmi.js +20 -10
- package/dist/components/Wallet/WalletProviders/index.js +13 -6
- package/dist/components/Widget/Footer.d.ts +2 -1
- package/dist/components/Widget/Footer.js +13 -4
- package/dist/components/Widget/Index.d.ts +1 -1
- package/dist/components/Widget/Index.js +1 -1
- package/dist/components/WidgetLoading.d.ts +1 -0
- package/dist/components/WidgetLoading.js +5 -0
- package/dist/components/Wizard/Wizard.js +1 -1
- package/dist/components/shadcn/command.js +1 -1
- package/dist/components/themeWrapper.js +3 -2
- package/dist/context/{LayerswapContext.d.ts → LayerswapProvider.d.ts} +3 -8
- package/dist/context/{LayerswapContext.js → LayerswapProvider.js} +8 -9
- package/dist/context/authContext.js +1 -0
- package/dist/context/walletHooksProvider.js +1 -0
- package/dist/hooks/useWallet.js +10 -14
- package/dist/index.css +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.js +2 -4
- package/dist/index.mjs +19 -0
- package/dist/lib/AppSettings.d.ts +7 -3
- package/dist/lib/AppSettings.js +8 -7
- package/dist/lib/address/formatter/index.js +8 -9
- package/dist/lib/address/validator/index.js +18 -20
- package/dist/lib/axiosInterceptor.js +1 -2
- package/dist/lib/balances/balanceResolver.js +16 -16
- package/dist/lib/balances/providers/evmBalanceProvider.js +3 -3
- package/dist/lib/balances/providers/loopringBalanceProvider.d.ts +0 -6
- package/dist/lib/balances/providers/loopringBalanceProvider.js +56 -43
- package/dist/lib/balances/providers/paradexBalanceProvider.d.ts +0 -6
- package/dist/lib/balances/providers/paradexBalanceProvider.js +42 -42
- package/dist/lib/balances/providers/solanaBalanceProvider.d.ts +0 -6
- package/dist/lib/balances/providers/solanaBalanceProvider.js +70 -71
- package/dist/lib/balances/providers/starknetBalanceProvider.d.ts +0 -6
- package/dist/lib/balances/providers/starknetBalanceProvider.js +48 -45
- package/dist/lib/balances/providers/tonBalanceProvider.d.ts +0 -18
- package/dist/lib/balances/providers/tonBalanceProvider.js +104 -100
- package/dist/lib/balances/providers/tronBalanceResolver.js +2 -3
- package/dist/lib/fuels/common/FakeAccount.d.ts +0 -24
- package/dist/lib/fuels/common/FakeAccount.js +58 -36
- package/dist/lib/fuels/common/PredicateConnector.d.ts +0 -54
- package/dist/lib/fuels/common/PredicateConnector.js +292 -205
- package/dist/lib/fuels/common/PredicateFactory.d.ts +0 -29
- package/dist/lib/fuels/common/PredicateFactory.js +123 -76
- package/dist/lib/fuels/common/PredicateWalletAdapter.d.ts +0 -17
- package/dist/lib/fuels/common/PredicateWalletAdapter.js +44 -29
- package/dist/lib/fuels/common/index.d.ts +0 -4
- package/dist/lib/fuels/common/index.js +4 -4
- package/dist/lib/fuels/connectors/fuel-wallet/FuelWalletConnector.d.ts +0 -51
- package/dist/lib/fuels/connectors/fuel-wallet/FuelWalletConnector.js +268 -234
- package/dist/lib/fuels/connectors/fuel-wallet/index.d.ts +0 -2
- package/dist/lib/fuels/connectors/fuel-wallet/index.js +2 -2
- package/dist/lib/fuels/connectors/fuel-wallet/types.d.ts +0 -50
- package/dist/lib/fuels/connectors/fuel-wallet/types.js +53 -9
- package/dist/lib/fuels/connectors/fuelet-wallet/FueletWalletConnector.d.ts +0 -7
- package/dist/lib/fuels/connectors/fuelet-wallet/FueletWalletConnector.js +20 -19
- package/dist/lib/fuels/connectors/fuelet-wallet/index.d.ts +0 -1
- package/dist/lib/fuels/connectors/fuelet-wallet/index.js +1 -1
- package/dist/lib/gases/gasResolver.d.ts +1 -1
- package/dist/lib/gases/gasResolver.js +10 -10
- package/dist/lib/gases/providers/evmGasProvider.js +5 -4
- package/dist/lib/gases/providers/loopringGasProvider.d.ts +0 -6
- package/dist/lib/gases/providers/loopringGasProvider.js +27 -24
- package/dist/lib/gases/providers/solanaGasProvider.d.ts +0 -7
- package/dist/lib/gases/providers/solanaGasProvider.js +32 -31
- package/dist/lib/gases/providers/starknetGasProvider.d.ts +0 -7
- package/dist/lib/gases/providers/starknetGasProvider.js +34 -33
- package/dist/lib/imtbl.d.ts +0 -69
- package/dist/lib/imtbl.js +63 -60
- package/dist/lib/internalApiClient.d.ts +0 -2
- package/dist/lib/internalApiClient.js +1 -4
- package/dist/lib/layerSwapApiClient.js +3 -3
- package/dist/lib/logError.js +2 -2
- package/dist/lib/nft/nftBalanceResolver.js +1 -2
- package/dist/lib/nft/providers/starknetNftProvider.d.ts +0 -6
- package/dist/lib/nft/providers/starknetNftProvider.js +49 -50
- package/dist/lib/wallets/connectors/EthereumProvider.d.ts +2 -2
- package/dist/lib/wallets/connectors/useSyncProviders/store.d.ts +1 -4
- package/dist/lib/wallets/fuel/Bako.d.ts +0 -15
- package/dist/lib/wallets/fuel/Bako.js +34 -29
- package/dist/lib/wallets/fuel/Basko.d.ts +0 -15
- package/dist/lib/wallets/fuel/Basko.js +34 -29
- package/dist/lib/wallets/fuel/useFuel.d.ts +0 -2
- package/dist/lib/wallets/fuel/useFuel.js +211 -192
- package/dist/lib/wallets/imtblX/useImtblX.d.ts +0 -2
- package/dist/lib/wallets/imtblX/useImtblX.js +87 -87
- package/dist/lib/wallets/paradex/Authorize/Ethereum.d.ts +0 -2
- package/dist/lib/wallets/paradex/Authorize/Ethereum.js +24 -23
- package/dist/lib/wallets/paradex/Authorize/Starknet.d.ts +0 -2
- package/dist/lib/wallets/paradex/Authorize/Starknet.js +14 -13
- package/dist/lib/wallets/paradex/lib/account.d.ts +0 -28
- package/dist/lib/wallets/paradex/lib/account.js +102 -53
- package/dist/lib/wallets/paradex/lib/index.d.ts +0 -24
- package/dist/lib/wallets/paradex/lib/index.js +20 -20
- package/dist/lib/wallets/paradex/lib/paraclear-provider.d.ts +0 -6
- package/dist/lib/wallets/paradex/lib/paraclear-provider.js +13 -9
- package/dist/lib/wallets/paradex/lib/paraclear.d.ts +0 -137
- package/dist/lib/wallets/paradex/lib/paraclear.js +258 -131
- package/dist/lib/wallets/paradex/lib/starknet-account-support.d.ts +0 -22
- package/dist/lib/wallets/paradex/lib/starknet-account-support.js +296 -220
- package/dist/lib/wallets/paradex/lib/starknet-signer.d.ts +0 -15
- package/dist/lib/wallets/paradex/lib/starknet-signer.js +120 -94
- package/dist/lib/wallets/paradex/useParadex.d.ts +0 -7
- package/dist/lib/wallets/paradex/useParadex.js +197 -194
- package/dist/lib/wallets/solana/transactionBuilder.d.ts +0 -4
- package/dist/lib/wallets/solana/transactionBuilder.js +63 -39
- package/dist/lib/wallets/solana/useSVM.d.ts +0 -5
- package/dist/lib/wallets/solana/useSVM.js +139 -142
- package/dist/lib/wallets/starknet/useStarknet.d.ts +0 -2
- package/dist/lib/wallets/starknet/useStarknet.js +139 -139
- package/dist/lib/wallets/ton/client.d.ts +0 -3
- package/dist/lib/wallets/ton/client.js +7 -7
- package/dist/lib/wallets/ton/useTON.d.ts +0 -2
- package/dist/lib/wallets/ton/useTON.js +121 -122
- package/dist/lib/wallets/tron/connectors/bitkeep.d.ts +0 -61
- package/dist/lib/wallets/tron/connectors/bitkeep.js +326 -303
- package/dist/lib/wallets/tron/connectors/index.d.ts +0 -4
- package/dist/lib/wallets/tron/connectors/index.js +4 -4
- package/dist/lib/wallets/tron/connectors/okxWallet.d.ts +0 -66
- package/dist/lib/wallets/tron/connectors/okxWallet.js +364 -336
- package/dist/lib/wallets/tron/connectors/tokenPocket.d.ts +0 -72
- package/dist/lib/wallets/tron/connectors/tokenPocket.js +337 -308
- package/dist/lib/wallets/tron/connectors/tronLink/index.d.ts +0 -102
- package/dist/lib/wallets/tron/connectors/tronLink/index.js +560 -520
- package/dist/lib/wallets/tron/connectors/tronLink/types.d.ts +0 -56
- package/dist/lib/wallets/tron/connectors/tronLink/types.js +53 -1
- package/dist/lib/wallets/tron/connectors/tronLink/utils.d.ts +0 -14
- package/dist/lib/wallets/tron/connectors/tronLink/utils.js +64 -61
- package/dist/lib/wallets/tron/useTron.d.ts +0 -2
- package/dist/lib/wallets/tron/useTron.js +111 -111
- package/dist/lib/wallets/utils/resolveWalletIcon.js +1 -0
- package/package.json +26 -77
- package/dist/hooks/useCopyClipboard.d.ts +0 -1
- package/dist/hooks/useCopyClipboard.js +0 -21
- package/dist/index.cjs +0 -125
- package/dist/lib/abis/ERC20.json +0 -258
- package/dist/lib/fuels/connectors/walletConnect/WalletConnectConnector.d.ts +0 -42
- package/dist/lib/fuels/connectors/walletConnect/WalletConnectConnector.js +0 -357
- package/dist/lib/fuels/connectors/walletConnect/constants.d.ts +0 -6
- package/dist/lib/fuels/connectors/walletConnect/constants.js +0 -7
- package/dist/lib/fuels/connectors/walletConnect/index.d.ts +0 -3
- package/dist/lib/fuels/connectors/walletConnect/index.js +0 -3
- package/dist/lib/fuels/connectors/walletConnect/types.d.ts +0 -12
- package/dist/lib/fuels/connectors/walletConnect/types.js +0 -1
- package/dist/lib/fuels/connectors/walletConnect/utils/index.d.ts +0 -1
- package/dist/lib/fuels/connectors/walletConnect/utils/index.js +0 -1
- package/dist/lib/fuels/connectors/walletConnect/utils/subscribeAndEnforceChain.d.ts +0 -2
- package/dist/lib/fuels/connectors/walletConnect/utils/subscribeAndEnforceChain.js +0 -39
- package/dist/lib/fuels/connectors/walletConnect/web3Modal.d.ts +0 -10
- package/dist/lib/fuels/connectors/walletConnect/web3Modal.js +0 -38
- package/dist/lib/loopring/LoopringAPI.d.ts +0 -12
- package/dist/lib/loopring/LoopringAPI.js +0 -13
- package/dist/lib/loopring/defs.d.ts +0 -425
- package/dist/lib/loopring/defs.js +0 -217
- package/dist/lib/loopring/eddsa.d.ts +0 -29
- package/dist/lib/loopring/eddsa.js +0 -208
- package/dist/lib/loopring/field.d.ts +0 -17
- package/dist/lib/loopring/field.js +0 -61
- package/dist/lib/loopring/formatter.d.ts +0 -137
- package/dist/lib/loopring/formatter.js +0 -516
- package/dist/lib/loopring/helpers.d.ts +0 -36
- package/dist/lib/loopring/helpers.js +0 -140
- package/dist/lib/loopring/jubjub.d.ts +0 -19
- package/dist/lib/loopring/jubjub.js +0 -79
- package/dist/lib/loopring/permutation.d.ts +0 -22
- package/dist/lib/loopring/permutation.js +0 -198
- package/dist/lib/loopring/poseidon/EDDSAUtil.d.ts +0 -14
- package/dist/lib/loopring/poseidon/EDDSAUtil.js +0 -61
- package/dist/lib/loopring/poseidon/babyJub.d.ts +0 -6
- package/dist/lib/loopring/poseidon/babyJub.js +0 -51
- package/dist/lib/loopring/poseidon/eddsa.d.ts +0 -29
- package/dist/lib/loopring/poseidon/eddsa.js +0 -210
- package/dist/lib/loopring/utils.d.ts +0 -76
- package/dist/lib/loopring/utils.js +0 -230
- package/dist/styles/dialog-transition.css +0 -28
- package/dist/styles/globals.css +0 -372
- package/dist/styles/manual-trasnfer-svg.css +0 -299
- package/dist/styles/vaul.css +0 -256
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from "ethers";
|
|
2
|
-
import { FQ } from "./field";
|
|
3
|
-
export declare class jubjub {
|
|
4
|
-
static JUBJUB_Q: BigNumber;
|
|
5
|
-
static JUBJUB_E: BigNumber;
|
|
6
|
-
static JUBJUB_C: BigNumber;
|
|
7
|
-
static JUBJUB_L: BigNumber;
|
|
8
|
-
static JUBJUB_A: BigNumber;
|
|
9
|
-
static JUBJUB_D: BigNumber;
|
|
10
|
-
}
|
|
11
|
-
export declare class Point {
|
|
12
|
-
x: FQ;
|
|
13
|
-
y: FQ;
|
|
14
|
-
constructor(x: FQ, y: FQ);
|
|
15
|
-
static generate(): Point;
|
|
16
|
-
mul(scaler: BigNumber): Point;
|
|
17
|
-
add(other: Point): Point;
|
|
18
|
-
static infinity(): Point;
|
|
19
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
This module implements the extended twisted edwards and extended affine coordinates
|
|
3
|
-
described in the paper "Twisted Edwards Curves Revisited":
|
|
4
|
-
|
|
5
|
-
- https://iacr.org/archive/asiacrypt2008/53500329/53500329.pdf
|
|
6
|
-
Huseyin Hisil, Kenneth Koon-Ho Wong, Gary Carter, and Ed Dawson
|
|
7
|
-
|
|
8
|
-
Information Security Institute,
|
|
9
|
-
Queensland University of Technology, QLD, 4000, Australia
|
|
10
|
-
{h.hisil, kk.wong, g.carter, e.dawson}@qut.edu.au
|
|
11
|
-
|
|
12
|
-
By using the extended coordinate system we can avoid expensive modular exponentiation
|
|
13
|
-
calls, for example - a scalar multiplication call (or multiple...) may perform only
|
|
14
|
-
one 3d->2d projection at the point where affine coordinates are necessary, and every
|
|
15
|
-
intermediate uses a much faster form.
|
|
16
|
-
|
|
17
|
-
# XXX: none of these functions are constant time, they should not be used interactively!
|
|
18
|
-
*/
|
|
19
|
-
import { BigNumber } from "ethers";
|
|
20
|
-
import { field, FQ } from "./field";
|
|
21
|
-
export class jubjub {
|
|
22
|
-
}
|
|
23
|
-
jubjub.JUBJUB_Q = field.SNARK_SCALAR_FIELD;
|
|
24
|
-
jubjub.JUBJUB_E = BigNumber.from("21888242871839275222246405745257275088614511777268538073601725287587578984328");
|
|
25
|
-
jubjub.JUBJUB_C = BigNumber.from("8"); // Cofactor
|
|
26
|
-
jubjub.JUBJUB_L = jubjub.JUBJUB_E.div(jubjub.JUBJUB_C); // L*B = 0, and (2^C)*L == #E
|
|
27
|
-
jubjub.JUBJUB_A = BigNumber.from("168700"); // Coefficient A
|
|
28
|
-
jubjub.JUBJUB_D = BigNumber.from("168696"); // Coefficient D
|
|
29
|
-
export class Point {
|
|
30
|
-
constructor(x, y) {
|
|
31
|
-
this.x = x;
|
|
32
|
-
this.y = y;
|
|
33
|
-
}
|
|
34
|
-
static generate() {
|
|
35
|
-
const xBigInt = BigNumber.from("16540640123574156134436876038791482806971768689494387082833631921987005038935");
|
|
36
|
-
const yBigInt = BigNumber.from("20819045374670962167435360035096875258406992893633759881276124905556507972311");
|
|
37
|
-
const point = new Point(new FQ(xBigInt), new FQ(yBigInt));
|
|
38
|
-
return point;
|
|
39
|
-
}
|
|
40
|
-
mul(scaler) {
|
|
41
|
-
let p = new Point(this.x, this.y);
|
|
42
|
-
let a = Point.infinity();
|
|
43
|
-
let i = 0;
|
|
44
|
-
while (!scaler.eq(BigNumber.from("0"))) {
|
|
45
|
-
const bitwiseAnd = scaler.and(BigNumber.from("1"));
|
|
46
|
-
if (!bitwiseAnd.eq(BigNumber.from("0"))) {
|
|
47
|
-
a = a.add(p);
|
|
48
|
-
}
|
|
49
|
-
let copyP1 = new Point(p.x, p.y);
|
|
50
|
-
let copyP2 = new Point(p.x, p.y);
|
|
51
|
-
p = copyP1.add(copyP2);
|
|
52
|
-
scaler = scaler.div(BigNumber.from("2"));
|
|
53
|
-
i = i + 1;
|
|
54
|
-
}
|
|
55
|
-
return a;
|
|
56
|
-
}
|
|
57
|
-
add(other) {
|
|
58
|
-
if (this.x.n.eq(BigNumber.from("0")) && this.y.n.eq(BigNumber.from("0"))) {
|
|
59
|
-
return other;
|
|
60
|
-
}
|
|
61
|
-
const u1 = this.x;
|
|
62
|
-
const v1 = this.y;
|
|
63
|
-
const u2 = other.x;
|
|
64
|
-
const v2 = other.y;
|
|
65
|
-
const u3_tmp0 = (u1.mul(v2.n)).add(v1.mul(u2.n).n);
|
|
66
|
-
const u3_tmp1 = u1.mul(u2.n).mul(v1.n).mul(v2.n).mul(jubjub.JUBJUB_D);
|
|
67
|
-
const u3_tmp2 = FQ.one().add(u3_tmp1.n);
|
|
68
|
-
const u3 = u3_tmp0.div(u3_tmp2.n);
|
|
69
|
-
const v3_tmp0 = v1.mul(v2.n);
|
|
70
|
-
const v3_tmp1 = u1.mul(u2.n).mul(jubjub.JUBJUB_A);
|
|
71
|
-
const v3_tmp3 = v3_tmp0.sub(v3_tmp1.n);
|
|
72
|
-
const v3_tmp5 = FQ.one().sub(u3_tmp1.n);
|
|
73
|
-
const v3 = v3_tmp3.div(v3_tmp5.n);
|
|
74
|
-
return new Point(u3, v3);
|
|
75
|
-
}
|
|
76
|
-
static infinity() {
|
|
77
|
-
return new Point(new FQ(BigNumber.from("0")), new FQ(BigNumber.from("1")));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from 'ethers';
|
|
2
|
-
export declare class PoseidonParams {
|
|
3
|
-
p: BigNumber;
|
|
4
|
-
t: number;
|
|
5
|
-
nRoundsF: number;
|
|
6
|
-
nRoundsP: number;
|
|
7
|
-
seed: string;
|
|
8
|
-
e: BigNumber;
|
|
9
|
-
constants_C: [BigNumber];
|
|
10
|
-
constants_M: [[BigNumber]];
|
|
11
|
-
security_target: number;
|
|
12
|
-
constructor(p: BigNumber, t: number, nRoundsF: number, nRoundsP: number, seed: string, e: BigNumber, constants_C: [BigNumber] | null, constants_M: [[BigNumber]] | null, security_target: number);
|
|
13
|
-
}
|
|
14
|
-
export declare class permunation {
|
|
15
|
-
static H(arg: string): BigNumber;
|
|
16
|
-
static H_Bigint(arg: BigNumber): BigNumber;
|
|
17
|
-
static poseidon_constants(p: BigNumber, seed: string, n: number): any;
|
|
18
|
-
static poseidon_matrix(p: BigNumber, seed: string, t: number): any;
|
|
19
|
-
static poseidon_sbox(state: [BigNumber], i: number, params: PoseidonParams): [BigNumber];
|
|
20
|
-
static poseidon_mix(state: [BigNumber], M: [[BigNumber]], p: BigNumber): any;
|
|
21
|
-
static poseidon(inputs: [BigNumber], params: PoseidonParams): any;
|
|
22
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Implements the Poseidon permutation:
|
|
3
|
-
|
|
4
|
-
Starkad and Poseidon: New Hash Functions for Zero Knowledge Proof Systems
|
|
5
|
-
- Lorenzo Grassi, Daniel Kales, Dmitry Khovratovich, Arnab Roy, Christian Rechberger, and Markus Schofnegger
|
|
6
|
-
- https://eprint.iacr.org/2019/458.pdf
|
|
7
|
-
|
|
8
|
-
Other implementations:
|
|
9
|
-
|
|
10
|
-
- https://github.com/shamatar/PoseidonTree/
|
|
11
|
-
- https://github.com/iden3/circomlib/blob/master/src/poseidon.js
|
|
12
|
-
- https://github.com/dusk-network/poseidon252
|
|
13
|
-
*/
|
|
14
|
-
import { BigNumber } from 'ethers';
|
|
15
|
-
import { SignatureScheme } from './eddsa';
|
|
16
|
-
import { modulo } from './field';
|
|
17
|
-
import { TextEncoder } from 'web-encoding';
|
|
18
|
-
import blake2b from 'blake2b';
|
|
19
|
-
export class PoseidonParams {
|
|
20
|
-
constructor(p, t, nRoundsF, nRoundsP, seed, e, constants_C, constants_M, security_target) {
|
|
21
|
-
this.p = p;
|
|
22
|
-
this.t = t;
|
|
23
|
-
this.nRoundsF = nRoundsF;
|
|
24
|
-
this.nRoundsP = nRoundsP;
|
|
25
|
-
this.seed = seed;
|
|
26
|
-
this.e = e;
|
|
27
|
-
if (constants_C == null) {
|
|
28
|
-
this.constants_C = permunation.poseidon_constants(p, `${seed}_constants`, nRoundsF + nRoundsP);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
this.constants_C = constants_C;
|
|
32
|
-
}
|
|
33
|
-
if (constants_M == null) {
|
|
34
|
-
this.constants_M = permunation.poseidon_matrix(p, `${seed}_matrix_0000`, t);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
this.constants_M = constants_M;
|
|
38
|
-
}
|
|
39
|
-
this.security_target = security_target;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
export class permunation {
|
|
43
|
-
static H(arg) {
|
|
44
|
-
const outputLength = 32;
|
|
45
|
-
const enc = new TextEncoder();
|
|
46
|
-
const message = enc.encode(arg);
|
|
47
|
-
const buf = Buffer.alloc(outputLength);
|
|
48
|
-
blake2b(buf.length, undefined).update(message).final(buf);
|
|
49
|
-
const items = buf.toJSON().data;
|
|
50
|
-
let sum = BigNumber.from('0');
|
|
51
|
-
var i = 0;
|
|
52
|
-
for (var i = 0; i < items.length; i++) {
|
|
53
|
-
const itemBigInt = BigNumber.from(items[i]);
|
|
54
|
-
const tmp = itemBigInt.mul(BigNumber.from('256').pow(BigNumber.from(i)));
|
|
55
|
-
sum = sum.add(tmp);
|
|
56
|
-
}
|
|
57
|
-
return sum;
|
|
58
|
-
}
|
|
59
|
-
static H_Bigint(arg) {
|
|
60
|
-
const outputLength = 32;
|
|
61
|
-
const message = new Uint8Array(SignatureScheme.to_bytes(arg));
|
|
62
|
-
const buf = Buffer.alloc(outputLength);
|
|
63
|
-
blake2b(buf.length, undefined).update(message).final(buf);
|
|
64
|
-
const items = buf.toJSON().data;
|
|
65
|
-
let sum = BigNumber.from('0');
|
|
66
|
-
var i = 0;
|
|
67
|
-
for (var i = 0; i < items.length; i++) {
|
|
68
|
-
const itemBigInt = BigNumber.from(items[i]);
|
|
69
|
-
const tmp = itemBigInt.mul(BigNumber.from('256').pow(BigNumber.from(i)));
|
|
70
|
-
sum = sum.add(tmp);
|
|
71
|
-
}
|
|
72
|
-
return sum;
|
|
73
|
-
}
|
|
74
|
-
static poseidon_constants(p, seed, n) {
|
|
75
|
-
let c;
|
|
76
|
-
c = [];
|
|
77
|
-
let seedBigInt = this.H(seed);
|
|
78
|
-
const result = seedBigInt.mod(p);
|
|
79
|
-
c.push(result);
|
|
80
|
-
for (let i = 0; i < n - 1; i++) {
|
|
81
|
-
seedBigInt = this.H_Bigint(seedBigInt);
|
|
82
|
-
const result = seedBigInt.mod(p);
|
|
83
|
-
c.push(result);
|
|
84
|
-
}
|
|
85
|
-
return c;
|
|
86
|
-
}
|
|
87
|
-
static poseidon_matrix(p, seed, t) {
|
|
88
|
-
const c = this.poseidon_constants(p, seed, t * 2);
|
|
89
|
-
let matrix;
|
|
90
|
-
matrix = [];
|
|
91
|
-
for (let i = 0; i < t; i++) {
|
|
92
|
-
let row;
|
|
93
|
-
row = [];
|
|
94
|
-
for (let j = 0; j < t; j++) {
|
|
95
|
-
const c_i = c[i];
|
|
96
|
-
const c_t_j = c[t + j];
|
|
97
|
-
const p_c = p;
|
|
98
|
-
const c_t_j_p = c_t_j.mod(p_c);
|
|
99
|
-
const left = c_i.sub(c_t_j_p);
|
|
100
|
-
const p_2 = p_c.sub(2);
|
|
101
|
-
const item_c = modulo(left, p_2, p_c);
|
|
102
|
-
row.push(item_c);
|
|
103
|
-
}
|
|
104
|
-
matrix.push(row);
|
|
105
|
-
}
|
|
106
|
-
return matrix;
|
|
107
|
-
}
|
|
108
|
-
static poseidon_sbox(state, i, params) {
|
|
109
|
-
/*
|
|
110
|
-
iacr.org/2019/458 § 2.2 The Hades Strategy (pg 6)
|
|
111
|
-
|
|
112
|
-
In more details, assume R_F = 2 · R_f is an even number. Then
|
|
113
|
-
- the first R_f rounds have a full S-Box layer,
|
|
114
|
-
- the middle R_P rounds have a partial S-Box layer (i.e., 1 S-Box layer),
|
|
115
|
-
- the last R_f rounds have a full S-Box layer
|
|
116
|
-
*/
|
|
117
|
-
const half_F = params.nRoundsF / 2;
|
|
118
|
-
if (i < half_F || i >= half_F + params.nRoundsP) {
|
|
119
|
-
for (let j = 0; j < state.length; j++) {
|
|
120
|
-
const element_c = state[j];
|
|
121
|
-
const e_c = params.e;
|
|
122
|
-
const p_c = params.p;
|
|
123
|
-
const item = modulo(element_c, e_c, p_c);
|
|
124
|
-
state[j] = item;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
const element_c = state[0];
|
|
129
|
-
const e_c = params.e;
|
|
130
|
-
const p_c = params.p;
|
|
131
|
-
const item = modulo(element_c, e_c, p_c);
|
|
132
|
-
state[0] = item;
|
|
133
|
-
}
|
|
134
|
-
return state;
|
|
135
|
-
}
|
|
136
|
-
static poseidon_mix(state, M, p) {
|
|
137
|
-
/*
|
|
138
|
-
The mixing layer is a matrix vector product of the state with the mixing matrix
|
|
139
|
-
- https://mathinsight.org/matrix_vector_multiplication
|
|
140
|
-
*/
|
|
141
|
-
let newState;
|
|
142
|
-
newState = [];
|
|
143
|
-
for (let i = 0; i < M.length; i++) {
|
|
144
|
-
let sum = BigNumber.from(0);
|
|
145
|
-
for (let j = 0; j < state.length; j++) {
|
|
146
|
-
const element = state[j];
|
|
147
|
-
sum = sum.add(M[i][j].mul(element));
|
|
148
|
-
}
|
|
149
|
-
newState.push(sum.mod(p));
|
|
150
|
-
}
|
|
151
|
-
return newState;
|
|
152
|
-
}
|
|
153
|
-
// poseidon
|
|
154
|
-
/*
|
|
155
|
-
Main instansiation of the Poseidon permutation
|
|
156
|
-
|
|
157
|
-
The state is `t` elements wide, there are `F` full-rounds
|
|
158
|
-
followed by `P` partial rounds, then `F` full rounds again.
|
|
159
|
-
|
|
160
|
-
[ ARK ] --,
|
|
161
|
-
| | | | | | |
|
|
162
|
-
[ SBOX ] - Full Round
|
|
163
|
-
| | | | | | |
|
|
164
|
-
[ MIX ] --`
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
[ ARK ] --,
|
|
168
|
-
| | | | | | |
|
|
169
|
-
[ SBOX ] - Partial Round
|
|
170
|
-
| | Only 1 element is substituted in partial round
|
|
171
|
-
[ MIX ] --`
|
|
172
|
-
|
|
173
|
-
There are F+P rounds for the full permutation.
|
|
174
|
-
|
|
175
|
-
You can provide `r = N - 2s` bits of input per round, where `s` is the desired
|
|
176
|
-
security level, in most cases this means you can provide `t-1` inputs with
|
|
177
|
-
appropriately chosen parameters. The permutation can be 'chained' together
|
|
178
|
-
to form a sponge construct.
|
|
179
|
-
*/
|
|
180
|
-
static poseidon(inputs, params) {
|
|
181
|
-
let state;
|
|
182
|
-
state = [];
|
|
183
|
-
state = state.concat(inputs);
|
|
184
|
-
for (var i = 0; i < params.t - inputs.length; i++) {
|
|
185
|
-
state.push(BigNumber.from(0));
|
|
186
|
-
}
|
|
187
|
-
for (var i = 0; i < params.constants_C.length; i++) {
|
|
188
|
-
const C_i = params.constants_C[i];
|
|
189
|
-
for (let index = 0; index < state.length; index++) {
|
|
190
|
-
const element = state[index];
|
|
191
|
-
state[index] = element.add(C_i);
|
|
192
|
-
}
|
|
193
|
-
state = this.poseidon_sbox(state, i, params);
|
|
194
|
-
state = this.poseidon_mix(state, params.constants_M, params.p);
|
|
195
|
-
}
|
|
196
|
-
return state[0];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare class EDDSAUtil {
|
|
2
|
-
static sign(PrivateKey: string | undefined, hash: any): {
|
|
3
|
-
Rx: string;
|
|
4
|
-
Ry: string;
|
|
5
|
-
s: string;
|
|
6
|
-
};
|
|
7
|
-
static formatted(hexString: string): string;
|
|
8
|
-
static generateKeyPair(seed: any): {
|
|
9
|
-
publicKeyX: string;
|
|
10
|
-
publicKeyY: string;
|
|
11
|
-
secretKey: string;
|
|
12
|
-
};
|
|
13
|
-
static pack(publicKeyX: string, publicKeyY: string): any;
|
|
14
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from "ethers";
|
|
2
|
-
import { SignatureScheme } from "./eddsa";
|
|
3
|
-
import { FQ } from "../field";
|
|
4
|
-
import { jubjub } from "../jubjub";
|
|
5
|
-
import { babyJub } from "./babyJub";
|
|
6
|
-
export class EDDSAUtil {
|
|
7
|
-
static sign(PrivateKey, hash) {
|
|
8
|
-
const strKey = BigNumber.from(PrivateKey);
|
|
9
|
-
const msg = BigNumber.from(hash);
|
|
10
|
-
const copyKey = new FQ(strKey);
|
|
11
|
-
const B = SignatureScheme.B();
|
|
12
|
-
const signed = SignatureScheme.sign(msg, copyKey, B);
|
|
13
|
-
const x = EDDSAUtil.formatted(signed.sig.R.x.n.toHexString().slice(2));
|
|
14
|
-
const y = EDDSAUtil.formatted(signed.sig.R.y.n.toHexString().slice(2));
|
|
15
|
-
const s = EDDSAUtil.formatted(signed.sig.s.n.toHexString().slice(2));
|
|
16
|
-
const result = `0x${x}${y}${s}`;
|
|
17
|
-
return {
|
|
18
|
-
"Rx": signed.sig.R.x.n.toString(),
|
|
19
|
-
"Ry": signed.sig.R.y.n.toString(),
|
|
20
|
-
"s": signed.sig.s.n.toString()
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
static formatted(hexString) {
|
|
24
|
-
const outputLength = 32 * 2;
|
|
25
|
-
const more = outputLength - hexString.length;
|
|
26
|
-
if (more > 0) {
|
|
27
|
-
for (let i = 0; i < more; i++) {
|
|
28
|
-
hexString = "0" + (hexString);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
hexString = hexString.slice(0, outputLength);
|
|
33
|
-
}
|
|
34
|
-
return hexString;
|
|
35
|
-
}
|
|
36
|
-
static generateKeyPair(seed) {
|
|
37
|
-
let bigInt = BigNumber.from(0);
|
|
38
|
-
for (let i = 0; i < seed.length; i++) {
|
|
39
|
-
const item = seed[i];
|
|
40
|
-
const itemBigInt = BigNumber.from(item);
|
|
41
|
-
const tmp = BigNumber.from("256").pow(BigNumber.from(i));
|
|
42
|
-
bigInt = bigInt.add(itemBigInt.mul(tmp));
|
|
43
|
-
}
|
|
44
|
-
const secretKey = bigInt.mod(jubjub.JUBJUB_L);
|
|
45
|
-
const copySecretKey = BigNumber.from(secretKey.toString());
|
|
46
|
-
const B = SignatureScheme.B();
|
|
47
|
-
const publicKey = B.mul(copySecretKey);
|
|
48
|
-
const keyPair = {
|
|
49
|
-
"publicKeyX": publicKey.x.n.toString(),
|
|
50
|
-
"publicKeyY": publicKey.y.n.toString(),
|
|
51
|
-
"secretKey": secretKey.toString()
|
|
52
|
-
};
|
|
53
|
-
return keyPair;
|
|
54
|
-
}
|
|
55
|
-
static pack(publicKeyX, publicKeyY) {
|
|
56
|
-
const P0 = BigNumber.from(publicKeyX);
|
|
57
|
-
const P1 = BigNumber.from(publicKeyY);
|
|
58
|
-
const newPack = babyJub.packPoint(P0, P1);
|
|
59
|
-
return newPack;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from "ethers";
|
|
2
|
-
import { SignatureScheme, bytesToHexString } from "./eddsa";
|
|
3
|
-
import { field } from "../field";
|
|
4
|
-
export class babyJub {
|
|
5
|
-
static packPoint(P0, P1) {
|
|
6
|
-
const packed = SignatureScheme.to_bytes(P1).reverse();
|
|
7
|
-
if (babyJub.lt(P0, BigNumber.from("0"))) {
|
|
8
|
-
packed[0] = packed[0] | 0x80;
|
|
9
|
-
}
|
|
10
|
-
const hexStr = bytesToHexString(packed);
|
|
11
|
-
return hexStr;
|
|
12
|
-
}
|
|
13
|
-
static lt(a, b) {
|
|
14
|
-
const half = field.SNARK_SCALAR_FIELD.div(BigNumber.from("2"));
|
|
15
|
-
const p = field.SNARK_SCALAR_FIELD;
|
|
16
|
-
let aa;
|
|
17
|
-
let bb;
|
|
18
|
-
if (a.gt(half)) {
|
|
19
|
-
aa = a.sub(p);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
aa = a;
|
|
23
|
-
}
|
|
24
|
-
if (b.gt(half)) {
|
|
25
|
-
bb = b.sub(p);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
bb = b;
|
|
29
|
-
}
|
|
30
|
-
return aa.lt(bb);
|
|
31
|
-
}
|
|
32
|
-
static gt(a, b) {
|
|
33
|
-
const half = field.SNARK_SCALAR_FIELD.div(BigNumber.from("2"));
|
|
34
|
-
const p = field.SNARK_SCALAR_FIELD;
|
|
35
|
-
let aa;
|
|
36
|
-
let bb;
|
|
37
|
-
if (a.gt(half)) {
|
|
38
|
-
aa = a.sub(p);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
aa = a;
|
|
42
|
-
}
|
|
43
|
-
if (b.gt(half)) {
|
|
44
|
-
bb = b.sub(p);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
bb = b;
|
|
48
|
-
}
|
|
49
|
-
return aa.gt(bb);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from "ethers";
|
|
2
|
-
import { FQ } from "../field";
|
|
3
|
-
import { Point } from "../jubjub";
|
|
4
|
-
export declare class Signature {
|
|
5
|
-
R: Point;
|
|
6
|
-
s: FQ;
|
|
7
|
-
constructor(R: Point, s: FQ);
|
|
8
|
-
toStr(): string;
|
|
9
|
-
}
|
|
10
|
-
export declare class SignedMessage {
|
|
11
|
-
A: Point;
|
|
12
|
-
sig: Signature;
|
|
13
|
-
msg: BigNumber;
|
|
14
|
-
constructor(A: Point, sig: Signature, msg: BigNumber);
|
|
15
|
-
toStr(): string;
|
|
16
|
-
}
|
|
17
|
-
export declare class SignatureScheme {
|
|
18
|
-
static to_bytes(arg: BigNumber): number[];
|
|
19
|
-
static prehash_message(M: BigNumber): BigNumber;
|
|
20
|
-
static hash_secret_python(k: FQ, arg: BigNumber): BigNumber;
|
|
21
|
-
static B(): Point;
|
|
22
|
-
static sign(msg: BigNumber, key: FQ, B: Point): SignedMessage;
|
|
23
|
-
static as_scalar(point: Point): BigNumber[];
|
|
24
|
-
static hash_public(R: Point, A: Point, M: BigNumber): any;
|
|
25
|
-
}
|
|
26
|
-
export declare function bnToBuf(bn: string): number[];
|
|
27
|
-
export declare function bnToBufWithFixedLength(bn: string, outputLength: number): number[];
|
|
28
|
-
export declare function bufToBn(buf: any): bigint;
|
|
29
|
-
export declare function bytesToHexString(bytes: any): any;
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Implements Pure-EdDSA and Hash-EdDSA
|
|
3
|
-
|
|
4
|
-
The signer has two secret values:
|
|
5
|
-
|
|
6
|
-
* k = Secret key
|
|
7
|
-
* r = Per-(message,key) nonce
|
|
8
|
-
|
|
9
|
-
The signer provides a signature consiting of two values:
|
|
10
|
-
|
|
11
|
-
* R = Point, image of `r*B`
|
|
12
|
-
* s = Image of `r + (k*t)`
|
|
13
|
-
|
|
14
|
-
The signer provides the verifier with their public key:
|
|
15
|
-
|
|
16
|
-
* A = k*B
|
|
17
|
-
|
|
18
|
-
Both the verifier and the signer calculate the common reference string:
|
|
19
|
-
|
|
20
|
-
* t = H(R, A, M)
|
|
21
|
-
|
|
22
|
-
The nonce `r` is secret, and protects the value `s` from revealing the
|
|
23
|
-
signers secret key.
|
|
24
|
-
|
|
25
|
-
For Hash-EdDSA, the message `M` is compressed before H(R,A,M)
|
|
26
|
-
|
|
27
|
-
For further information see: https://ed2519.cr.yp.to/eddsa-20150704.pdf
|
|
28
|
-
*/
|
|
29
|
-
import { BigNumber } from "ethers";
|
|
30
|
-
import { field, FQ } from "../field";
|
|
31
|
-
import { jubjub, Point } from "../jubjub";
|
|
32
|
-
import { sha512 } from "js-sha512";
|
|
33
|
-
import { permunation, PoseidonParams } from "../permutation";
|
|
34
|
-
export class Signature {
|
|
35
|
-
constructor(R, s) {
|
|
36
|
-
this.R = R;
|
|
37
|
-
this.s = s;
|
|
38
|
-
}
|
|
39
|
-
toStr() {
|
|
40
|
-
return `${this.R.x.n} ${this.R.y.n} ${this.s.n}`;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
export class SignedMessage {
|
|
44
|
-
constructor(A, sig, msg) {
|
|
45
|
-
this.A = A;
|
|
46
|
-
this.sig = sig;
|
|
47
|
-
this.msg = msg;
|
|
48
|
-
}
|
|
49
|
-
toStr() {
|
|
50
|
-
return `${this.A.x.n} ${this.A.y.n} ${this.sig.toStr()} ${this.msg.toString()}`;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export class SignatureScheme {
|
|
54
|
-
static to_bytes(arg) {
|
|
55
|
-
const outputLength = 32;
|
|
56
|
-
let bitIntDataItems = bnToBuf(arg.toString());
|
|
57
|
-
const more = outputLength - bitIntDataItems.length;
|
|
58
|
-
if (more > 0) {
|
|
59
|
-
for (let i = 0; i < more; i++) {
|
|
60
|
-
bitIntDataItems = [0].concat(bitIntDataItems);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
bitIntDataItems = bitIntDataItems.slice(0, outputLength);
|
|
65
|
-
}
|
|
66
|
-
bitIntDataItems = bitIntDataItems.reverse();
|
|
67
|
-
return bitIntDataItems;
|
|
68
|
-
}
|
|
69
|
-
/*
|
|
70
|
-
Identity function for message
|
|
71
|
-
|
|
72
|
-
Can be used to truncate the message before hashing it
|
|
73
|
-
as part of the public parameters.
|
|
74
|
-
*/
|
|
75
|
-
static prehash_message(M) {
|
|
76
|
-
return M;
|
|
77
|
-
}
|
|
78
|
-
/*
|
|
79
|
-
Hash the key and message to create `r`, the blinding factor for this signature.
|
|
80
|
-
|
|
81
|
-
If the same `r` value is used more than once, the key for the signature is revealed.
|
|
82
|
-
|
|
83
|
-
From: https://eprint.iacr.org/2015/677.pdf (EdDSA for more curves)
|
|
84
|
-
|
|
85
|
-
Page 3:
|
|
86
|
-
|
|
87
|
-
(Implementation detail: To save time in the computation of `rB`, the signer
|
|
88
|
-
can replace `r` with `r mod L` before computing `rB`.)
|
|
89
|
-
*/
|
|
90
|
-
static hash_secret_python(k, arg) {
|
|
91
|
-
const byteArray0 = this.to_bytes(k.n);
|
|
92
|
-
const byteArray1 = this.to_bytes(arg);
|
|
93
|
-
const sum = byteArray0.concat(byteArray1);
|
|
94
|
-
// let byteArrayHexStr = bytesToHexString(sum)
|
|
95
|
-
const digest1 = sha512.array(new Uint8Array(sum).buffer);
|
|
96
|
-
// let digest1 = createHash('sha512').update .digest("SHA-512", new Uint8Array(sum).buffer)
|
|
97
|
-
let sha512StrItems;
|
|
98
|
-
for (let i = 0; i < digest1.length; i++) {
|
|
99
|
-
const itemInt = digest1[i];
|
|
100
|
-
let st = itemInt.toString(16);
|
|
101
|
-
if (st.length == 1) {
|
|
102
|
-
st = "0" + st;
|
|
103
|
-
}
|
|
104
|
-
sha512StrItems = [st].concat(sha512StrItems);
|
|
105
|
-
}
|
|
106
|
-
const sha512MessageHexStr = sha512StrItems.join("");
|
|
107
|
-
const sha512MessageHexStrBigInt = BigNumber.from("0x" + sha512MessageHexStr);
|
|
108
|
-
const hashed = sha512MessageHexStrBigInt.mod(jubjub.JUBJUB_L);
|
|
109
|
-
return hashed;
|
|
110
|
-
}
|
|
111
|
-
static B() {
|
|
112
|
-
return Point.generate();
|
|
113
|
-
}
|
|
114
|
-
static sign(msg, key, B) {
|
|
115
|
-
const copyKey = new FQ(key.n, key.m);
|
|
116
|
-
const A = B.mul(copyKey.n);
|
|
117
|
-
const M = this.prehash_message(msg);
|
|
118
|
-
const r = this.hash_secret_python(key, M);
|
|
119
|
-
const copy_r = BigNumber.from(r.toString());
|
|
120
|
-
const R = B.mul(copy_r);
|
|
121
|
-
const t = this.hash_public(R, A, M);
|
|
122
|
-
const t_c = t;
|
|
123
|
-
const key_n_t = key.n.mul(t_c);
|
|
124
|
-
const left = r.add(key_n_t);
|
|
125
|
-
const S = left.mod(jubjub.JUBJUB_E);
|
|
126
|
-
const signatureResult = new Signature(R, new FQ(S));
|
|
127
|
-
const signedMessage = new SignedMessage(A, signatureResult, msg);
|
|
128
|
-
return signedMessage;
|
|
129
|
-
}
|
|
130
|
-
static as_scalar(point) {
|
|
131
|
-
return [point.x.n, point.y.n];
|
|
132
|
-
}
|
|
133
|
-
static hash_public(R, A, M) {
|
|
134
|
-
let inputMsg;
|
|
135
|
-
inputMsg = this.as_scalar(R).concat(this.as_scalar(A)).concat([M]);
|
|
136
|
-
const params = new PoseidonParams(field.SNARK_SCALAR_FIELD, 6, 6, 52, "poseidon", BigNumber.from(5), null, null, 128);
|
|
137
|
-
const result = permunation.poseidon(inputMsg, params);
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
export function bnToBuf(bn) {
|
|
142
|
-
let hex = BigInt(bn).toString(16);
|
|
143
|
-
if (hex.length % 2) {
|
|
144
|
-
hex = "0" + hex;
|
|
145
|
-
}
|
|
146
|
-
const len = hex.length / 2;
|
|
147
|
-
const u8 = new Uint8Array(len);
|
|
148
|
-
let i = 0;
|
|
149
|
-
let j = 0;
|
|
150
|
-
while (i < len) {
|
|
151
|
-
u8[i] = parseInt(hex.slice(j, j + 2), 16);
|
|
152
|
-
i += 1;
|
|
153
|
-
j += 2;
|
|
154
|
-
}
|
|
155
|
-
return Array.from(u8);
|
|
156
|
-
}
|
|
157
|
-
export function bnToBufWithFixedLength(bn, outputLength) {
|
|
158
|
-
let hex = BigInt(bn).toString(16);
|
|
159
|
-
if (hex.length % 2) {
|
|
160
|
-
hex = "0" + hex;
|
|
161
|
-
}
|
|
162
|
-
const len = hex.length / 2;
|
|
163
|
-
const u8 = new Uint8Array(len);
|
|
164
|
-
let i = 0;
|
|
165
|
-
let j = 0;
|
|
166
|
-
while (i < len) {
|
|
167
|
-
u8[i] = parseInt(hex.slice(j, j + 2), 16);
|
|
168
|
-
i += 1;
|
|
169
|
-
j += 2;
|
|
170
|
-
}
|
|
171
|
-
let bitIntDataItems = Array.from(u8);
|
|
172
|
-
const more = outputLength - bitIntDataItems.length;
|
|
173
|
-
if (more > 0) {
|
|
174
|
-
for (let i = 0; i < more; i++) {
|
|
175
|
-
bitIntDataItems = [0].concat(bitIntDataItems);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
bitIntDataItems = bitIntDataItems.slice(0, outputLength);
|
|
180
|
-
}
|
|
181
|
-
return bitIntDataItems;
|
|
182
|
-
}
|
|
183
|
-
export function bufToBn(buf) {
|
|
184
|
-
let hex;
|
|
185
|
-
hex = [];
|
|
186
|
-
const u8 = Uint8Array.from(buf);
|
|
187
|
-
u8.forEach(function (i) {
|
|
188
|
-
let h = i.toString(16);
|
|
189
|
-
if (h.length % 2) {
|
|
190
|
-
h = "0" + h;
|
|
191
|
-
}
|
|
192
|
-
hex.push(h);
|
|
193
|
-
});
|
|
194
|
-
return BigInt("0x" + hex.join(""));
|
|
195
|
-
}
|
|
196
|
-
export function bytesToHexString(bytes) {
|
|
197
|
-
let strItems;
|
|
198
|
-
strItems = [];
|
|
199
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
200
|
-
const item = bytes[i];
|
|
201
|
-
let st = item.toString(16);
|
|
202
|
-
if (st.length == 1) {
|
|
203
|
-
st = "0" + st;
|
|
204
|
-
}
|
|
205
|
-
// st = st.toUpperCase()
|
|
206
|
-
strItems.push(st);
|
|
207
|
-
}
|
|
208
|
-
const strItemsJoined = strItems.join("");
|
|
209
|
-
return strItemsJoined;
|
|
210
|
-
}
|