@helios-lang/effect 0.1.15 → 0.3.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/Cardano/CoinSelection.js +130 -0
- package/dist/Cardano/CoinSelection.js.map +1 -0
- package/dist/{Ledger → Cardano/Ledger}/Address.js +31 -21
- package/dist/Cardano/Ledger/Address.js.map +1 -0
- package/dist/{Ledger → Cardano/Ledger}/AssetClass.js +16 -11
- package/dist/Cardano/Ledger/AssetClass.js.map +1 -0
- package/dist/Cardano/Ledger/Assets.js +235 -0
- package/dist/Cardano/Ledger/Assets.js.map +1 -0
- package/dist/Cardano/Ledger/Credential.js +53 -0
- package/dist/Cardano/Ledger/Credential.js.map +1 -0
- package/dist/Cardano/Ledger/DCert.js +117 -0
- package/dist/Cardano/Ledger/DCert.js.map +1 -0
- package/dist/Cardano/Ledger/DatumHash.js +25 -0
- package/dist/Cardano/Ledger/DatumHash.js.map +1 -0
- package/dist/Cardano/Ledger/MintingPolicy.js +40 -0
- package/dist/Cardano/Ledger/MintingPolicy.js.map +1 -0
- package/dist/Cardano/Ledger/NativeScript.js +140 -0
- package/dist/Cardano/Ledger/NativeScript.js.map +1 -0
- package/dist/Cardano/Ledger/PubKey.js +24 -0
- package/dist/Cardano/Ledger/PubKey.js.map +1 -0
- package/dist/{Ledger → Cardano/Ledger}/PubKeyHash.js +5 -5
- package/dist/Cardano/Ledger/PubKeyHash.js.map +1 -0
- package/dist/Cardano/Ledger/Redeemer.js +155 -0
- package/dist/Cardano/Ledger/Redeemer.js.map +1 -0
- package/dist/Cardano/Ledger/RewardAddress.js +93 -0
- package/dist/Cardano/Ledger/RewardAddress.js.map +1 -0
- package/dist/Cardano/Ledger/Signature.js +23 -0
- package/dist/Cardano/Ledger/Signature.js.map +1 -0
- package/dist/Cardano/Ledger/Tx.js +498 -0
- package/dist/Cardano/Ledger/Tx.js.map +1 -0
- package/dist/Cardano/Ledger/TxHash.js +38 -0
- package/dist/Cardano/Ledger/TxHash.js.map +1 -0
- package/dist/Cardano/Ledger/TxOutput.js +167 -0
- package/dist/Cardano/Ledger/TxOutput.js.map +1 -0
- package/dist/{Ledger → Cardano/Ledger}/TxOutputDatum.js +44 -8
- package/dist/Cardano/Ledger/TxOutputDatum.js.map +1 -0
- package/dist/Cardano/Ledger/UTxO.js +100 -0
- package/dist/Cardano/Ledger/UTxO.js.map +1 -0
- package/dist/{Ledger → Cardano/Ledger}/UTxORef.js +28 -6
- package/dist/Cardano/Ledger/UTxORef.js.map +1 -0
- package/dist/{Ledger → Cardano/Ledger}/ValidatorHash.js +5 -5
- package/dist/Cardano/Ledger/ValidatorHash.js.map +1 -0
- package/dist/{Ledger → Cardano/Ledger}/index.js +6 -0
- package/dist/Cardano/Ledger/index.js.map +1 -0
- package/dist/Cardano/Network/IsMainnet.js.map +1 -0
- package/dist/{Network → Cardano/Network}/Params.js +27 -3
- package/dist/Cardano/Network/Params.js.map +1 -0
- package/dist/Cardano/Network/UTxO.js +20 -0
- package/dist/Cardano/Network/UTxO.js.map +1 -0
- package/dist/Cardano/Network/UTxOsAt.js +4 -0
- package/dist/Cardano/Network/UTxOsAt.js.map +1 -0
- package/dist/Cardano/Network/errors.js +33 -0
- package/dist/Cardano/Network/errors.js.map +1 -0
- package/dist/{Network → Cardano/Network}/index.js +1 -0
- package/dist/Cardano/Network/index.js.map +1 -0
- package/dist/Cardano/TxBuilder.js +963 -0
- package/dist/Cardano/TxBuilder.js.map +1 -0
- package/dist/Cardano/Uplc/Builtins.js +1820 -0
- package/dist/Cardano/Uplc/Builtins.js.map +1 -0
- package/dist/Cardano/Uplc/Cek.js +716 -0
- package/dist/Cardano/Uplc/Cek.js.map +1 -0
- package/dist/Cardano/Uplc/Cost.js +956 -0
- package/dist/Cardano/Uplc/Cost.js.map +1 -0
- package/dist/{Uplc → Cardano/Uplc}/Data.js +143 -22
- package/dist/Cardano/Uplc/Data.js.map +1 -0
- package/dist/Cardano/Uplc/Script.js +118 -0
- package/dist/Cardano/Uplc/Script.js.map +1 -0
- package/dist/Cardano/Uplc/ScriptContext.js +259 -0
- package/dist/Cardano/Uplc/ScriptContext.js.map +1 -0
- package/dist/Cardano/Uplc/Term.js +384 -0
- package/dist/Cardano/Uplc/Term.js.map +1 -0
- package/dist/Cardano/Uplc/Type.js +131 -0
- package/dist/Cardano/Uplc/Type.js.map +1 -0
- package/dist/Cardano/Uplc/Value.js +315 -0
- package/dist/Cardano/Uplc/Value.js.map +1 -0
- package/dist/Cardano/Uplc/index.js +7 -0
- package/dist/Cardano/Uplc/index.js.map +1 -0
- package/dist/Cardano/Wallet.js +48 -0
- package/dist/Cardano/Wallet.js.map +1 -0
- package/dist/Cardano/index.js +7 -0
- package/dist/Cardano/index.js.map +1 -0
- package/dist/{internal → Codecs}/Base32.js +2 -2
- package/dist/Codecs/Base32.js.map +1 -0
- package/dist/{Bech32.js → Codecs/Bech32.js} +2 -2
- package/dist/Codecs/Bech32.js.map +1 -0
- package/dist/Codecs/BigEndian.js.map +1 -0
- package/dist/Codecs/Bits.js.map +1 -0
- package/dist/{internal → Codecs}/Bytes.js +23 -12
- package/dist/Codecs/Bytes.js.map +1 -0
- package/dist/{Cbor.js → Codecs/Cbor.js} +559 -328
- package/dist/Codecs/Cbor.js.map +1 -0
- package/dist/{internal → Codecs}/Flat.js +16 -0
- package/dist/Codecs/Flat.js.map +1 -0
- package/dist/Codecs/Float.js.map +1 -0
- package/dist/Codecs/LittleEndian.js +31 -0
- package/dist/Codecs/LittleEndian.js.map +1 -0
- package/dist/Codecs/Uint64.js +89 -0
- package/dist/Codecs/Uint64.js.map +1 -0
- package/dist/{internal → Codecs}/Utf8.js +7 -2
- package/dist/Codecs/Utf8.js.map +1 -0
- package/dist/Codecs/ZigZag.js +26 -0
- package/dist/Codecs/ZigZag.js.map +1 -0
- package/dist/Codecs/index.js +8 -0
- package/dist/Codecs/index.js.map +1 -0
- package/dist/Crypto/Bip32.js +131 -0
- package/dist/Crypto/Bip32.js.map +1 -0
- package/dist/Crypto/Bip39.js +2176 -0
- package/dist/Crypto/Bip39.js.map +1 -0
- package/dist/Crypto/Blake2b.js +156 -0
- package/dist/Crypto/Blake2b.js.map +1 -0
- package/dist/Crypto/Curve.js +92 -0
- package/dist/Crypto/Curve.js.map +1 -0
- package/dist/Crypto/Ed25519.js +323 -0
- package/dist/Crypto/Ed25519.js.map +1 -0
- package/dist/Crypto/EdDSA.js +222 -0
- package/dist/Crypto/EdDSA.js.map +1 -0
- package/dist/Crypto/Field.js +323 -0
- package/dist/Crypto/Field.js.map +1 -0
- package/dist/Crypto/Hmac.js +51 -0
- package/dist/Crypto/Hmac.js.map +1 -0
- package/dist/Crypto/Keccak.js +167 -0
- package/dist/Crypto/Keccak.js.map +1 -0
- package/dist/Crypto/Pbkdf2.js +45 -0
- package/dist/Crypto/Pbkdf2.js.map +1 -0
- package/dist/Crypto/Sha2_256.js +200 -0
- package/dist/Crypto/Sha2_256.js.map +1 -0
- package/dist/Crypto/Sha2_512.js +264 -0
- package/dist/Crypto/Sha2_512.js.map +1 -0
- package/dist/Crypto/Sha3_256.js +10 -0
- package/dist/Crypto/Sha3_256.js.map +1 -0
- package/dist/Crypto/errors.js +9 -0
- package/dist/Crypto/errors.js.map +1 -0
- package/dist/Crypto/index.js +12 -0
- package/dist/Crypto/index.js.map +1 -0
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/package.json +24 -6
- package/tsconfig.build.json +1 -1
- package/types/Cardano/CoinSelection.d.ts +26 -0
- package/types/Cardano/CoinSelection.d.ts.map +1 -0
- package/types/{Ledger → Cardano/Ledger}/Address.d.ts +8 -7
- package/types/Cardano/Ledger/Address.d.ts.map +1 -0
- package/types/{Ledger → Cardano/Ledger}/AssetClass.d.ts +2 -2
- package/types/Cardano/Ledger/AssetClass.d.ts.map +1 -0
- package/types/Cardano/Ledger/Assets.d.ts +114 -0
- package/types/Cardano/Ledger/Assets.d.ts.map +1 -0
- package/types/{Ledger → Cardano/Ledger}/Credential.d.ts +10 -4
- package/types/Cardano/Ledger/Credential.d.ts.map +1 -0
- package/types/Cardano/Ledger/DCert.d.ts +40 -0
- package/types/Cardano/Ledger/DCert.d.ts.map +1 -0
- package/types/{Ledger → Cardano/Ledger}/DatumHash.d.ts +6 -5
- package/types/Cardano/Ledger/DatumHash.d.ts.map +1 -0
- package/types/{Ledger → Cardano/Ledger}/MintingPolicy.d.ts +11 -8
- package/types/Cardano/Ledger/MintingPolicy.d.ts.map +1 -0
- package/types/Cardano/Ledger/NativeScript.d.ts +105 -0
- package/types/Cardano/Ledger/NativeScript.d.ts.map +1 -0
- package/types/Cardano/Ledger/PubKey.d.ts +45 -0
- package/types/Cardano/Ledger/PubKey.d.ts.map +1 -0
- package/types/{Ledger → Cardano/Ledger}/PubKeyHash.d.ts +5 -5
- package/types/Cardano/Ledger/PubKeyHash.d.ts.map +1 -0
- package/types/Cardano/Ledger/Redeemer.d.ts +303 -0
- package/types/Cardano/Ledger/Redeemer.d.ts.map +1 -0
- package/types/Cardano/Ledger/RewardAddress.d.ts +60 -0
- package/types/Cardano/Ledger/RewardAddress.d.ts.map +1 -0
- package/types/Cardano/Ledger/Signature.d.ts +13 -0
- package/types/Cardano/Ledger/Signature.d.ts.map +1 -0
- package/types/Cardano/Ledger/Tx.d.ts +375 -0
- package/types/Cardano/Ledger/Tx.d.ts.map +1 -0
- package/types/{Ledger → Cardano/Ledger}/TxHash.d.ts +35 -5
- package/types/Cardano/Ledger/TxHash.d.ts.map +1 -0
- package/types/Cardano/Ledger/TxOutput.d.ts +438 -0
- package/types/Cardano/Ledger/TxOutput.d.ts.map +1 -0
- package/types/Cardano/Ledger/TxOutputDatum.d.ts +98 -0
- package/types/Cardano/Ledger/TxOutputDatum.d.ts.map +1 -0
- package/types/Cardano/Ledger/UTxO.d.ts +1420 -0
- package/types/Cardano/Ledger/UTxO.d.ts.map +1 -0
- package/types/Cardano/Ledger/UTxORef.d.ts +222 -0
- package/types/Cardano/Ledger/UTxORef.d.ts.map +1 -0
- package/types/{Ledger → Cardano/Ledger}/ValidatorHash.d.ts +5 -5
- package/types/Cardano/Ledger/ValidatorHash.d.ts.map +1 -0
- package/types/{Ledger → Cardano/Ledger}/index.d.ts +6 -0
- package/types/Cardano/Ledger/index.d.ts.map +1 -0
- package/types/Cardano/Network/IsMainnet.d.ts.map +1 -0
- package/types/{Network → Cardano/Network}/Params.d.ts +32 -4
- package/types/Cardano/Network/Params.d.ts.map +1 -0
- package/types/Cardano/Network/UTxO.d.ts +15 -0
- package/types/Cardano/Network/UTxO.d.ts.map +1 -0
- package/types/Cardano/Network/UTxOsAt.d.ts +9 -0
- package/types/Cardano/Network/UTxOsAt.d.ts.map +1 -0
- package/types/Cardano/Network/errors.d.ts +39 -0
- package/types/Cardano/Network/errors.d.ts.map +1 -0
- package/types/{Network → Cardano/Network}/index.d.ts +1 -0
- package/types/Cardano/Network/index.d.ts.map +1 -0
- package/types/Cardano/TxBuilder.d.ts +232 -0
- package/types/Cardano/TxBuilder.d.ts.map +1 -0
- package/types/Cardano/Uplc/Builtins.d.ts +163 -0
- package/types/Cardano/Uplc/Builtins.d.ts.map +1 -0
- package/types/Cardano/Uplc/Cek.d.ts +165 -0
- package/types/Cardano/Uplc/Cek.d.ts.map +1 -0
- package/types/Cardano/Uplc/Cost.d.ts +93 -0
- package/types/Cardano/Uplc/Cost.d.ts.map +1 -0
- package/types/{Uplc → Cardano/Uplc}/Data.d.ts +149 -15
- package/types/Cardano/Uplc/Data.d.ts.map +1 -0
- package/types/Cardano/Uplc/Script.d.ts +87 -0
- package/types/Cardano/Uplc/Script.d.ts.map +1 -0
- package/types/Cardano/Uplc/ScriptContext.d.ts +21 -0
- package/types/Cardano/Uplc/ScriptContext.d.ts.map +1 -0
- package/types/Cardano/Uplc/Term.d.ts +454 -0
- package/types/Cardano/Uplc/Term.d.ts.map +1 -0
- package/types/Cardano/Uplc/Type.d.ts +29 -0
- package/types/Cardano/Uplc/Type.d.ts.map +1 -0
- package/types/Cardano/Uplc/Value.d.ts +152 -0
- package/types/Cardano/Uplc/Value.d.ts.map +1 -0
- package/types/Cardano/Uplc/index.d.ts +7 -0
- package/types/Cardano/Uplc/index.d.ts.map +1 -0
- package/types/Cardano/Wallet.d.ts +73 -0
- package/types/Cardano/Wallet.d.ts.map +1 -0
- package/types/Cardano/index.d.ts +7 -0
- package/types/Cardano/index.d.ts.map +1 -0
- package/types/Codecs/Base32.d.ts.map +1 -0
- package/types/Codecs/Bech32.d.ts.map +1 -0
- package/types/Codecs/BigEndian.d.ts.map +1 -0
- package/types/Codecs/Bits.d.ts.map +1 -0
- package/types/{internal → Codecs}/Bytes.d.ts +7 -6
- package/types/Codecs/Bytes.d.ts.map +1 -0
- package/types/{Cbor.d.ts → Codecs/Cbor.d.ts} +77 -55
- package/types/Codecs/Cbor.d.ts.map +1 -0
- package/types/{internal → Codecs}/Flat.d.ts +2 -0
- package/types/Codecs/Flat.d.ts.map +1 -0
- package/types/Codecs/Float.d.ts.map +1 -0
- package/types/Codecs/LittleEndian.d.ts +19 -0
- package/types/Codecs/LittleEndian.d.ts.map +1 -0
- package/types/Codecs/Uint64.d.ts +16 -0
- package/types/Codecs/Uint64.d.ts.map +1 -0
- package/types/{internal → Codecs}/Utf8.d.ts +2 -2
- package/types/Codecs/Utf8.d.ts.map +1 -0
- package/types/Codecs/ZigZag.d.ts +3 -0
- package/types/Codecs/ZigZag.d.ts.map +1 -0
- package/types/Codecs/index.d.ts +8 -0
- package/types/Codecs/index.d.ts.map +1 -0
- package/types/Crypto/Bip32.d.ts +29 -0
- package/types/Crypto/Bip32.d.ts.map +1 -0
- package/types/Crypto/Bip39.d.ts +43 -0
- package/types/Crypto/Bip39.d.ts.map +1 -0
- package/types/Crypto/Blake2b.d.ts +16 -0
- package/types/Crypto/Blake2b.d.ts.map +1 -0
- package/types/Crypto/Curve.d.ts +161 -0
- package/types/Crypto/Curve.d.ts.map +1 -0
- package/types/Crypto/Ed25519.d.ts +155 -0
- package/types/Crypto/Ed25519.d.ts.map +1 -0
- package/types/Crypto/EdDSA.d.ts +159 -0
- package/types/Crypto/EdDSA.d.ts.map +1 -0
- package/types/Crypto/Field.d.ts +273 -0
- package/types/Crypto/Field.d.ts.map +1 -0
- package/types/Crypto/Hmac.d.ts +20 -0
- package/types/Crypto/Hmac.d.ts.map +1 -0
- package/types/Crypto/Keccak.d.ts +16 -0
- package/types/Crypto/Keccak.d.ts.map +1 -0
- package/types/Crypto/Pbkdf2.d.ts +15 -0
- package/types/Crypto/Pbkdf2.d.ts.map +1 -0
- package/types/Crypto/Sha2_256.d.ts +36 -0
- package/types/Crypto/Sha2_256.d.ts.map +1 -0
- package/types/Crypto/Sha2_512.d.ts +31 -0
- package/types/Crypto/Sha2_512.d.ts.map +1 -0
- package/types/Crypto/Sha3_256.d.ts +8 -0
- package/types/Crypto/Sha3_256.d.ts.map +1 -0
- package/types/Crypto/errors.d.ts +10 -0
- package/types/Crypto/errors.d.ts.map +1 -0
- package/types/Crypto/index.d.ts +12 -0
- package/types/Crypto/index.d.ts.map +1 -0
- package/types/index.d.ts +3 -5
- package/types/index.d.ts.map +1 -1
- package/dist/Address.js +0 -13
- package/dist/Address.js.map +0 -1
- package/dist/Bech32.js.map +0 -1
- package/dist/Cbor.js.map +0 -1
- package/dist/Ledger/Address.js.map +0 -1
- package/dist/Ledger/AssetClass.js.map +0 -1
- package/dist/Ledger/Assets.js +0 -120
- package/dist/Ledger/Assets.js.map +0 -1
- package/dist/Ledger/Credential.js +0 -17
- package/dist/Ledger/Credential.js.map +0 -1
- package/dist/Ledger/DatumHash.js +0 -21
- package/dist/Ledger/DatumHash.js.map +0 -1
- package/dist/Ledger/IsMainnet.js +0 -4
- package/dist/Ledger/IsMainnet.js.map +0 -1
- package/dist/Ledger/MintingPolicy.js +0 -45
- package/dist/Ledger/MintingPolicy.js.map +0 -1
- package/dist/Ledger/NetworkParams.js +0 -40
- package/dist/Ledger/NetworkParams.js.map +0 -1
- package/dist/Ledger/PubKeyHash.js.map +0 -1
- package/dist/Ledger/TxHash.js +0 -23
- package/dist/Ledger/TxHash.js.map +0 -1
- package/dist/Ledger/TxId.js +0 -23
- package/dist/Ledger/TxId.js.map +0 -1
- package/dist/Ledger/TxInput.js +0 -51
- package/dist/Ledger/TxInput.js.map +0 -1
- package/dist/Ledger/TxOutput.js +0 -118
- package/dist/Ledger/TxOutput.js.map +0 -1
- package/dist/Ledger/TxOutputDatum.js.map +0 -1
- package/dist/Ledger/TxOutputId.js +0 -55
- package/dist/Ledger/TxOutputId.js.map +0 -1
- package/dist/Ledger/UTxO.js +0 -43
- package/dist/Ledger/UTxO.js.map +0 -1
- package/dist/Ledger/UTxORef.js.map +0 -1
- package/dist/Ledger/ValidatorHash.js.map +0 -1
- package/dist/Ledger/index.js.map +0 -1
- package/dist/Network/IsMainnet.js.map +0 -1
- package/dist/Network/Params.js.map +0 -1
- package/dist/Network/UTxOsAt.js +0 -4
- package/dist/Network/UTxOsAt.js.map +0 -1
- package/dist/Network/errors.js +0 -16
- package/dist/Network/errors.js.map +0 -1
- package/dist/Network/index.js.map +0 -1
- package/dist/Uplc/Cek.js +0 -3
- package/dist/Uplc/Cek.js.map +0 -1
- package/dist/Uplc/Data.js.map +0 -1
- package/dist/Uplc/DataSchema.js +0 -118
- package/dist/Uplc/DataSchema.js.map +0 -1
- package/dist/Uplc/Primitive.js +0 -23
- package/dist/Uplc/Primitive.js.map +0 -1
- package/dist/Uplc/index.js +0 -3
- package/dist/Uplc/index.js.map +0 -1
- package/dist/internal/Base32.js.map +0 -1
- package/dist/internal/BigEndian.js.map +0 -1
- package/dist/internal/Bits.js.map +0 -1
- package/dist/internal/Bytes.js.map +0 -1
- package/dist/internal/Flat.js.map +0 -1
- package/dist/internal/Float.js.map +0 -1
- package/dist/internal/Utf8.js.map +0 -1
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.check.tsbuildinfo +0 -1
- package/tsconfig.tsbuildinfo +0 -1
- package/types/Address.d.ts +0 -5
- package/types/Address.d.ts.map +0 -1
- package/types/Bech32.d.ts.map +0 -1
- package/types/Cbor.d.ts.map +0 -1
- package/types/Ledger/Address.d.ts.map +0 -1
- package/types/Ledger/AssetClass.d.ts.map +0 -1
- package/types/Ledger/Assets.d.ts +0 -70
- package/types/Ledger/Assets.d.ts.map +0 -1
- package/types/Ledger/Credential.d.ts.map +0 -1
- package/types/Ledger/DatumHash.d.ts.map +0 -1
- package/types/Ledger/IsMainnet.d.ts +0 -6
- package/types/Ledger/IsMainnet.d.ts.map +0 -1
- package/types/Ledger/MintingPolicy.d.ts.map +0 -1
- package/types/Ledger/NetworkParams.d.ts +0 -40
- package/types/Ledger/NetworkParams.d.ts.map +0 -1
- package/types/Ledger/PubKeyHash.d.ts.map +0 -1
- package/types/Ledger/TxHash.d.ts.map +0 -1
- package/types/Ledger/TxId.d.ts +0 -70
- package/types/Ledger/TxId.d.ts.map +0 -1
- package/types/Ledger/TxInput.d.ts +0 -55
- package/types/Ledger/TxInput.d.ts.map +0 -1
- package/types/Ledger/TxOutput.d.ts +0 -63
- package/types/Ledger/TxOutput.d.ts.map +0 -1
- package/types/Ledger/TxOutputDatum.d.ts +0 -41
- package/types/Ledger/TxOutputDatum.d.ts.map +0 -1
- package/types/Ledger/TxOutputId.d.ts +0 -133
- package/types/Ledger/TxOutputId.d.ts.map +0 -1
- package/types/Ledger/UTxO.d.ts +0 -55
- package/types/Ledger/UTxO.d.ts.map +0 -1
- package/types/Ledger/UTxORef.d.ts +0 -133
- package/types/Ledger/UTxORef.d.ts.map +0 -1
- package/types/Ledger/ValidatorHash.d.ts.map +0 -1
- package/types/Ledger/index.d.ts.map +0 -1
- package/types/Network/IsMainnet.d.ts.map +0 -1
- package/types/Network/Params.d.ts.map +0 -1
- package/types/Network/UTxOsAt.d.ts +0 -9
- package/types/Network/UTxOsAt.d.ts.map +0 -1
- package/types/Network/errors.d.ts +0 -18
- package/types/Network/errors.d.ts.map +0 -1
- package/types/Network/index.d.ts.map +0 -1
- package/types/Uplc/Cek.d.ts +0 -72
- package/types/Uplc/Cek.d.ts.map +0 -1
- package/types/Uplc/Data.d.ts.map +0 -1
- package/types/Uplc/DataSchema.d.ts +0 -227
- package/types/Uplc/DataSchema.d.ts.map +0 -1
- package/types/Uplc/Primitive.d.ts +0 -26
- package/types/Uplc/Primitive.d.ts.map +0 -1
- package/types/Uplc/index.d.ts +0 -3
- package/types/Uplc/index.d.ts.map +0 -1
- package/types/internal/Base32.d.ts.map +0 -1
- package/types/internal/BigEndian.d.ts.map +0 -1
- package/types/internal/Bits.d.ts.map +0 -1
- package/types/internal/Bytes.d.ts.map +0 -1
- package/types/internal/Flat.d.ts.map +0 -1
- package/types/internal/Float.d.ts.map +0 -1
- package/types/internal/Utf8.d.ts.map +0 -1
- /package/dist/{Network → Cardano/Network}/IsMainnet.js +0 -0
- /package/dist/{internal → Codecs}/BigEndian.js +0 -0
- /package/dist/{internal → Codecs}/Bits.js +0 -0
- /package/dist/{internal → Codecs}/Float.js +0 -0
- /package/types/{Network → Cardano/Network}/IsMainnet.d.ts +0 -0
- /package/types/{internal → Codecs}/Base32.d.ts +0 -0
- /package/types/{Bech32.d.ts → Codecs/Bech32.d.ts} +0 -0
- /package/types/{internal → Codecs}/BigEndian.d.ts +0 -0
- /package/types/{internal → Codecs}/Bits.d.ts +0 -0
- /package/types/{internal → Codecs}/Float.d.ts +0 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { Data, Either } from "effect";
|
|
2
|
+
import { CurveHelper } from "./Curve.js";
|
|
3
|
+
import * as Sha2_512 from "./Sha2_512.js";
|
|
4
|
+
export class BadPrivateKeyLength extends Data.TaggedError("Crypto.EdDSA.BadPrivateKeyLength") {
|
|
5
|
+
constructor(privateKey) {
|
|
6
|
+
super({
|
|
7
|
+
message: `expected extended privateKey with a length of 64 bytes, this privateKey is ${privateKey.length} bytes long (hint: pass hashPrivateKey = true)`
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class BadSignatureLength extends Data.TaggedError("Crypto.EdDSA.BadSignatureLength") {
|
|
12
|
+
constructor(signature) {
|
|
13
|
+
super({ message: `unexpected signature length ${signature.length}` });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class BadPublicKeyLength extends Data.TaggedError("Crypto.EdDSA.BadPublicKeyLength") {
|
|
17
|
+
constructor(publicKey) {
|
|
18
|
+
super({ message: `unexpected publicKey length ${publicKey.length}` });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Edwards Digital Signing Algorithm
|
|
23
|
+
*
|
|
24
|
+
* Symbols based on the book "Elliptic Curves in Cryptography" by I.F. Blake, G. Seroussi and N.P. Smart
|
|
25
|
+
* See page 4 for an overview of the DSA algorithm.
|
|
26
|
+
* This book along with the first few sections of "Cryptography: An Introduction" by N.P. Smart are
|
|
27
|
+
* recommended reads in order to understand better the concepts of "scalars" and "CurvePoint" and
|
|
28
|
+
* their arithmatic over finite fields.
|
|
29
|
+
*
|
|
30
|
+
* Notation:
|
|
31
|
+
* privateKey: 64 bytes, first 32 bytes form the scalar integer `x`, the latter bytes are used for private nonce generation
|
|
32
|
+
* publicKey: 32 bytes
|
|
33
|
+
* x: bigint scalar representation of privateKey
|
|
34
|
+
* g: generator BASE point
|
|
35
|
+
* h: CurvePoint representation of publicKey
|
|
36
|
+
* m: (hashed) message, kept as bytes
|
|
37
|
+
* k: a practically random number, created by applying a one-way function to the message and part of the private key
|
|
38
|
+
* a: first part of signature
|
|
39
|
+
* b: second part of signature
|
|
40
|
+
* `*`: group multiplication of a CurvePoint by a scalar integer, or multiplication of 2 scalars (depending on context)
|
|
41
|
+
* `+`: CurvePoint addition or scalar addition depending on context
|
|
42
|
+
* `.`: byte concatenation
|
|
43
|
+
* `[n:N]`: slice bytes
|
|
44
|
+
* `f(a,h,m)`: a one-way function for publicy known information
|
|
45
|
+
* `mod()`: take modulo of a scalar wrt. the order of the Curve
|
|
46
|
+
* `hash()`: Sha512 hash function
|
|
47
|
+
* `encodeScalar`: turn a scalar integer into bytes
|
|
48
|
+
* `decodeScalar`: turn bytes into a scalar integer
|
|
49
|
+
* `encodePoint`: turn a CurvePoint into bytes
|
|
50
|
+
* `decodePoint`: turn bytes into a CurvePoint
|
|
51
|
+
*
|
|
52
|
+
* The algorithm below is approached from an additive perspective.
|
|
53
|
+
*
|
|
54
|
+
* 1. Generate 64 random private key bytes
|
|
55
|
+
* privateKey = random(64)
|
|
56
|
+
* 2. Generate the associated scalar `x`:
|
|
57
|
+
* x = decodeScalar(privateKey[0:32])
|
|
58
|
+
* 3. Generate public key CurvePoint:
|
|
59
|
+
* h = g*x
|
|
60
|
+
* 4. Encode public key:
|
|
61
|
+
* publicKey = encodePoint(h)
|
|
62
|
+
* 5. Create first part of a signature:
|
|
63
|
+
* k = decodeScalar(hash(privateKey[32:64] . m))
|
|
64
|
+
* a = g*k
|
|
65
|
+
* signature[0:32] = encodePoint(a)
|
|
66
|
+
* 6. Create second part of a signature:
|
|
67
|
+
* f(a,h,m) = decodeScalar(hash(signature[0:32] . publicKey . m))
|
|
68
|
+
* b = mod(k + f(a,h,m)*x)
|
|
69
|
+
* signature[32:64] = encodeScalar(b)
|
|
70
|
+
* 7. Verify a signature:
|
|
71
|
+
* a = decodePoint(signature[0:32])
|
|
72
|
+
* b = decodeScalar(signature[32:64])
|
|
73
|
+
* h = decodePoint(publicKey)
|
|
74
|
+
* f(a,h,m) = decodeScalar(hash(signature[0:32] . publicKey . m))
|
|
75
|
+
* g*b === a + h*f(a,h,m)
|
|
76
|
+
*
|
|
77
|
+
* We can show that this works by substituting the private calculations done upon signing (the arithmatic takes care of the mod() operator):
|
|
78
|
+
* g*(k + f(a,h,m)*x) === g*k + h*f(a,h,m)
|
|
79
|
+
* g*k + g*x*f(a,h,m) === g*k + h*f(a,h,m)
|
|
80
|
+
*
|
|
81
|
+
* We know that `g*x == h`, QED.
|
|
82
|
+
*
|
|
83
|
+
* The arithmatic details are handled by the CurvePoint class
|
|
84
|
+
*/
|
|
85
|
+
export class EdDSA {
|
|
86
|
+
curve;
|
|
87
|
+
G;
|
|
88
|
+
Z;
|
|
89
|
+
codec;
|
|
90
|
+
/**
|
|
91
|
+
* @param curve
|
|
92
|
+
*/
|
|
93
|
+
constructor(curve, G, Z, pointCodec) {
|
|
94
|
+
this.curve = curve;
|
|
95
|
+
this.G = G;
|
|
96
|
+
this.Z = Z;
|
|
97
|
+
this.codec = pointCodec;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Combination hash and decodeCurveInt
|
|
101
|
+
* @param bytes
|
|
102
|
+
* @returns
|
|
103
|
+
*/
|
|
104
|
+
oneWay(...chunks) {
|
|
105
|
+
const l = chunks.reduce((prev, chunk) => chunk.length + prev, 0);
|
|
106
|
+
const bytes = new Uint8Array(l);
|
|
107
|
+
let offset = 0;
|
|
108
|
+
chunks.forEach((chunk) => {
|
|
109
|
+
bytes.set(chunk, offset);
|
|
110
|
+
offset += chunk.length;
|
|
111
|
+
});
|
|
112
|
+
return Either.getOrThrow(this.codec.decodeScalar(Sha2_512.hashSync(bytes)));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @param privateKeyBytes
|
|
116
|
+
* @param hashPrivateKey
|
|
117
|
+
* Defaults to true, set to false
|
|
118
|
+
* when used in Bip32 algorithm
|
|
119
|
+
* @returns 32 byte public key.
|
|
120
|
+
*/
|
|
121
|
+
derivePublicKey(privateKeyBytes, hashPrivateKey = true) {
|
|
122
|
+
if (hashPrivateKey) {
|
|
123
|
+
privateKeyBytes = Sha2_512.hashSync(privateKeyBytes);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
if (privateKeyBytes.length != 64) {
|
|
127
|
+
return Either.left(new BadPrivateKeyLength(privateKeyBytes));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// we know that `privateKeyBytes` isn't empty, so `decodePrivateKey()` should never throw an error
|
|
131
|
+
const privateKey = Either.getOrThrow(this.codec.decodePrivateKey(privateKeyBytes));
|
|
132
|
+
const curveHelper = new CurveHelper(this.curve);
|
|
133
|
+
const publicKey = curveHelper.scale(this.curve.fromAffine(this.G), privateKey);
|
|
134
|
+
const publicKeyBytes = this.codec.encodePoint(this.curve.toAffine(publicKey));
|
|
135
|
+
return Either.right(publicKeyBytes);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Sign the message.
|
|
139
|
+
* Even though this implementation isn't constant time, it isn't vulnerable to a timing attack (see detailed notes in implementation below)
|
|
140
|
+
* @param message
|
|
141
|
+
* @param privateKeyBytes
|
|
142
|
+
* @param hashPrivateKey
|
|
143
|
+
* Defaults to true, Bip32 passes this as false
|
|
144
|
+
* @returns
|
|
145
|
+
* 64 byte signature.
|
|
146
|
+
*/
|
|
147
|
+
sign(message, privateKeyBytes, hashPrivateKey = true) {
|
|
148
|
+
if (hashPrivateKey) {
|
|
149
|
+
privateKeyBytes = Sha2_512.hashSync(privateKeyBytes);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
if (privateKeyBytes.length != 64) {
|
|
153
|
+
return Either.left(new BadPrivateKeyLength(privateKeyBytes));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Extract privateKey as integer
|
|
157
|
+
// (Not vulnerable to timing attack because there is no mixing with the message,
|
|
158
|
+
// so always takes the same amount of time for the same privateKey)
|
|
159
|
+
const privateKey = Either.getOrThrow(this.codec.decodePrivateKey(privateKeyBytes));
|
|
160
|
+
const curveHelper = new CurveHelper(this.curve);
|
|
161
|
+
// For convenience calculate publicKey here
|
|
162
|
+
// (Not vulnerable to timing attack because there is no mixing with the message,
|
|
163
|
+
// so always takes the same amount of time for the same privateKey)
|
|
164
|
+
const publicKey = curveHelper.scale(this.curve.fromAffine(this.G), privateKey);
|
|
165
|
+
const publicKeyBytes = this.codec.encodePoint(this.curve.toAffine(publicKey));
|
|
166
|
+
// Generate a practically random number
|
|
167
|
+
// (Not vulnerable to timing attack because sha2_512 runtime only depends on message length,
|
|
168
|
+
// so timing doesn't expose any bytes of the privateKey)
|
|
169
|
+
const k = this.oneWay(privateKeyBytes.slice(32, 64), message);
|
|
170
|
+
// First part of the signature
|
|
171
|
+
// (Not vulnerable to timing attack because variations in the message create huge random variations in k)
|
|
172
|
+
const a = curveHelper.scale(this.curve.fromAffine(this.G), k);
|
|
173
|
+
const aEncoded = this.codec.encodePoint(this.curve.toAffine(a));
|
|
174
|
+
// Second part of the signature
|
|
175
|
+
// (Not vulnerable to timing attack.
|
|
176
|
+
// Even though f is known publicly and changes with each message,
|
|
177
|
+
// and the f * x operation isn't constant time (bigint ops in JS aren't constant time),
|
|
178
|
+
// k also changes with each message, and the [k]BASE operation above
|
|
179
|
+
// is much more expensive than multiplying two big ints)
|
|
180
|
+
const f = this.oneWay(aEncoded, publicKeyBytes, message);
|
|
181
|
+
const b = this.Z.add(k, f * privateKey);
|
|
182
|
+
const bEncoded = this.codec.encodeScalar(b);
|
|
183
|
+
return Either.right(new Uint8Array(Array.from(aEncoded).concat(Array.from(bEncoded))));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Returns `true` if the signature is correct.
|
|
187
|
+
* Returns `false`:
|
|
188
|
+
* * if the signature is incorrect
|
|
189
|
+
* * if the signature doesn't lie on the curve,
|
|
190
|
+
* * if the publicKey doesn't lie on the curve
|
|
191
|
+
* Throw an error:
|
|
192
|
+
* * signature isn't 64 bytes long
|
|
193
|
+
* * publickey isn't 32 bytes long (asserted inside `decodePoint()`)
|
|
194
|
+
* @param signature
|
|
195
|
+
* @param message
|
|
196
|
+
* @param publicKey
|
|
197
|
+
* @returns
|
|
198
|
+
*/
|
|
199
|
+
verify(signature, message, publicKey) {
|
|
200
|
+
if (signature.length != 64) {
|
|
201
|
+
return Either.left(new BadSignatureLength(signature));
|
|
202
|
+
}
|
|
203
|
+
const a = this.curve.fromAffine(Either.getOrThrow(this.codec.decodePoint(signature.slice(0, 32))));
|
|
204
|
+
if (!this.curve.isValidPoint(a)) {
|
|
205
|
+
return Either.right(false);
|
|
206
|
+
}
|
|
207
|
+
const b = Either.getOrThrow(this.codec.decodeScalar(signature.slice(32, 64)));
|
|
208
|
+
if (publicKey.length != 32) {
|
|
209
|
+
return Either.left(new BadPublicKeyLength(publicKey));
|
|
210
|
+
}
|
|
211
|
+
const h = this.curve.fromAffine(Either.getOrThrow(this.codec.decodePoint(publicKey)));
|
|
212
|
+
if (!this.curve.isValidPoint(h)) {
|
|
213
|
+
return Either.right(false);
|
|
214
|
+
}
|
|
215
|
+
const f = this.oneWay(signature.slice(0, 32), publicKey, message);
|
|
216
|
+
const curveHelper = new CurveHelper(this.curve);
|
|
217
|
+
const left = curveHelper.scale(this.curve.fromAffine(this.G), b);
|
|
218
|
+
const right = this.curve.add(a, curveHelper.scale(h, f));
|
|
219
|
+
return Either.right(this.curve.equals(left, right));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=EdDSA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EdDSA.js","sourceRoot":"","sources":["../../src/Crypto/EdDSA.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAY,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAc,WAAW,EAAgB,MAAM,YAAY,CAAA;AAClE,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAGzC,MAAM,OAAO,mBAAoB,SAAQ,IAAI,CAAC,WAAW,CACvD,kCAAkC,CAGlC;IACA,YAAY,UAAsB;QAChC,KAAK,CAAC;YACJ,OAAO,EAAE,8EAA8E,UAAU,CAAC,MAAM,gDAAgD;SACzJ,CAAC,CAAA;IACJ,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,IAAI,CAAC,WAAW,CACtD,iCAAiC,CAGjC;IACA,YAAY,SAAqB;QAC/B,KAAK,CAAC,EAAE,OAAO,EAAE,+BAA+B,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IACvE,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IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CACrD,CAAA;QAED,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;YAChC,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC5B,CAAC;QAED,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;QAEjE,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAE/C,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QAChE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAExD,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;IACrD,CAAC;CACF"}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Positive modulo operator
|
|
3
|
+
* @param x
|
|
4
|
+
* @param modulo
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export function mod(x, modulo) {
|
|
8
|
+
const res = x % modulo;
|
|
9
|
+
if (res < 0n) {
|
|
10
|
+
return res + modulo;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return res;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class ScalarField {
|
|
17
|
+
/**
|
|
18
|
+
* Every operation is modulo this number
|
|
19
|
+
*/
|
|
20
|
+
modulo;
|
|
21
|
+
constructor(modulo) {
|
|
22
|
+
this.modulo = modulo;
|
|
23
|
+
}
|
|
24
|
+
get ZERO() {
|
|
25
|
+
return 0n;
|
|
26
|
+
}
|
|
27
|
+
get ONE() {
|
|
28
|
+
return 1n;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @param a
|
|
32
|
+
* @param b
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
add(a, ...b) {
|
|
36
|
+
return mod(b.reduce((sum, b) => sum + b, a), this.modulo);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @param a
|
|
40
|
+
* @param n
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
scale(a, n) {
|
|
44
|
+
return mod(a * n, this.modulo);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Implemented separately from `scale` because it has a different meaning
|
|
48
|
+
* @param a
|
|
49
|
+
* @param b
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
multiply(a, b) {
|
|
53
|
+
return mod(a * b, this.modulo);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @param a
|
|
57
|
+
* @param b
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
equals(a, b) {
|
|
61
|
+
return mod(a, this.modulo) === mod(b, this.modulo);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Invert a number on a field (i.e. calculate n^-1 so that n*n^-1 = 1)
|
|
65
|
+
* This is an expensive iterative procedure that is only guaranteed to converge if the modulo is a prime number
|
|
66
|
+
* @param n
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
invert(n) {
|
|
70
|
+
let a = mod(n, this.modulo);
|
|
71
|
+
let b = this.modulo;
|
|
72
|
+
let x = 0n;
|
|
73
|
+
let y = 1n;
|
|
74
|
+
let u = 1n;
|
|
75
|
+
let v = 0n;
|
|
76
|
+
while (a !== 0n) {
|
|
77
|
+
const q = b / a;
|
|
78
|
+
const r = b % a;
|
|
79
|
+
const m = x - u * q;
|
|
80
|
+
const n = y - v * q;
|
|
81
|
+
b = a;
|
|
82
|
+
a = r;
|
|
83
|
+
x = u;
|
|
84
|
+
y = v;
|
|
85
|
+
u = m;
|
|
86
|
+
v = n;
|
|
87
|
+
}
|
|
88
|
+
return mod(x, this.modulo);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Defines additional operations on a field (which use the basic operations as building blocks)
|
|
93
|
+
* * isZero(a)
|
|
94
|
+
* * isOne(a)
|
|
95
|
+
* * mod(a)
|
|
96
|
+
* * subtract(a, b)
|
|
97
|
+
* * negate(a)
|
|
98
|
+
* * square(a)
|
|
99
|
+
* * cube(a)
|
|
100
|
+
* * divide(a, b)
|
|
101
|
+
* * pow(a, p)
|
|
102
|
+
* * halve(a)
|
|
103
|
+
*/
|
|
104
|
+
export class FieldHelper {
|
|
105
|
+
F;
|
|
106
|
+
/**
|
|
107
|
+
* @param F
|
|
108
|
+
*/
|
|
109
|
+
constructor(F) {
|
|
110
|
+
this.F = F;
|
|
111
|
+
}
|
|
112
|
+
get ZERO() {
|
|
113
|
+
return this.F.ZERO;
|
|
114
|
+
}
|
|
115
|
+
get ONE() {
|
|
116
|
+
return this.F.ONE;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @param a
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
isZero(a) {
|
|
123
|
+
return this.equals(a, this.ZERO);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* @param a
|
|
127
|
+
* @returns
|
|
128
|
+
*/
|
|
129
|
+
isOne(a) {
|
|
130
|
+
return this.equals(a, this.ONE);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* @param a
|
|
134
|
+
* @returns
|
|
135
|
+
*/
|
|
136
|
+
mod(a) {
|
|
137
|
+
return this.F.scale(a, 1n);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @param a
|
|
141
|
+
* @param bs
|
|
142
|
+
* @returns
|
|
143
|
+
*/
|
|
144
|
+
add(a, ...bs) {
|
|
145
|
+
return this.F.add(a, ...bs);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* @param a
|
|
149
|
+
* @param b
|
|
150
|
+
* @returns
|
|
151
|
+
*/
|
|
152
|
+
subtract(a, b) {
|
|
153
|
+
const F = this.F;
|
|
154
|
+
return F.add(a, F.scale(b, -1n));
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* @param a
|
|
158
|
+
* @param s
|
|
159
|
+
* @returns
|
|
160
|
+
*/
|
|
161
|
+
scale(a, s) {
|
|
162
|
+
return this.F.scale(a, s);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @param a
|
|
166
|
+
* @returns
|
|
167
|
+
*/
|
|
168
|
+
negate(a) {
|
|
169
|
+
return this.F.scale(a, -1n);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* @param a
|
|
173
|
+
* @param b
|
|
174
|
+
* @returns
|
|
175
|
+
*/
|
|
176
|
+
multiply(a, b) {
|
|
177
|
+
return this.F.multiply(a, b);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* @param a
|
|
181
|
+
* @returns
|
|
182
|
+
*/
|
|
183
|
+
square(a) {
|
|
184
|
+
return this.F.multiply(a, a);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* @param a
|
|
188
|
+
* @returns
|
|
189
|
+
*/
|
|
190
|
+
cube(a) {
|
|
191
|
+
return this.F.multiply(a, this.F.multiply(a, a));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* @param a
|
|
195
|
+
* @param b
|
|
196
|
+
* @returns
|
|
197
|
+
*/
|
|
198
|
+
divide(a, b) {
|
|
199
|
+
return this.F.multiply(a, this.F.invert(b));
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* @param a
|
|
203
|
+
* @returns
|
|
204
|
+
*/
|
|
205
|
+
invert(a) {
|
|
206
|
+
return this.F.invert(a);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Modular exponent
|
|
210
|
+
* TODO: would a non-recursive version of this algorithm be faster?
|
|
211
|
+
* @param a
|
|
212
|
+
* @param p
|
|
213
|
+
* @returns
|
|
214
|
+
*/
|
|
215
|
+
pow(a, p) {
|
|
216
|
+
if (p == 0n) {
|
|
217
|
+
return this.F.ONE;
|
|
218
|
+
}
|
|
219
|
+
else if (p == 1n) {
|
|
220
|
+
return a;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
let t = this.pow(a, p / 2n);
|
|
224
|
+
t = this.F.multiply(t, t);
|
|
225
|
+
if (p % 2n != 0n) {
|
|
226
|
+
t = this.F.multiply(t, a);
|
|
227
|
+
}
|
|
228
|
+
return t;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* @param a
|
|
233
|
+
* @param b
|
|
234
|
+
* @returns
|
|
235
|
+
*/
|
|
236
|
+
equals(a, b) {
|
|
237
|
+
return this.F.equals(a, b);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* @param a
|
|
241
|
+
* @returns
|
|
242
|
+
*/
|
|
243
|
+
halve(a) {
|
|
244
|
+
return this.divide(a, this.F.scale(this.F.ONE, 2n));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
export class QuadraticField {
|
|
248
|
+
/**
|
|
249
|
+
* Field used for each component
|
|
250
|
+
*/
|
|
251
|
+
F;
|
|
252
|
+
/**
|
|
253
|
+
* We can always replace u^2 by this number (e.g. for complex numbers this is -1)
|
|
254
|
+
*/
|
|
255
|
+
U2;
|
|
256
|
+
/**
|
|
257
|
+
* @param F
|
|
258
|
+
* Applied to each part separately
|
|
259
|
+
* @param U2
|
|
260
|
+
*/
|
|
261
|
+
constructor(F, U2) {
|
|
262
|
+
this.F = F;
|
|
263
|
+
this.U2 = U2;
|
|
264
|
+
}
|
|
265
|
+
get ZERO() {
|
|
266
|
+
return [this.F.ZERO, this.F.ZERO];
|
|
267
|
+
}
|
|
268
|
+
get ONE() {
|
|
269
|
+
return [this.F.ONE, this.F.ZERO];
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* @param a
|
|
273
|
+
* @param b
|
|
274
|
+
* @returns
|
|
275
|
+
*/
|
|
276
|
+
add([ax, ay], ...b) {
|
|
277
|
+
const F = this.F;
|
|
278
|
+
return [F.add(ax, ...b.map((b) => b[0])), F.add(ay, ...b.map((b) => b[1]))];
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* @param a
|
|
282
|
+
* @param s
|
|
283
|
+
* @returns
|
|
284
|
+
*/
|
|
285
|
+
scale([ax, ay], s) {
|
|
286
|
+
const F = this.F;
|
|
287
|
+
return [F.scale(ax, s), F.scale(ay, s)];
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* @param a
|
|
291
|
+
* @param b
|
|
292
|
+
* @returns
|
|
293
|
+
*/
|
|
294
|
+
multiply([ax, ay], [bx, by]) {
|
|
295
|
+
const F = this.F;
|
|
296
|
+
return [
|
|
297
|
+
F.add(F.multiply(ax, bx), F.multiply(F.multiply(ay, by), this.U2)),
|
|
298
|
+
F.add(F.multiply(ay, bx), F.multiply(by, ax))
|
|
299
|
+
];
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* @param a
|
|
303
|
+
* @param b
|
|
304
|
+
* @returns
|
|
305
|
+
*/
|
|
306
|
+
equals([ax, ay], [bx, by]) {
|
|
307
|
+
const F = this.F;
|
|
308
|
+
return F.equals(ax, bx) && F.equals(ay, by);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Using the following formula we can derive the inverse of complex field element
|
|
312
|
+
* (ax + u*ay)*(ax - u*ay) = ax^2 - u^2*ay^2
|
|
313
|
+
* (ax + u*ay)^-1 = (ax - u*ay)/(ax^2 - u^2*ay^2)
|
|
314
|
+
* @param a
|
|
315
|
+
* @returns
|
|
316
|
+
*/
|
|
317
|
+
invert([ax, ay]) {
|
|
318
|
+
const F = new FieldHelper(this.F);
|
|
319
|
+
const f = F.invert(F.subtract(F.square(ax), F.multiply(F.square(ay), this.U2)));
|
|
320
|
+
return [F.multiply(ax, f), F.multiply(ay, F.negate(f))];
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
//# sourceMappingURL=Field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Field.js","sourceRoot":"","sources":["../../src/Crypto/Field.ts"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,MAAc;IAC3C,MAAM,GAAG,GAAG,CAAC,GAAG,MAAM,CAAA;IAEtB,IAAI,GAAG,GAAG,EAAE,EAAE,CAAC;QACb,OAAO,GAAG,GAAG,MAAM,CAAA;IACrB,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,CAAA;IACZ,CAAC;AACH,CAAC;AAmCD,MAAM,OAAO,WAAW;IACtB;;OAEG;IACM,MAAM,CAAQ;IAEvB,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,GAAG;QACL,OAAO,EAAE,CAAA;IACX,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,CAAS,EAAE,GAAG,CAAW;QAC3B,OAAO,GAAG,CACR,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,EAChC,IAAI,CAAC,MAAM,CACZ,CAAA;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,CAAS,EAAE,CAAS;QACxB,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAChC,C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AC7C,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAS;QACrB,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAChB,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAC5D,CAAA;QAED,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACzD,CAAC;CACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as Bytes from "../Codecs/Bytes.js";
|
|
2
|
+
import * as Sha2_256 from "./Sha2_256.js";
|
|
3
|
+
import * as Sha2_512 from "./Sha2_512.js";
|
|
4
|
+
/**
|
|
5
|
+
* Hmac using sha2-256.
|
|
6
|
+
* @example
|
|
7
|
+
* bytesToHex(hmacSha2_256(textToBytes("key"), textToBytes("The quick brown fox jumps over the lazy dog"))) == "f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8"
|
|
8
|
+
* @param key
|
|
9
|
+
* @param message
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export function sha2_256Sync(key, message) {
|
|
13
|
+
return deriveSyncInternal(Sha2_256.hashSync, 64)(Bytes.toUint8Array(key), Bytes.toUint8Array(message));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Hmac using sha2-512.
|
|
17
|
+
* @example
|
|
18
|
+
* bytesToHex(hmacSha2_512(textToBytes("key"), textToBytes("The quick brown fox jumps over the lazy dog"))) == "b42af09057bac1e2d41708e48a902e09b5ff7f12ab428a4fe86653c73dd248fb82f948a549f7b791a5b41915ee4d1ec3935357e4e2317250d0372afa2ebeeb3a"
|
|
19
|
+
* @param key
|
|
20
|
+
* @param message
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export function sha2_512Sync(key, message) {
|
|
24
|
+
return deriveSyncInternal(Sha2_512.hashSync, 128)(Bytes.toUint8Array(key), Bytes.toUint8Array(message));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Don't use this directly, use hmacSyncSha2_256 or hmacSyncSha2_512 instead
|
|
28
|
+
* @param algorithm
|
|
29
|
+
* sync hashing function
|
|
30
|
+
* @param b
|
|
31
|
+
* blockSize of algorithm
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
const deriveSyncInternal = (algorithm, blockSize) => (key, message) => {
|
|
35
|
+
if (key.length > blockSize) {
|
|
36
|
+
key = algorithm(key);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
key = key.slice();
|
|
40
|
+
}
|
|
41
|
+
while (key.length < blockSize) {
|
|
42
|
+
const tmp = new Uint8Array(key.length + 1);
|
|
43
|
+
tmp.set(key);
|
|
44
|
+
tmp[key.length] = 0x00;
|
|
45
|
+
key = tmp;
|
|
46
|
+
}
|
|
47
|
+
const iPadded = key.map((k) => k ^ 0x36);
|
|
48
|
+
const oPadded = key.map((k) => k ^ 0x5c);
|
|
49
|
+
return algorithm(Bytes.concat(oPadded, algorithm(Bytes.concat(iPadded, message))));
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=Hmac.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Hmac.js","sourceRoot":"","sources":["../../src/Crypto/Hmac.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAC3C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,eAA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