@ocap/mpc-hsm 0.0.0-stage → 1.33.6
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/esm/constants.d.mts +76 -0
- package/esm/constants.mjs +78 -0
- package/esm/dkg.d.mts +279 -0
- package/esm/dkg.mjs +903 -0
- package/esm/index.d.mts +9 -0
- package/esm/index.mjs +10 -0
- package/esm/mta.d.mts +63 -0
- package/esm/mta.mjs +275 -0
- package/esm/ot.d.mts +187 -0
- package/esm/ot.mjs +593 -0
- package/esm/presign.d.mts +242 -0
- package/esm/presign.mjs +951 -0
- package/esm/secp256k1-scalar.d.mts +141 -0
- package/esm/secp256k1-scalar.mjs +465 -0
- package/esm/sign.d.mts +113 -0
- package/esm/sign.mjs +225 -0
- package/esm/tweak.d.mts +100 -0
- package/esm/tweak.mjs +168 -0
- package/lib/constants.cjs +136 -0
- package/lib/constants.d.cts +76 -0
- package/lib/dkg.cjs +910 -0
- package/lib/dkg.d.cts +279 -0
- package/lib/index.cjs +171 -0
- package/lib/index.d.cts +9 -0
- package/lib/mta.cjs +280 -0
- package/lib/mta.d.cts +63 -0
- package/lib/ot.cjs +609 -0
- package/lib/ot.d.cts +187 -0
- package/lib/presign.cjs +954 -0
- package/lib/presign.d.cts +242 -0
- package/lib/secp256k1-scalar.cjs +518 -0
- package/lib/secp256k1-scalar.d.cts +141 -0
- package/lib/sign.cjs +233 -0
- package/lib/sign.d.cts +113 -0
- package/lib/tweak.cjs +178 -0
- package/lib/tweak.d.cts +100 -0
- package/package.json +75 -4
- package/README.md +0 -3
package/esm/index.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BSGS_M, DEFAULT_COLD_GUARDIANS, DEFAULT_COLD_THRESHOLD, DEFAULT_ONLINE_PARTIES, DEFAULT_ONLINE_THRESHOLD, DST_BASEOT_KEY_V1, DST_BASEOT_S_POK_V1, DST_CHILD_TWEAK_V1, DST_COT_ROW_V1, DST_DKG_COM_V2, DST_DKG_CTX_V2, DST_DKG_ECHO_V2, DST_DKG_POK_V2, DST_DKG_SELFTEST_V2, DST_DKG_SHARE_AAD_V2, DST_DKG_STEP1_AUTH_V1, DST_DKG_TRANSCRIPT_V2, DST_DKG_X25519_HKDF_V2, DST_KOS15_CHI_V1, DST_LHL_GADGET_V1, DST_MTA_ETA_V1, DST_OT_CTR_IV_V1, DST_PRESIG_COM_V1, DST_PRESIG_ID_V1, DST_PRESIG_PI_LIN_K_V1, DST_PRESIG_PI_POK_Z_V1, DST_PRESIG_POK_B_V1, DST_PRESIG_POK_CK_V1, DST_PRESIG_POK_GAMMA_V1, DST_PRESIG_RERAND_V1, DST_PRESIG_ZETA_HKDF_V1, DST_PRESIG_ZETA_V1, DST_RULE_TWEAK_V1, ESCAPE_DRILL_MAX_AGE_SECONDS, FORBIDDEN_ONLINE_ROLE_ESCAPE_CANARY, MAX_MPC_CLUSTER_NODES, MAX_MPC_PEER_MESSAGE_BYTES, MAX_MPC_SIGN_REQUEST_BYTES, MAX_ON_DEMAND_SILENCE_SECONDS, MAX_RECOVERY_PACKAGE_BYTES, MAX_RULE_DAG_NODES, MAX_RULE_YAML_BYTES, MPC_PROTOCOL_VERSION, MpcErrorCode, MpcProtocolError, MpcRootLifecycleState, OT_BASE_PARTIAL_BITS, OT_COLUMN_BYTES, OT_EXTENSION_ROWS, OT_GADGET_BITS, OT_KAPPA_BITS, OT_KAPPA_BYTES, OT_LHL_EXTRA_BITS, OT_SACRIFICE_BITS, PEDERSEN_H_COMPRESSED_HEX, PEDERSEN_H_DST, PEDERSEN_H_MESSAGE, SECP256K1_HALF_N, SECP256K1_N, SECP256K1_P } from "./constants.mjs";
|
|
2
|
+
import { Fn, H_scalar, LinearPedersenDleqProof, PEDERSEN_H, PEDERSEN_H_COMP33, PedersenPokProof, RandomBytesFn, SECP256K1_G, SECP256K1_ZERO, SchnorrPokProof, Secp256k1Point, addModN, assertScalarInField, assertScalarNonZero, assertValidX25519PublicKey, bytes32ToScalarNonZero, bytes32ToScalarStrict, bytesToBigIntBE, bytesToHex, computeX25519SharedSecret, concatBytes, constantTimeEqual, createLinearPedersenDleqProof, createPedersenPok, createSchnorrPokInBase, decodePointCompressed, defaultRandomBytes, encodePointCompressed, enumerateCombinations, evaluateFeldmanCommitments, evaluatePolynomialModN, hashTranscriptSha256, hexToBytes, invModN, lagrangeCoefficientAtZero, lengthPrefixedEncode, modN, mulBaseG, mulModN, mulPoint, negModN, normalizeHexBytes, normalizeSortedSubset, pedersenCommit, sampleScalarNonZero, scalarToBytes32, secp256k1, sortedSubsetBytes, subModN, subsetsEqual, u16be, u32be, u64be, u8, utf8Bytes, verifyLinearPedersenDleqProof, verifyPedersenPok, verifySchnorrPokInBase, zeroizeBytes } from "./secp256k1-scalar.mjs";
|
|
3
|
+
import { AppendOnlyDkgEchoLock, ColdBackupDealerInput, ColdBackupPlugin, DkgCeremonyConfig, DkgEchoLock, DkgEncryptedShareEnvelope, DkgParticipantSession, DkgRosterEntry, DkgRound1CommitMessage, DkgRound2RevealPayload, DkgRound3EchoMessage, DkgSubsetSelfTestSignature, MpcNodeProvisionedKeyRecord, OcapConsensusAnchor, assertSafeCeremonyId, computeDkgContextHash32, computeDkgSubsetSelfTestDigest32, promoteNodeRecordAfterSelfTests, validateAndComputeDkgContext } from "./dkg.mjs";
|
|
4
|
+
import { DerivedChildKey, MpcChildDerivationSpec, MpcTweakMode, applyAdditiveTweak, assertAllowedOnlineRole, deriveRoleBoundChild, deriveRuleBoundChild, deriveUntweakedChild, ecrecoverEthAddress, parseStrictEthAddress, pointToEthAddress, toEip55ChecksumAddress } from "./tweak.mjs";
|
|
5
|
+
import { BaseOtReceiverState, BaseOtSenderPendingSession, BaseOtSenderState, BaseOtStep1Message, BaseOtStep2Message, OtExtReceiverPendingState, OtExtSenderPendingState, OtExtStep1Message, OtExtStep2Message, OtExtStep3Message, VerifiedCotReceiverRows, VerifiedCotSenderRows, baseOtReceiverStep2, baseOtSenderStep1, baseOtSenderStep3, bytes16ToU128LE, eklundhTranspose128x1024, expandKos15ChiWeights, gf128Mul, otExtendReceiverStep1, otExtendReceiverStep3, otExtendSenderStep2, otExtendSenderStep4VerifyBeforePads, u128ToBytes16LE, wipeBaseOtReceiverState, wipeBaseOtSenderState, wipeVerifiedCotReceiverRows, wipeVerifiedCotSenderRows } from "./ot.mjs";
|
|
6
|
+
import { GadgetMtaPayload, decomposeScalarWithLhlGadget, deriveDualPadFromCotRow, gadgetMtaReceiverVerifyAndFinish, gadgetMtaSenderCreateMessage, getGadgetVector768, recombineGadgetBitsModN } from "./mta.mjs";
|
|
7
|
+
import { MpcPartyBaseOtChannels, MpcPublicClusterInfo, MtaInstanceKind, PresignMtaOtStep1Bundle, PresignMtaOtStep2Bundle, PresignMtaOtStep3Bundle, PresignMtaStep4PayloadBundle, PresignPartySession, PresignRound1CommitmentMsg, PresignRound1RevealMsg, PresignRound3BroadcastMsg, PresignRound4BroadcastMsg, PresignaturePublicVerification, PresignatureShareRecord, VolatilePresignaturePool, computeSubsetBoundPresigId } from "./presign.mjs";
|
|
8
|
+
import { MpcAggregatedSignature, MpcOnlineSignRequest, MpcOnlineSignShare, RerandomizedNonceResult, aggregateOnlineSignature, computeRerandomizedNoncePoint, createOnlineSignShare, deriveGrothShoupRerandScalar, evaluateConsumedPresigShareWithRerand, verifyAndDeriveRequestChildKey, verifyOnlineSignShare } from "./sign.mjs";
|
|
9
|
+
export { AppendOnlyDkgEchoLock, BSGS_M, BaseOtReceiverState, BaseOtSenderPendingSession, BaseOtSenderState, BaseOtStep1Message, BaseOtStep2Message, ColdBackupDealerInput, ColdBackupPlugin, DEFAULT_COLD_GUARDIANS, DEFAULT_COLD_THRESHOLD, DEFAULT_ONLINE_PARTIES, DEFAULT_ONLINE_THRESHOLD, DST_BASEOT_KEY_V1, DST_BASEOT_S_POK_V1, DST_CHILD_TWEAK_V1, DST_COT_ROW_V1, DST_DKG_COM_V2, DST_DKG_CTX_V2, DST_DKG_ECHO_V2, DST_DKG_POK_V2, DST_DKG_SELFTEST_V2, DST_DKG_SHARE_AAD_V2, DST_DKG_STEP1_AUTH_V1, DST_DKG_TRANSCRIPT_V2, DST_DKG_X25519_HKDF_V2, DST_KOS15_CHI_V1, DST_LHL_GADGET_V1, DST_MTA_ETA_V1, DST_OT_CTR_IV_V1, DST_PRESIG_COM_V1, DST_PRESIG_ID_V1, DST_PRESIG_PI_LIN_K_V1, DST_PRESIG_PI_POK_Z_V1, DST_PRESIG_POK_B_V1, DST_PRESIG_POK_CK_V1, DST_PRESIG_POK_GAMMA_V1, DST_PRESIG_RERAND_V1, DST_PRESIG_ZETA_HKDF_V1, DST_PRESIG_ZETA_V1, DST_RULE_TWEAK_V1, DerivedChildKey, DkgCeremonyConfig, DkgEchoLock, DkgEncryptedShareEnvelope, DkgParticipantSession, DkgRosterEntry, DkgRound1CommitMessage, DkgRound2RevealPayload, DkgRound3EchoMessage, DkgSubsetSelfTestSignature, ESCAPE_DRILL_MAX_AGE_SECONDS, FORBIDDEN_ONLINE_ROLE_ESCAPE_CANARY, Fn, GadgetMtaPayload, H_scalar, LinearPedersenDleqProof, MAX_MPC_CLUSTER_NODES, MAX_MPC_PEER_MESSAGE_BYTES, MAX_MPC_SIGN_REQUEST_BYTES, MAX_ON_DEMAND_SILENCE_SECONDS, MAX_RECOVERY_PACKAGE_BYTES, MAX_RULE_DAG_NODES, MAX_RULE_YAML_BYTES, MPC_PROTOCOL_VERSION, type MpcAggregatedSignature, MpcChildDerivationSpec, MpcErrorCode, MpcNodeProvisionedKeyRecord, type MpcOnlineSignRequest, type MpcOnlineSignShare, MpcPartyBaseOtChannels, MpcProtocolError, MpcPublicClusterInfo, MpcRootLifecycleState, MpcTweakMode, MtaInstanceKind, OT_BASE_PARTIAL_BITS, OT_COLUMN_BYTES, OT_EXTENSION_ROWS, OT_GADGET_BITS, OT_KAPPA_BITS, OT_KAPPA_BYTES, OT_LHL_EXTRA_BITS, OT_SACRIFICE_BITS, OcapConsensusAnchor, OtExtReceiverPendingState, OtExtSenderPendingState, OtExtStep1Message, OtExtStep2Message, OtExtStep3Message, PEDERSEN_H, PEDERSEN_H_COMP33, PEDERSEN_H_COMPRESSED_HEX, PEDERSEN_H_DST, PEDERSEN_H_MESSAGE, PedersenPokProof, PresignMtaOtStep1Bundle, PresignMtaOtStep2Bundle, PresignMtaOtStep3Bundle, PresignMtaStep4PayloadBundle, PresignPartySession, PresignRound1CommitmentMsg, PresignRound1RevealMsg, PresignRound3BroadcastMsg, PresignRound4BroadcastMsg, PresignaturePublicVerification, PresignatureShareRecord, RandomBytesFn, type RerandomizedNonceResult, SECP256K1_G, SECP256K1_HALF_N, SECP256K1_N, SECP256K1_P, SECP256K1_ZERO, SchnorrPokProof, Secp256k1Point, VerifiedCotReceiverRows, VerifiedCotSenderRows, VolatilePresignaturePool, addModN, aggregateOnlineSignature, applyAdditiveTweak, assertAllowedOnlineRole, assertSafeCeremonyId, assertScalarInField, assertScalarNonZero, assertValidX25519PublicKey, baseOtReceiverStep2, baseOtSenderStep1, baseOtSenderStep3, bytes16ToU128LE, bytes32ToScalarNonZero, bytes32ToScalarStrict, bytesToBigIntBE, bytesToHex, computeDkgContextHash32, computeDkgSubsetSelfTestDigest32, computeRerandomizedNoncePoint, computeSubsetBoundPresigId, computeX25519SharedSecret, concatBytes, constantTimeEqual, createLinearPedersenDleqProof, createOnlineSignShare, createPedersenPok, createSchnorrPokInBase, decodePointCompressed, decomposeScalarWithLhlGadget, defaultRandomBytes, deriveDualPadFromCotRow, deriveGrothShoupRerandScalar, deriveRoleBoundChild, deriveRuleBoundChild, deriveUntweakedChild, ecrecoverEthAddress, eklundhTranspose128x1024, encodePointCompressed, enumerateCombinations, evaluateConsumedPresigShareWithRerand, evaluateFeldmanCommitments, evaluatePolynomialModN, expandKos15ChiWeights, gadgetMtaReceiverVerifyAndFinish, gadgetMtaSenderCreateMessage, getGadgetVector768, gf128Mul, hashTranscriptSha256, hexToBytes, invModN, lagrangeCoefficientAtZero, lengthPrefixedEncode, modN, mulBaseG, mulModN, mulPoint, negModN, normalizeHexBytes, normalizeSortedSubset, otExtendReceiverStep1, otExtendReceiverStep3, otExtendSenderStep2, otExtendSenderStep4VerifyBeforePads, parseStrictEthAddress, pedersenCommit, pointToEthAddress, promoteNodeRecordAfterSelfTests, recombineGadgetBitsModN, sampleScalarNonZero, scalarToBytes32, secp256k1, sortedSubsetBytes, subModN, subsetsEqual, toEip55ChecksumAddress, u128ToBytes16LE, u16be, u32be, u64be, u8, utf8Bytes, validateAndComputeDkgContext, verifyAndDeriveRequestChildKey, verifyLinearPedersenDleqProof, verifyOnlineSignShare, verifyPedersenPok, verifySchnorrPokInBase, wipeBaseOtReceiverState, wipeBaseOtSenderState, wipeVerifiedCotReceiverRows, wipeVerifiedCotSenderRows, zeroizeBytes };
|
package/esm/index.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BSGS_M, DEFAULT_COLD_GUARDIANS, DEFAULT_COLD_THRESHOLD, DEFAULT_ONLINE_PARTIES, DEFAULT_ONLINE_THRESHOLD, DST_BASEOT_KEY_V1, DST_BASEOT_S_POK_V1, DST_CHILD_TWEAK_V1, DST_COT_ROW_V1, DST_DKG_COM_V2, DST_DKG_CTX_V2, DST_DKG_ECHO_V2, DST_DKG_POK_V2, DST_DKG_SELFTEST_V2, DST_DKG_SHARE_AAD_V2, DST_DKG_STEP1_AUTH_V1, DST_DKG_TRANSCRIPT_V2, DST_DKG_X25519_HKDF_V2, DST_KOS15_CHI_V1, DST_LHL_GADGET_V1, DST_MTA_ETA_V1, DST_OT_CTR_IV_V1, DST_PRESIG_COM_V1, DST_PRESIG_ID_V1, DST_PRESIG_PI_LIN_K_V1, DST_PRESIG_PI_POK_Z_V1, DST_PRESIG_POK_B_V1, DST_PRESIG_POK_CK_V1, DST_PRESIG_POK_GAMMA_V1, DST_PRESIG_RERAND_V1, DST_PRESIG_ZETA_HKDF_V1, DST_PRESIG_ZETA_V1, DST_RULE_TWEAK_V1, ESCAPE_DRILL_MAX_AGE_SECONDS, FORBIDDEN_ONLINE_ROLE_ESCAPE_CANARY, MAX_MPC_CLUSTER_NODES, MAX_MPC_PEER_MESSAGE_BYTES, MAX_MPC_SIGN_REQUEST_BYTES, MAX_ON_DEMAND_SILENCE_SECONDS, MAX_RECOVERY_PACKAGE_BYTES, MAX_RULE_DAG_NODES, MAX_RULE_YAML_BYTES, MPC_PROTOCOL_VERSION, MpcProtocolError, OT_BASE_PARTIAL_BITS, OT_COLUMN_BYTES, OT_EXTENSION_ROWS, OT_GADGET_BITS, OT_KAPPA_BITS, OT_KAPPA_BYTES, OT_LHL_EXTRA_BITS, OT_SACRIFICE_BITS, PEDERSEN_H_COMPRESSED_HEX, PEDERSEN_H_DST, PEDERSEN_H_MESSAGE, SECP256K1_HALF_N, SECP256K1_N, SECP256K1_P } from "./constants.mjs";
|
|
2
|
+
import { Fn, H_scalar, PEDERSEN_H, PEDERSEN_H_COMP33, SECP256K1_G, SECP256K1_ZERO, addModN, assertScalarInField, assertScalarNonZero, assertValidX25519PublicKey, bytes32ToScalarNonZero, bytes32ToScalarStrict, bytesToBigIntBE, bytesToHex, computeX25519SharedSecret, concatBytes, constantTimeEqual, createLinearPedersenDleqProof, createPedersenPok, createSchnorrPokInBase, decodePointCompressed, defaultRandomBytes, encodePointCompressed, enumerateCombinations, evaluateFeldmanCommitments, evaluatePolynomialModN, hashTranscriptSha256, hexToBytes, invModN, lagrangeCoefficientAtZero, lengthPrefixedEncode, modN, mulBaseG, mulModN, mulPoint, negModN, normalizeHexBytes, normalizeSortedSubset, pedersenCommit, sampleScalarNonZero, scalarToBytes32, secp256k1, sortedSubsetBytes, subModN, subsetsEqual, u16be, u32be, u64be, u8, utf8Bytes, verifyLinearPedersenDleqProof, verifyPedersenPok, verifySchnorrPokInBase, zeroizeBytes } from "./secp256k1-scalar.mjs";
|
|
3
|
+
import { applyAdditiveTweak, assertAllowedOnlineRole, deriveRoleBoundChild, deriveRuleBoundChild, deriveUntweakedChild, ecrecoverEthAddress, parseStrictEthAddress, pointToEthAddress, toEip55ChecksumAddress } from "./tweak.mjs";
|
|
4
|
+
import { AppendOnlyDkgEchoLock, DkgParticipantSession, assertSafeCeremonyId, computeDkgContextHash32, computeDkgSubsetSelfTestDigest32, promoteNodeRecordAfterSelfTests, validateAndComputeDkgContext } from "./dkg.mjs";
|
|
5
|
+
import { baseOtReceiverStep2, baseOtSenderStep1, baseOtSenderStep3, bytes16ToU128LE, eklundhTranspose128x1024, expandKos15ChiWeights, gf128Mul, otExtendReceiverStep1, otExtendReceiverStep3, otExtendSenderStep2, otExtendSenderStep4VerifyBeforePads, u128ToBytes16LE, wipeBaseOtReceiverState, wipeBaseOtSenderState, wipeVerifiedCotReceiverRows, wipeVerifiedCotSenderRows } from "./ot.mjs";
|
|
6
|
+
import { decomposeScalarWithLhlGadget, deriveDualPadFromCotRow, gadgetMtaReceiverVerifyAndFinish, gadgetMtaSenderCreateMessage, getGadgetVector768, recombineGadgetBitsModN } from "./mta.mjs";
|
|
7
|
+
import { PresignPartySession, VolatilePresignaturePool, computeSubsetBoundPresigId } from "./presign.mjs";
|
|
8
|
+
import { aggregateOnlineSignature, computeRerandomizedNoncePoint, createOnlineSignShare, deriveGrothShoupRerandScalar, evaluateConsumedPresigShareWithRerand, verifyAndDeriveRequestChildKey, verifyOnlineSignShare } from "./sign.mjs";
|
|
9
|
+
|
|
10
|
+
export { AppendOnlyDkgEchoLock, BSGS_M, DEFAULT_COLD_GUARDIANS, DEFAULT_COLD_THRESHOLD, DEFAULT_ONLINE_PARTIES, DEFAULT_ONLINE_THRESHOLD, DST_BASEOT_KEY_V1, DST_BASEOT_S_POK_V1, DST_CHILD_TWEAK_V1, DST_COT_ROW_V1, DST_DKG_COM_V2, DST_DKG_CTX_V2, DST_DKG_ECHO_V2, DST_DKG_POK_V2, DST_DKG_SELFTEST_V2, DST_DKG_SHARE_AAD_V2, DST_DKG_STEP1_AUTH_V1, DST_DKG_TRANSCRIPT_V2, DST_DKG_X25519_HKDF_V2, DST_KOS15_CHI_V1, DST_LHL_GADGET_V1, DST_MTA_ETA_V1, DST_OT_CTR_IV_V1, DST_PRESIG_COM_V1, DST_PRESIG_ID_V1, DST_PRESIG_PI_LIN_K_V1, DST_PRESIG_PI_POK_Z_V1, DST_PRESIG_POK_B_V1, DST_PRESIG_POK_CK_V1, DST_PRESIG_POK_GAMMA_V1, DST_PRESIG_RERAND_V1, DST_PRESIG_ZETA_HKDF_V1, DST_PRESIG_ZETA_V1, DST_RULE_TWEAK_V1, DkgParticipantSession, ESCAPE_DRILL_MAX_AGE_SECONDS, FORBIDDEN_ONLINE_ROLE_ESCAPE_CANARY, Fn, H_scalar, MAX_MPC_CLUSTER_NODES, MAX_MPC_PEER_MESSAGE_BYTES, MAX_MPC_SIGN_REQUEST_BYTES, MAX_ON_DEMAND_SILENCE_SECONDS, MAX_RECOVERY_PACKAGE_BYTES, MAX_RULE_DAG_NODES, MAX_RULE_YAML_BYTES, MPC_PROTOCOL_VERSION, MpcProtocolError, OT_BASE_PARTIAL_BITS, OT_COLUMN_BYTES, OT_EXTENSION_ROWS, OT_GADGET_BITS, OT_KAPPA_BITS, OT_KAPPA_BYTES, OT_LHL_EXTRA_BITS, OT_SACRIFICE_BITS, PEDERSEN_H, PEDERSEN_H_COMP33, PEDERSEN_H_COMPRESSED_HEX, PEDERSEN_H_DST, PEDERSEN_H_MESSAGE, PresignPartySession, SECP256K1_G, SECP256K1_HALF_N, SECP256K1_N, SECP256K1_P, SECP256K1_ZERO, VolatilePresignaturePool, addModN, aggregateOnlineSignature, applyAdditiveTweak, assertAllowedOnlineRole, assertSafeCeremonyId, assertScalarInField, assertScalarNonZero, assertValidX25519PublicKey, baseOtReceiverStep2, baseOtSenderStep1, baseOtSenderStep3, bytes16ToU128LE, bytes32ToScalarNonZero, bytes32ToScalarStrict, bytesToBigIntBE, bytesToHex, computeDkgContextHash32, computeDkgSubsetSelfTestDigest32, computeRerandomizedNoncePoint, computeSubsetBoundPresigId, computeX25519SharedSecret, concatBytes, constantTimeEqual, createLinearPedersenDleqProof, createOnlineSignShare, createPedersenPok, createSchnorrPokInBase, decodePointCompressed, decomposeScalarWithLhlGadget, defaultRandomBytes, deriveDualPadFromCotRow, deriveGrothShoupRerandScalar, deriveRoleBoundChild, deriveRuleBoundChild, deriveUntweakedChild, ecrecoverEthAddress, eklundhTranspose128x1024, encodePointCompressed, enumerateCombinations, evaluateConsumedPresigShareWithRerand, evaluateFeldmanCommitments, evaluatePolynomialModN, expandKos15ChiWeights, gadgetMtaReceiverVerifyAndFinish, gadgetMtaSenderCreateMessage, getGadgetVector768, gf128Mul, hashTranscriptSha256, hexToBytes, invModN, lagrangeCoefficientAtZero, lengthPrefixedEncode, modN, mulBaseG, mulModN, mulPoint, negModN, normalizeHexBytes, normalizeSortedSubset, otExtendReceiverStep1, otExtendReceiverStep3, otExtendSenderStep2, otExtendSenderStep4VerifyBeforePads, parseStrictEthAddress, pedersenCommit, pointToEthAddress, promoteNodeRecordAfterSelfTests, recombineGadgetBitsModN, sampleScalarNonZero, scalarToBytes32, secp256k1, sortedSubsetBytes, subModN, subsetsEqual, toEip55ChecksumAddress, u128ToBytes16LE, u16be, u32be, u64be, u8, utf8Bytes, validateAndComputeDkgContext, verifyAndDeriveRequestChildKey, verifyLinearPedersenDleqProof, verifyOnlineSignShare, verifyPedersenPok, verifySchnorrPokInBase, wipeBaseOtReceiverState, wipeBaseOtSenderState, wipeVerifiedCotReceiverRows, wipeVerifiedCotSenderRows, zeroizeBytes };
|
package/esm/mta.d.mts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { RandomBytesFn } from "./secp256k1-scalar.mjs";
|
|
2
|
+
import { VerifiedCotReceiverRows, VerifiedCotSenderRows } from "./ot.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/mta.d.ts
|
|
5
|
+
declare function getGadgetVector768(): ReadonlyArray<bigint>;
|
|
6
|
+
/**
|
|
7
|
+
* Encodes Receiver `B`'s secret scalar `\beta \in Z_n^*` into `768` choice bits `b_{0..767}`
|
|
8
|
+
* using `512` fresh CSPRNG Leftover-Hash-Lemma bits `b_{256..767}` and exact binary decomposition
|
|
9
|
+
* of `\beta_{rem} = (\beta - \sum_{l=256}^{767} b_l g_l) mod n` in `b_{0..255}`.
|
|
10
|
+
*/
|
|
11
|
+
declare function decomposeScalarWithLhlGadget(betaScalar: bigint, rng?: RandomBytesFn): Uint8Array;
|
|
12
|
+
declare function recombineGadgetBitsModN(choiceBits768: Uint8Array): bigint;
|
|
13
|
+
/**
|
|
14
|
+
* Single-row `SHAKE256(96B)` dual-pad extractor (`(r_{l,bit}, r_hat_{l,bit}) \in Z_n^2`).
|
|
15
|
+
* Squeezes an initial 96-byte chunk (3 x 32B candidates for 2 scalars) and continues squeezing
|
|
16
|
+
* 32B blocks on the same XOF stream if any 256-bit block is `>= n` (exact unbiased over `Z_n^2`).
|
|
17
|
+
*/
|
|
18
|
+
declare function deriveDualPadFromCotRow(ctxMta: Uint8Array, rowIndex: number, bit: 0 | 1, rowBytes16: Uint8Array): readonly [bigint, bigint];
|
|
19
|
+
interface GadgetMtaPayload {
|
|
20
|
+
readonly senderSlotA: number;
|
|
21
|
+
readonly receiverSlotB: number;
|
|
22
|
+
readonly cAlphaComp33: Uint8Array;
|
|
23
|
+
readonly cHatAlphaComp33: Uint8Array;
|
|
24
|
+
readonly uPackedBytes: Uint8Array;
|
|
25
|
+
readonly uHatPackedBytes: Uint8Array;
|
|
26
|
+
readonly alphaStarBytes32: Uint8Array;
|
|
27
|
+
readonly rhoStarBytes32: Uint8Array;
|
|
28
|
+
readonly rStarPackedBytes: Uint8Array;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sender `A` (slot `i`) executes single-row dual-pad `GadgetMtA` over verified `KOS15` rows,
|
|
32
|
+
* anchored to Round-1 Pedersen commitment `C_{k,i} = k_i G + \rho_{k,i} H`.
|
|
33
|
+
* Returns additive share `u_A \in Z_n` such that `u_A + v_B === k_i * \beta_j (mod n)`.
|
|
34
|
+
*/
|
|
35
|
+
declare function gadgetMtaSenderCreateMessage(params: {
|
|
36
|
+
ctxMta: Uint8Array;
|
|
37
|
+
senderSlotA: number;
|
|
38
|
+
receiverSlotB: number;
|
|
39
|
+
verifiedSenderRows: VerifiedCotSenderRows;
|
|
40
|
+
alphaScalar: bigint;
|
|
41
|
+
rhoAlphaScalar: bigint;
|
|
42
|
+
expectedRound1CommitmentCk: Uint8Array;
|
|
43
|
+
rng?: RandomBytesFn;
|
|
44
|
+
}): {
|
|
45
|
+
senderShareModN: bigint;
|
|
46
|
+
payload: GadgetMtaPayload;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Receiver `B` (slot `j`) verifies `C_alpha === C_{k,i}` (Round-1 commitment binding),
|
|
50
|
+
* checks the Pedersen linear combination `\alpha^* G + \rho^* H == \eta C_{k,i} + \hat{C}_\alpha`,
|
|
51
|
+
* verifies all 768 single-row dual-pad equations `\eta t_l + \hat{t}_l == r^*_l + b_l \alpha^* (mod n)`,
|
|
52
|
+
* and outputs additive share `v_B \in Z_n`.
|
|
53
|
+
*/
|
|
54
|
+
declare function gadgetMtaReceiverVerifyAndFinish(params: {
|
|
55
|
+
ctxMta: Uint8Array;
|
|
56
|
+
senderSlotA: number;
|
|
57
|
+
receiverSlotB: number;
|
|
58
|
+
verifiedReceiverRows: VerifiedCotReceiverRows;
|
|
59
|
+
expectedRound1CommitmentCk: Uint8Array;
|
|
60
|
+
payload: GadgetMtaPayload;
|
|
61
|
+
}): bigint;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { GadgetMtaPayload, decomposeScalarWithLhlGadget, deriveDualPadFromCotRow, gadgetMtaReceiverVerifyAndFinish, gadgetMtaSenderCreateMessage, getGadgetVector768, recombineGadgetBitsModN };
|
package/esm/mta.mjs
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { DST_COT_ROW_V1, DST_LHL_GADGET_V1, DST_MTA_ETA_V1, MpcProtocolError, OT_BASE_PARTIAL_BITS, OT_GADGET_BITS, OT_LHL_EXTRA_BITS, SECP256K1_N } from "./constants.mjs";
|
|
2
|
+
import { H_scalar, addModN, assertScalarNonZero, bytes32ToScalarStrict, bytesToBigIntBE, constantTimeEqual, decodePointCompressed, defaultRandomBytes, encodePointCompressed, mulModN, mulPoint, negModN, pedersenCommit, sampleScalarNonZero, scalarToBytes32, subModN, u32be, zeroizeBytes } from "./secp256k1-scalar.mjs";
|
|
3
|
+
import { shake256 } from "@noble/hashes/sha3.js";
|
|
4
|
+
|
|
5
|
+
//#region src/mta.ts
|
|
6
|
+
/**
|
|
7
|
+
* Single-Row Dual-Pad `GadgetMtA` anchored to Presignature Round-1 `C_{k,i}` (`design.md` §4.4(3)):
|
|
8
|
+
*
|
|
9
|
+
* - Gadget vector `g_{0..767}`:
|
|
10
|
+
* - `g_l = 2^l mod n` for `0 <= l < 256`
|
|
11
|
+
* - `g_l = H_scalar("ARC-MPC-LHL-GADGET-V1", u32be(l))` for `256 <= l < 768`
|
|
12
|
+
* - Both pads `(r_{l,b}, r_hat_{l,b}) \in Z_n^2` derive from ONE single COT row
|
|
13
|
+
* `row_{l,b} = Q_l ^ (b * Delta)` via `SHAKE256("ARC-MPC-COT-ROW-V1", ctx_mta, u32be(l), u8(b), row)`
|
|
14
|
+
* squeezing a 96-byte fast-path buffer (with XOF continuation on `>= n`) for exact zero modulo bias.
|
|
15
|
+
* - Anchored to `C_alpha === C_{k,i}`: Receiver `B` strictly verifies byte-equality with Round-1
|
|
16
|
+
* `C_{k,i}`, checks `\alpha^* G + \rho^* H == \eta C_{k,i} + \hat{C}_\alpha`, and verifies all
|
|
17
|
+
* 768 linear checks `\eta t_l + \hat{t}_l === r^*_l + b_l \alpha^* (mod n)`.
|
|
18
|
+
* Note: Single-row selective-failure probing on `s` rows passes with probability `2^{-s}` while
|
|
19
|
+
* `\tilde{x}_B` never enters `GadgetMtA`, `b_B` / `\gamma_B` are single-use and wiped before `e_B`
|
|
20
|
+
* on any Round-2 abort, and `512` fresh per-peer CSPRNG LHL bits keep `b_B mod n` statistically
|
|
21
|
+
* uniform (`> 128`-bit LHL security margin).
|
|
22
|
+
*/
|
|
23
|
+
let cachedGadgetVector = null;
|
|
24
|
+
function getGadgetVector768() {
|
|
25
|
+
if (cachedGadgetVector !== null) return cachedGadgetVector;
|
|
26
|
+
const vec = new Array(OT_GADGET_BITS);
|
|
27
|
+
let pow2 = 1n;
|
|
28
|
+
for (let l = 0; l < OT_BASE_PARTIAL_BITS; l++) {
|
|
29
|
+
vec[l] = pow2;
|
|
30
|
+
pow2 = mulModN(pow2, 2n);
|
|
31
|
+
}
|
|
32
|
+
for (let l = OT_BASE_PARTIAL_BITS; l < OT_GADGET_BITS; l++) vec[l] = H_scalar(DST_LHL_GADGET_V1, u32be(l));
|
|
33
|
+
cachedGadgetVector = vec;
|
|
34
|
+
return vec;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Encodes Receiver `B`'s secret scalar `\beta \in Z_n^*` into `768` choice bits `b_{0..767}`
|
|
38
|
+
* using `512` fresh CSPRNG Leftover-Hash-Lemma bits `b_{256..767}` and exact binary decomposition
|
|
39
|
+
* of `\beta_{rem} = (\beta - \sum_{l=256}^{767} b_l g_l) mod n` in `b_{0..255}`.
|
|
40
|
+
*/
|
|
41
|
+
function decomposeScalarWithLhlGadget(betaScalar, rng = defaultRandomBytes) {
|
|
42
|
+
assertScalarNonZero(betaScalar, "MtA receiver betaScalar");
|
|
43
|
+
const gadget = getGadgetVector768();
|
|
44
|
+
const choiceBits768 = new Uint8Array(OT_GADGET_BITS);
|
|
45
|
+
const randomLhlBytes64 = rng(OT_LHL_EXTRA_BITS >>> 3);
|
|
46
|
+
if (randomLhlBytes64.length !== 64) {
|
|
47
|
+
zeroizeBytes(randomLhlBytes64);
|
|
48
|
+
throw new MpcProtocolError("INVALID_PARAMETER", "RNG must produce 64 bytes for LHL bits");
|
|
49
|
+
}
|
|
50
|
+
let highSum = 0n;
|
|
51
|
+
try {
|
|
52
|
+
for (let i = 0; i < OT_LHL_EXTRA_BITS; i++) {
|
|
53
|
+
const bit = randomLhlBytes64[i >>> 3] >>> (i & 7) & 1;
|
|
54
|
+
const idx = OT_BASE_PARTIAL_BITS + i;
|
|
55
|
+
choiceBits768[idx] = bit;
|
|
56
|
+
if (bit === 1) highSum = addModN(highSum, gadget[idx]);
|
|
57
|
+
}
|
|
58
|
+
} finally {
|
|
59
|
+
zeroizeBytes(randomLhlBytes64);
|
|
60
|
+
}
|
|
61
|
+
const betaRem = subModN(betaScalar, highSum);
|
|
62
|
+
for (let l = 0; l < OT_BASE_PARTIAL_BITS; l++) choiceBits768[l] = Number(betaRem >> BigInt(l) & 1n);
|
|
63
|
+
return choiceBits768;
|
|
64
|
+
}
|
|
65
|
+
function recombineGadgetBitsModN(choiceBits768) {
|
|
66
|
+
if (choiceBits768.length !== OT_GADGET_BITS) throw new MpcProtocolError("INVALID_PARAMETER", `Expected ${OT_GADGET_BITS} gadget bits`);
|
|
67
|
+
const gadget = getGadgetVector768();
|
|
68
|
+
let acc = 0n;
|
|
69
|
+
for (let l = 0; l < OT_GADGET_BITS; l++) {
|
|
70
|
+
const bit = choiceBits768[l];
|
|
71
|
+
if (bit !== 0 && bit !== 1) throw new MpcProtocolError("INVALID_PARAMETER", `Invalid gadget bit at ${l}`);
|
|
72
|
+
if (bit === 1) acc = addModN(acc, gadget[l]);
|
|
73
|
+
}
|
|
74
|
+
return acc;
|
|
75
|
+
}
|
|
76
|
+
const COT_ROW_TAG_BYTES = new TextEncoder().encode(DST_COT_ROW_V1);
|
|
77
|
+
function buildCotRowHasherTemplate(ctxMta) {
|
|
78
|
+
const prefixLen = 4 + COT_ROW_TAG_BYTES.length + 4 + 4 + ctxMta.length;
|
|
79
|
+
const prefix = new Uint8Array(prefixLen);
|
|
80
|
+
const pView = new DataView(prefix.buffer);
|
|
81
|
+
let off = 0;
|
|
82
|
+
pView.setUint32(off, COT_ROW_TAG_BYTES.length, false);
|
|
83
|
+
off += 4;
|
|
84
|
+
prefix.set(COT_ROW_TAG_BYTES, off);
|
|
85
|
+
off += COT_ROW_TAG_BYTES.length;
|
|
86
|
+
pView.setUint32(off, 4, false);
|
|
87
|
+
off += 4;
|
|
88
|
+
pView.setUint32(off, ctxMta.length, false);
|
|
89
|
+
off += 4;
|
|
90
|
+
prefix.set(ctxMta, off);
|
|
91
|
+
const baseHasher = shake256.create({});
|
|
92
|
+
baseHasher.update(prefix);
|
|
93
|
+
const suffix = new Uint8Array(33);
|
|
94
|
+
const sView = new DataView(suffix.buffer);
|
|
95
|
+
sView.setUint32(0, 4, false);
|
|
96
|
+
sView.setUint32(8, 1, false);
|
|
97
|
+
sView.setUint32(13, 16, false);
|
|
98
|
+
const initial96 = new Uint8Array(96);
|
|
99
|
+
const extra32 = new Uint8Array(32);
|
|
100
|
+
return {
|
|
101
|
+
derive(rowIndex, bit, rowBytes16) {
|
|
102
|
+
if (rowBytes16.length !== 16) throw new MpcProtocolError("INVALID_PARAMETER", "COT row must be 16 bytes");
|
|
103
|
+
sView.setUint32(4, rowIndex >>> 0, false);
|
|
104
|
+
suffix[12] = bit;
|
|
105
|
+
suffix.set(rowBytes16, 17);
|
|
106
|
+
const xof = baseHasher.clone();
|
|
107
|
+
try {
|
|
108
|
+
xof.update(suffix);
|
|
109
|
+
xof.xofInto(initial96);
|
|
110
|
+
let rPrimary = null;
|
|
111
|
+
let rHat = null;
|
|
112
|
+
for (let chunk = 0; chunk < 3 && rHat === null; chunk++) {
|
|
113
|
+
const candidate = bytesToBigIntBE(initial96.subarray(chunk * 32, (chunk + 1) * 32));
|
|
114
|
+
if (candidate < SECP256K1_N) if (rPrimary === null) rPrimary = candidate;
|
|
115
|
+
else rHat = candidate;
|
|
116
|
+
}
|
|
117
|
+
while (rHat === null) {
|
|
118
|
+
xof.xofInto(extra32);
|
|
119
|
+
const candidate = bytesToBigIntBE(extra32);
|
|
120
|
+
if (candidate < SECP256K1_N) if (rPrimary === null) rPrimary = candidate;
|
|
121
|
+
else rHat = candidate;
|
|
122
|
+
}
|
|
123
|
+
return [rPrimary, rHat];
|
|
124
|
+
} finally {
|
|
125
|
+
xof.destroy();
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
destroy() {
|
|
129
|
+
zeroizeBytes(suffix, initial96, extra32);
|
|
130
|
+
baseHasher.destroy();
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Single-row `SHAKE256(96B)` dual-pad extractor (`(r_{l,bit}, r_hat_{l,bit}) \in Z_n^2`).
|
|
136
|
+
* Squeezes an initial 96-byte chunk (3 x 32B candidates for 2 scalars) and continues squeezing
|
|
137
|
+
* 32B blocks on the same XOF stream if any 256-bit block is `>= n` (exact unbiased over `Z_n^2`).
|
|
138
|
+
*/
|
|
139
|
+
function deriveDualPadFromCotRow(ctxMta, rowIndex, bit, rowBytes16) {
|
|
140
|
+
const tpl = buildCotRowHasherTemplate(ctxMta);
|
|
141
|
+
try {
|
|
142
|
+
return tpl.derive(rowIndex, bit, rowBytes16);
|
|
143
|
+
} finally {
|
|
144
|
+
tpl.destroy();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function computeMtaEtaChallenge(ctxMta, senderSlotA, receiverSlotB, cAlphaComp33, cHatAlphaComp33, uPackedBytes, uHatPackedBytes) {
|
|
148
|
+
return H_scalar(DST_MTA_ETA_V1, ctxMta, u32be(senderSlotA), u32be(receiverSlotB), cAlphaComp33, cHatAlphaComp33, uPackedBytes, uHatPackedBytes);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Sender `A` (slot `i`) executes single-row dual-pad `GadgetMtA` over verified `KOS15` rows,
|
|
152
|
+
* anchored to Round-1 Pedersen commitment `C_{k,i} = k_i G + \rho_{k,i} H`.
|
|
153
|
+
* Returns additive share `u_A \in Z_n` such that `u_A + v_B === k_i * \beta_j (mod n)`.
|
|
154
|
+
*/
|
|
155
|
+
function gadgetMtaSenderCreateMessage(params) {
|
|
156
|
+
const { ctxMta, senderSlotA, receiverSlotB, verifiedSenderRows, alphaScalar, rhoAlphaScalar, expectedRound1CommitmentCk, rng = defaultRandomBytes } = params;
|
|
157
|
+
assertScalarNonZero(alphaScalar, "MtA alphaScalar");
|
|
158
|
+
assertScalarNonZero(rhoAlphaScalar, "MtA rhoAlphaScalar");
|
|
159
|
+
if (verifiedSenderRows.qRows768.length !== OT_GADGET_BITS) throw new MpcProtocolError("INVALID_PARAMETER", "Verified COT sender rows must have 768 rows");
|
|
160
|
+
const cAlphaComp33 = encodePointCompressed(pedersenCommit(alphaScalar, rhoAlphaScalar));
|
|
161
|
+
if (!constantTimeEqual(cAlphaComp33, expectedRound1CommitmentCk)) throw new MpcProtocolError("MTA_COMMITMENT_MISMATCH", "Sender C_alpha does not match Round-1 C_{k,i}");
|
|
162
|
+
const alphaHat = sampleScalarNonZero(rng);
|
|
163
|
+
const rhoHat = sampleScalarNonZero(rng);
|
|
164
|
+
const cHatAlphaComp33 = encodePointCompressed(pedersenCommit(alphaHat, rhoHat));
|
|
165
|
+
const r0Vec = new Array(OT_GADGET_BITS);
|
|
166
|
+
const rHat0Vec = new Array(OT_GADGET_BITS);
|
|
167
|
+
const uPackedBytes = new Uint8Array(OT_GADGET_BITS * 32);
|
|
168
|
+
const uHatPackedBytes = new Uint8Array(OT_GADGET_BITS * 32);
|
|
169
|
+
const row1Buf = new Uint8Array(16);
|
|
170
|
+
const rowHasher = buildCotRowHasherTemplate(ctxMta);
|
|
171
|
+
try {
|
|
172
|
+
for (let l = 0; l < OT_GADGET_BITS; l++) {
|
|
173
|
+
const row0 = verifiedSenderRows.qRows768[l];
|
|
174
|
+
for (let bIdx = 0; bIdx < 16; bIdx++) row1Buf[bIdx] = row0[bIdx] ^ verifiedSenderRows.deltaBytes16[bIdx];
|
|
175
|
+
const [r0, rHat0] = rowHasher.derive(l, 0, row0);
|
|
176
|
+
const [r1, rHat1] = rowHasher.derive(l, 1, row1Buf);
|
|
177
|
+
r0Vec[l] = r0;
|
|
178
|
+
rHat0Vec[l] = rHat0;
|
|
179
|
+
const uL = addModN(subModN(r0, r1), alphaScalar);
|
|
180
|
+
const uHatL = addModN(subModN(rHat0, rHat1), alphaHat);
|
|
181
|
+
uPackedBytes.set(scalarToBytes32(uL), l * 32);
|
|
182
|
+
uHatPackedBytes.set(scalarToBytes32(uHatL), l * 32);
|
|
183
|
+
}
|
|
184
|
+
} finally {
|
|
185
|
+
zeroizeBytes(row1Buf);
|
|
186
|
+
rowHasher.destroy();
|
|
187
|
+
}
|
|
188
|
+
const eta = computeMtaEtaChallenge(ctxMta, senderSlotA, receiverSlotB, cAlphaComp33, cHatAlphaComp33, uPackedBytes, uHatPackedBytes);
|
|
189
|
+
const alphaStar = addModN(mulModN(eta, alphaScalar), alphaHat);
|
|
190
|
+
const rhoStar = addModN(mulModN(eta, rhoAlphaScalar), rhoHat);
|
|
191
|
+
const rStarPackedBytes = new Uint8Array(OT_GADGET_BITS * 32);
|
|
192
|
+
const gadget = getGadgetVector768();
|
|
193
|
+
let sumGR0 = 0n;
|
|
194
|
+
for (let l = 0; l < OT_GADGET_BITS; l++) {
|
|
195
|
+
const r0 = r0Vec[l];
|
|
196
|
+
const rHat0 = rHat0Vec[l];
|
|
197
|
+
const rStarL = addModN(mulModN(eta, r0), rHat0);
|
|
198
|
+
rStarPackedBytes.set(scalarToBytes32(rStarL), l * 32);
|
|
199
|
+
sumGR0 = addModN(sumGR0, mulModN(gadget[l], r0));
|
|
200
|
+
r0Vec[l] = 0n;
|
|
201
|
+
rHat0Vec[l] = 0n;
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
senderShareModN: negModN(sumGR0),
|
|
205
|
+
payload: {
|
|
206
|
+
senderSlotA,
|
|
207
|
+
receiverSlotB,
|
|
208
|
+
cAlphaComp33,
|
|
209
|
+
cHatAlphaComp33,
|
|
210
|
+
uPackedBytes,
|
|
211
|
+
uHatPackedBytes,
|
|
212
|
+
alphaStarBytes32: scalarToBytes32(alphaStar),
|
|
213
|
+
rhoStarBytes32: scalarToBytes32(rhoStar),
|
|
214
|
+
rStarPackedBytes
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Receiver `B` (slot `j`) verifies `C_alpha === C_{k,i}` (Round-1 commitment binding),
|
|
220
|
+
* checks the Pedersen linear combination `\alpha^* G + \rho^* H == \eta C_{k,i} + \hat{C}_\alpha`,
|
|
221
|
+
* verifies all 768 single-row dual-pad equations `\eta t_l + \hat{t}_l == r^*_l + b_l \alpha^* (mod n)`,
|
|
222
|
+
* and outputs additive share `v_B \in Z_n`.
|
|
223
|
+
*/
|
|
224
|
+
function gadgetMtaReceiverVerifyAndFinish(params) {
|
|
225
|
+
const { ctxMta, senderSlotA, receiverSlotB, verifiedReceiverRows, expectedRound1CommitmentCk, payload } = params;
|
|
226
|
+
if (payload.senderSlotA !== senderSlotA || payload.receiverSlotB !== receiverSlotB) throw new MpcProtocolError("MTA_CONSISTENCY_CHECK_FAILED", "MtA payload slot header mismatch", senderSlotA);
|
|
227
|
+
if (!constantTimeEqual(payload.cAlphaComp33, expectedRound1CommitmentCk)) throw new MpcProtocolError("MTA_COMMITMENT_MISMATCH", `MtA C_alpha mismatch against Round-1 C_{k,${senderSlotA}}`, senderSlotA);
|
|
228
|
+
const expectedPackedLen = OT_GADGET_BITS * 32;
|
|
229
|
+
if (payload.uPackedBytes.length !== expectedPackedLen || payload.uHatPackedBytes.length !== expectedPackedLen || payload.rStarPackedBytes.length !== expectedPackedLen) throw new MpcProtocolError("MTA_CONSISTENCY_CHECK_FAILED", "Invalid MtA vector byte length", senderSlotA);
|
|
230
|
+
let cKiPoint;
|
|
231
|
+
let cHatPoint;
|
|
232
|
+
let alphaStar;
|
|
233
|
+
let rhoStar;
|
|
234
|
+
try {
|
|
235
|
+
cKiPoint = decodePointCompressed(expectedRound1CommitmentCk, false);
|
|
236
|
+
cHatPoint = decodePointCompressed(payload.cHatAlphaComp33, false);
|
|
237
|
+
alphaStar = bytes32ToScalarStrict(payload.alphaStarBytes32);
|
|
238
|
+
rhoStar = bytes32ToScalarStrict(payload.rhoStarBytes32);
|
|
239
|
+
} catch (err) {
|
|
240
|
+
throw new MpcProtocolError("MTA_CONSISTENCY_CHECK_FAILED", `Invalid MtA point/scalar from slot ${senderSlotA}: ${err.message}`, senderSlotA);
|
|
241
|
+
}
|
|
242
|
+
const eta = computeMtaEtaChallenge(ctxMta, senderSlotA, receiverSlotB, payload.cAlphaComp33, payload.cHatAlphaComp33, payload.uPackedBytes, payload.uHatPackedBytes);
|
|
243
|
+
const lhsPedersen = pedersenCommit(alphaStar, rhoStar);
|
|
244
|
+
const rhsPedersen = mulPoint(cKiPoint, eta).add(cHatPoint);
|
|
245
|
+
if (!lhsPedersen.equals(rhsPedersen)) throw new MpcProtocolError("MTA_CONSISTENCY_CHECK_FAILED", `MtA Pedersen linear check failed against sender slot ${senderSlotA}`, senderSlotA);
|
|
246
|
+
const gadget = getGadgetVector768();
|
|
247
|
+
let receiverShareAcc = 0n;
|
|
248
|
+
const rowHasher = buildCotRowHasherTemplate(ctxMta);
|
|
249
|
+
try {
|
|
250
|
+
for (let l = 0; l < OT_GADGET_BITS; l++) {
|
|
251
|
+
const bBit = verifiedReceiverRows.gadgetChoiceBits768[l];
|
|
252
|
+
let uL;
|
|
253
|
+
let uHatL;
|
|
254
|
+
let rStarL;
|
|
255
|
+
try {
|
|
256
|
+
uL = bytes32ToScalarStrict(payload.uPackedBytes.subarray(l * 32, (l + 1) * 32));
|
|
257
|
+
uHatL = bytes32ToScalarStrict(payload.uHatPackedBytes.subarray(l * 32, (l + 1) * 32));
|
|
258
|
+
rStarL = bytes32ToScalarStrict(payload.rStarPackedBytes.subarray(l * 32, (l + 1) * 32));
|
|
259
|
+
} catch {
|
|
260
|
+
throw new MpcProtocolError("MTA_CONSISTENCY_CHECK_FAILED", `Out-of-range scalar in MtA row ${l} from sender slot ${senderSlotA}`, senderSlotA);
|
|
261
|
+
}
|
|
262
|
+
const [rLb, rHatLb] = rowHasher.derive(l, bBit, verifiedReceiverRows.tRows768[l]);
|
|
263
|
+
const tL = bBit === 1 ? addModN(rLb, uL) : rLb;
|
|
264
|
+
const tHatL = bBit === 1 ? addModN(rHatLb, uHatL) : rHatLb;
|
|
265
|
+
if (addModN(mulModN(eta, tL), tHatL) !== (bBit === 1 ? addModN(rStarL, alphaStar) : rStarL)) throw new MpcProtocolError("MTA_CONSISTENCY_CHECK_FAILED", `MtA row ${l} consistency check failed against sender slot ${senderSlotA}`, senderSlotA);
|
|
266
|
+
receiverShareAcc = addModN(receiverShareAcc, mulModN(gadget[l], tL));
|
|
267
|
+
}
|
|
268
|
+
} finally {
|
|
269
|
+
rowHasher.destroy();
|
|
270
|
+
}
|
|
271
|
+
return receiverShareAcc;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
//#endregion
|
|
275
|
+
export { decomposeScalarWithLhlGadget, deriveDualPadFromCotRow, gadgetMtaReceiverVerifyAndFinish, gadgetMtaSenderCreateMessage, getGadgetVector768, recombineGadgetBitsModN };
|
package/esm/ot.d.mts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { RandomBytesFn, SchnorrPokProof } from "./secp256k1-scalar.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/ot.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Active-secure IKNP / `KOS15` 1024-row (`768` gadget + `256` sacrifice) OT-Extension
|
|
7
|
+
* with exact inverted Base-OT role orientation (`design.md` §4.4):
|
|
8
|
+
*
|
|
9
|
+
* - **Extended-OT Receiver `B`** (who chooses choice bits `b_0..b_{1023}`) acts as the
|
|
10
|
+
* **Base-OT Sender**, holding `BaseOtSenderState` with 128 seed pairs `(k_{m,0}, k_{m,1})`.
|
|
11
|
+
* - **Extended-OT Sender `A`** (who inputs scalar `k_i`) samples correlation `Delta` (`128` bits)
|
|
12
|
+
* and acts as the **Base-OT Receiver**, holding `BaseOtReceiverState` with `Delta` and ONLY
|
|
13
|
+
* the 128 chosen seeds `k_{m, Delta_m}` (`k_{m, 1 - Delta_m}` is completely unknown to `A`).
|
|
14
|
+
*/
|
|
15
|
+
interface BaseOtSenderState {
|
|
16
|
+
readonly ownerSlotB: number;
|
|
17
|
+
readonly peerSlotA: number;
|
|
18
|
+
readonly ctxBaseOt: Uint8Array;
|
|
19
|
+
readonly seedPairs: ReadonlyArray<readonly [Uint8Array, Uint8Array]>;
|
|
20
|
+
readonly usedSessionKeys: Set<string>;
|
|
21
|
+
invalidated: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface BaseOtReceiverState {
|
|
24
|
+
readonly ownerSlotA: number;
|
|
25
|
+
readonly peerSlotB: number;
|
|
26
|
+
readonly ctxBaseOt: Uint8Array;
|
|
27
|
+
readonly deltaBytes16: Uint8Array;
|
|
28
|
+
readonly deltaBits128: Uint8Array;
|
|
29
|
+
readonly chosenSeeds: ReadonlyArray<Uint8Array>;
|
|
30
|
+
readonly usedSessionKeys: Set<string>;
|
|
31
|
+
invalidated: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface BaseOtStep1Message {
|
|
34
|
+
readonly senderSlotB: number;
|
|
35
|
+
readonly receiverSlotA: number;
|
|
36
|
+
readonly sPointComp33: Uint8Array;
|
|
37
|
+
readonly pokS: SchnorrPokProof;
|
|
38
|
+
}
|
|
39
|
+
interface BaseOtSenderPendingSession {
|
|
40
|
+
readonly senderSlotB: number;
|
|
41
|
+
readonly receiverSlotA: number;
|
|
42
|
+
readonly ctxBaseOt: Uint8Array;
|
|
43
|
+
readonly yScalarBytes32: Uint8Array;
|
|
44
|
+
readonly sPointComp33: Uint8Array;
|
|
45
|
+
completed: boolean;
|
|
46
|
+
}
|
|
47
|
+
interface BaseOtStep2Message {
|
|
48
|
+
readonly senderSlotB: number;
|
|
49
|
+
readonly receiverSlotA: number;
|
|
50
|
+
readonly rPointsComp33: ReadonlyArray<Uint8Array>;
|
|
51
|
+
}
|
|
52
|
+
declare function wipeBaseOtSenderState(state: BaseOtSenderState): void;
|
|
53
|
+
declare function wipeBaseOtReceiverState(state: BaseOtReceiverState): void;
|
|
54
|
+
declare function baseOtSenderStep1(params: {
|
|
55
|
+
ctxBaseOt: Uint8Array;
|
|
56
|
+
senderSlotB: number;
|
|
57
|
+
receiverSlotA: number;
|
|
58
|
+
rng?: RandomBytesFn;
|
|
59
|
+
}): {
|
|
60
|
+
pending: BaseOtSenderPendingSession;
|
|
61
|
+
message: BaseOtStep1Message;
|
|
62
|
+
};
|
|
63
|
+
declare function baseOtReceiverStep2(params: {
|
|
64
|
+
ctxBaseOt: Uint8Array;
|
|
65
|
+
senderSlotB: number;
|
|
66
|
+
receiverSlotA: number;
|
|
67
|
+
step1Message: BaseOtStep1Message;
|
|
68
|
+
rng?: RandomBytesFn;
|
|
69
|
+
}): {
|
|
70
|
+
receiverState: BaseOtReceiverState;
|
|
71
|
+
message: BaseOtStep2Message;
|
|
72
|
+
};
|
|
73
|
+
declare function baseOtSenderStep3(params: {
|
|
74
|
+
pending: BaseOtSenderPendingSession;
|
|
75
|
+
step2Message: BaseOtStep2Message;
|
|
76
|
+
}): BaseOtSenderState;
|
|
77
|
+
declare function bytes16ToU128LE(bytes16: Uint8Array, offset?: number): bigint;
|
|
78
|
+
declare function u128ToBytes16LE(value: bigint): Uint8Array;
|
|
79
|
+
/**
|
|
80
|
+
* Eklundh recursive butterfly `128 x 1024` bit-matrix transpose (`7` log-stages per `128 x 128`
|
|
81
|
+
* sub-block, zero data-dependent branches).
|
|
82
|
+
*
|
|
83
|
+
* Input: `128` columns (`m = 0..127`), each `128` bytes (`1024` bits LSB-first).
|
|
84
|
+
* Output: `1024` rows (`l = 0..1023`), each `16` bytes (`128` bits LSB-first), where
|
|
85
|
+
* bit `m` of `rows[l]` equals bit `l` of `columns[m]`.
|
|
86
|
+
*/
|
|
87
|
+
declare function eklundhTranspose128x1024(columns: ReadonlyArray<Uint8Array>): Uint8Array[];
|
|
88
|
+
declare function gf128Mul(a: bigint, b: bigint): bigint;
|
|
89
|
+
declare function expandKos15ChiWeights(ctxOtExt: Uint8Array, mtaNonce: Uint8Array, xiSeed32: Uint8Array, culpritSlot?: number): bigint[];
|
|
90
|
+
interface OtExtStep1Message {
|
|
91
|
+
readonly mtaNonce: Uint8Array;
|
|
92
|
+
readonly uColumns: ReadonlyArray<Uint8Array>;
|
|
93
|
+
}
|
|
94
|
+
interface OtExtStep2Message {
|
|
95
|
+
readonly mtaNonce: Uint8Array;
|
|
96
|
+
readonly xiSeed32: Uint8Array;
|
|
97
|
+
}
|
|
98
|
+
interface OtExtStep3Message {
|
|
99
|
+
readonly mtaNonce: Uint8Array;
|
|
100
|
+
readonly xBytes16: Uint8Array;
|
|
101
|
+
readonly tChkBytes16: Uint8Array;
|
|
102
|
+
}
|
|
103
|
+
interface OtExtReceiverPendingState {
|
|
104
|
+
readonly ctxOtExt: Uint8Array;
|
|
105
|
+
readonly mtaNonce: Uint8Array;
|
|
106
|
+
readonly allChoiceBits1024: Uint8Array;
|
|
107
|
+
readonly tRows1024: Uint8Array[];
|
|
108
|
+
completed: boolean;
|
|
109
|
+
}
|
|
110
|
+
interface OtExtSenderPendingState {
|
|
111
|
+
readonly baseOtReceiver: BaseOtReceiverState;
|
|
112
|
+
readonly ctxOtExt: Uint8Array;
|
|
113
|
+
readonly mtaNonce: Uint8Array;
|
|
114
|
+
readonly xiSeed32: Uint8Array;
|
|
115
|
+
readonly qRows1024: Uint8Array[];
|
|
116
|
+
completed: boolean;
|
|
117
|
+
}
|
|
118
|
+
interface VerifiedCotReceiverRows {
|
|
119
|
+
readonly ctxOtExt: Uint8Array;
|
|
120
|
+
readonly mtaNonce: Uint8Array;
|
|
121
|
+
readonly gadgetChoiceBits768: Uint8Array;
|
|
122
|
+
readonly tRows768: ReadonlyArray<Uint8Array>;
|
|
123
|
+
}
|
|
124
|
+
interface VerifiedCotSenderRows {
|
|
125
|
+
readonly ctxOtExt: Uint8Array;
|
|
126
|
+
readonly mtaNonce: Uint8Array;
|
|
127
|
+
readonly deltaBytes16: Uint8Array;
|
|
128
|
+
readonly qRows768: ReadonlyArray<Uint8Array>;
|
|
129
|
+
}
|
|
130
|
+
declare function wipeVerifiedCotReceiverRows(rows: VerifiedCotReceiverRows): void;
|
|
131
|
+
declare function wipeVerifiedCotSenderRows(rows: VerifiedCotSenderRows): void;
|
|
132
|
+
/**
|
|
133
|
+
* Step 1 (Extended Receiver `B`, holding `BaseOtSenderState`):
|
|
134
|
+
* Appends `256` fresh CSPRNG sacrifice bits to the `768` gadget choice bits, expands
|
|
135
|
+
* `(t^{(0)}_m, t^{(1)}_m)`, emits `u^{col}_m = t^{(0)}_m ^ t^{(1)}_m ^ b`, and transposes `T_0..T_{1023}`.
|
|
136
|
+
*/
|
|
137
|
+
declare function otExtendReceiverStep1(params: {
|
|
138
|
+
baseOtSender: BaseOtSenderState;
|
|
139
|
+
ctxOtExt: Uint8Array;
|
|
140
|
+
mtaNonce: Uint8Array;
|
|
141
|
+
gadgetChoiceBits768: Uint8Array;
|
|
142
|
+
rng?: RandomBytesFn;
|
|
143
|
+
}): {
|
|
144
|
+
pendingReceiver: OtExtReceiverPendingState;
|
|
145
|
+
step1Message: OtExtStep1Message;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Step 2 (Extended Sender `A`, holding `BaseOtReceiverState`):
|
|
149
|
+
* Receives `B`'s committed columns `uColumns`, expands `z^{col}_m` from `k_{m, Delta_m}`,
|
|
150
|
+
* computes `q^{col}_m = z^{col}_m ^ (Delta_m * u^{col}_m)`, transposes `Q_0..Q_{1023}`, and
|
|
151
|
+
* samples coin-toss challenge `xiSeed32` WITHOUT touching `k_i` or deriving any row pads.
|
|
152
|
+
*/
|
|
153
|
+
declare function otExtendSenderStep2(params: {
|
|
154
|
+
baseOtReceiver: BaseOtReceiverState;
|
|
155
|
+
ctxOtExt: Uint8Array;
|
|
156
|
+
step1Message: OtExtStep1Message;
|
|
157
|
+
rng?: RandomBytesFn;
|
|
158
|
+
}): {
|
|
159
|
+
pendingSender: OtExtSenderPendingState;
|
|
160
|
+
step2Message: OtExtStep2Message;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Step 3 (Extended Receiver `B`):
|
|
164
|
+
* Computes `KOS15` correlation response `(x, T_chk)` over all `1024` rows (masked by the
|
|
165
|
+
* `256` sacrifice bits), wipes sacrifice rows `768..1023`, and returns the `768` gadget rows.
|
|
166
|
+
*/
|
|
167
|
+
declare function otExtendReceiverStep3(params: {
|
|
168
|
+
pendingReceiver: OtExtReceiverPendingState;
|
|
169
|
+
step2Message: OtExtStep2Message;
|
|
170
|
+
peerSenderSlotA?: number;
|
|
171
|
+
}): {
|
|
172
|
+
receiverRows: VerifiedCotReceiverRows;
|
|
173
|
+
step3Message: OtExtStep3Message;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Step 4 (Extended Sender `A`):
|
|
177
|
+
* Strictly verifies `KOS15` `GF(2^128)` correlation check `Q_chk == T_chk ^ (x * Delta)`
|
|
178
|
+
* **before** any pad `(r_{l,b}, r_hat_{l,b})` or MtA ciphertext `(u_l, u_hat_l, r_star_l)` can
|
|
179
|
+
* be computed. On mismatch, immediately zeroizes all `Q_l` AND permanently wipes/drops `Delta`
|
|
180
|
+
* (`BaseOtReceiverState`)!
|
|
181
|
+
*/
|
|
182
|
+
declare function otExtendSenderStep4VerifyBeforePads(params: {
|
|
183
|
+
pendingSender: OtExtSenderPendingState;
|
|
184
|
+
step3Message: OtExtStep3Message;
|
|
185
|
+
}): VerifiedCotSenderRows;
|
|
186
|
+
//#endregion
|
|
187
|
+
export { BaseOtReceiverState, BaseOtSenderPendingSession, BaseOtSenderState, BaseOtStep1Message, BaseOtStep2Message, OtExtReceiverPendingState, OtExtSenderPendingState, OtExtStep1Message, OtExtStep2Message, OtExtStep3Message, VerifiedCotReceiverRows, VerifiedCotSenderRows, baseOtReceiverStep2, baseOtSenderStep1, baseOtSenderStep3, bytes16ToU128LE, eklundhTranspose128x1024, expandKos15ChiWeights, gf128Mul, otExtendReceiverStep1, otExtendReceiverStep3, otExtendSenderStep2, otExtendSenderStep4VerifyBeforePads, u128ToBytes16LE, wipeBaseOtReceiverState, wipeBaseOtSenderState, wipeVerifiedCotReceiverRows, wipeVerifiedCotSenderRows };
|