zapo-js 0.1.1 → 0.2.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/README.md +20 -4
- package/dist/appstate/WaAppStateCrypto.js +19 -26
- package/dist/appstate/WaAppStateSyncClient.js +293 -181
- package/dist/appstate/WaAppStateSyncResponseParser.js +16 -5
- package/dist/appstate/constants.js +4 -3
- package/dist/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/appstate/index.js +8 -6
- package/dist/appstate/utils.js +9 -34
- package/dist/auth/WaAuthClient.js +43 -61
- package/dist/auth/flow/WaAuthCredentialsFlow.js +22 -15
- package/dist/auth/index.js +1 -8
- package/dist/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/auth/pairing/WaPairingFlow.js +34 -26
- package/dist/auth/pairing/WaQrFlow.js +37 -24
- package/dist/client/WaClient.js +275 -324
- package/dist/client/WaClientFactory.js +500 -133
- package/dist/client/connection/WaConnectionManager.js +301 -0
- package/dist/client/connection/WaKeyShareCoordinator.js +63 -0
- package/dist/client/connection/WaReceiptQueue.js +51 -0
- package/dist/client/coordinators/WaAppStateMutationCoordinator.js +471 -0
- package/dist/client/coordinators/WaBusinessCoordinator.js +241 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +30 -16
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +21 -27
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +439 -701
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/client/coordinators/WaPrivacyCoordinator.js +134 -0
- package/dist/client/coordinators/WaProfileCoordinator.js +212 -0
- package/dist/client/coordinators/WaRetryCoordinator.js +242 -57
- package/dist/client/coordinators/WaStreamControlCoordinator.js +18 -11
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +166 -0
- package/dist/client/dirty.js +74 -48
- package/dist/client/events/chat.js +4 -3
- package/dist/client/events/devices.js +72 -0
- package/dist/client/events/group.js +62 -47
- package/dist/client/events/identity.js +22 -0
- package/dist/client/events/privacy-token.js +39 -0
- package/dist/client/history-sync.js +94 -63
- package/dist/client/incoming.js +60 -27
- package/dist/client/mailbox.js +24 -23
- package/dist/client/messages.js +107 -31
- package/dist/client/messaging/fanout.js +199 -0
- package/dist/client/messaging/key-protocol.js +130 -0
- package/dist/client/messaging/participants.js +193 -0
- package/dist/client/persistence/WriteBehindPersistence.js +129 -0
- package/dist/client/tokens/cs-token.js +50 -0
- package/dist/client/tokens/tc-token.js +25 -0
- package/dist/crypto/core/hkdf.js +3 -8
- package/dist/crypto/core/index.js +2 -5
- package/dist/crypto/core/keys.js +6 -7
- package/dist/crypto/core/nonce.js +2 -0
- package/dist/crypto/core/primitives.js +12 -23
- package/dist/crypto/core/random.js +26 -23
- package/dist/crypto/curves/Ed25519.js +7 -8
- package/dist/crypto/curves/X25519.js +38 -22
- package/dist/crypto/index.js +1 -3
- package/dist/crypto/math/constants.js +13 -36
- package/dist/crypto/math/edwards.js +171 -44
- package/dist/crypto/math/fe.js +706 -0
- package/dist/crypto/math/mod.js +10 -3
- package/dist/esm/appstate/WaAppStateCrypto.js +7 -14
- package/dist/esm/appstate/WaAppStateSyncClient.js +284 -172
- package/dist/esm/appstate/WaAppStateSyncResponseParser.js +17 -6
- package/dist/esm/appstate/constants.js +3 -2
- package/dist/esm/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/esm/appstate/index.js +2 -2
- package/dist/esm/appstate/utils.js +8 -30
- package/dist/esm/auth/WaAuthClient.js +43 -61
- package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +22 -15
- package/dist/esm/auth/index.js +0 -3
- package/dist/esm/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/esm/auth/pairing/WaPairingFlow.js +28 -20
- package/dist/esm/auth/pairing/WaQrFlow.js +37 -24
- package/dist/esm/client/WaClient.js +275 -324
- package/dist/esm/client/WaClientFactory.js +501 -134
- package/dist/esm/client/connection/WaConnectionManager.js +297 -0
- package/dist/esm/client/connection/WaKeyShareCoordinator.js +59 -0
- package/dist/esm/client/connection/WaReceiptQueue.js +47 -0
- package/dist/esm/client/coordinators/WaAppStateMutationCoordinator.js +467 -0
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +238 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +23 -9
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +21 -27
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +443 -705
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/esm/client/coordinators/WaPrivacyCoordinator.js +131 -0
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +209 -0
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +244 -59
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +19 -12
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +162 -0
- package/dist/esm/client/dirty.js +69 -43
- package/dist/esm/client/events/chat.js +4 -3
- package/dist/esm/client/events/devices.js +68 -0
- package/dist/esm/client/events/group.js +53 -39
- package/dist/esm/client/events/identity.js +19 -0
- package/dist/esm/client/events/privacy-token.js +36 -0
- package/dist/esm/client/history-sync.js +91 -60
- package/dist/esm/client/incoming.js +61 -28
- package/dist/esm/client/mailbox.js +24 -23
- package/dist/esm/client/messages.js +108 -32
- package/dist/esm/client/messaging/fanout.js +196 -0
- package/dist/esm/client/messaging/key-protocol.js +127 -0
- package/dist/esm/client/messaging/participants.js +190 -0
- package/dist/esm/client/persistence/WriteBehindPersistence.js +125 -0
- package/dist/esm/client/tokens/cs-token.js +46 -0
- package/dist/esm/client/tokens/tc-token.js +18 -0
- package/dist/esm/crypto/core/hkdf.js +3 -8
- package/dist/esm/crypto/core/index.js +2 -3
- package/dist/esm/crypto/core/keys.js +3 -4
- package/dist/esm/crypto/core/nonce.js +2 -0
- package/dist/esm/crypto/core/primitives.js +12 -22
- package/dist/esm/crypto/core/random.js +25 -23
- package/dist/esm/crypto/curves/Ed25519.js +4 -5
- package/dist/esm/crypto/curves/X25519.js +35 -19
- package/dist/esm/crypto/index.js +0 -1
- package/dist/esm/crypto/math/constants.js +12 -35
- package/dist/esm/crypto/math/edwards.js +174 -47
- package/dist/esm/crypto/math/fe.js +691 -0
- package/dist/esm/crypto/math/mod.js +10 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/infra/log/ConsoleLogger.js +18 -17
- package/dist/esm/infra/log/PinoLogger.js +15 -9
- package/dist/esm/infra/log/types.js +11 -1
- package/dist/esm/infra/perf/BackgroundQueue.js +478 -0
- package/dist/esm/infra/perf/BoundedTaskQueue.js +16 -18
- package/dist/esm/infra/perf/PromiseDedup.js +20 -0
- package/dist/esm/infra/perf/SharedExclusiveGate.js +109 -0
- package/dist/esm/infra/perf/StoreLock.js +77 -0
- package/dist/esm/media/WaMediaCrypto.js +96 -16
- package/dist/esm/media/WaMediaTransferClient.js +251 -91
- package/dist/esm/media/conn.js +10 -6
- package/dist/esm/media/constants.js +6 -2
- package/dist/esm/message/WaMessageClient.js +30 -32
- package/dist/esm/message/ack.js +6 -6
- package/dist/esm/message/addon-crypto.js +59 -0
- package/dist/esm/message/content.js +195 -9
- package/dist/esm/message/icdc.js +76 -0
- package/dist/esm/message/incoming.js +129 -122
- package/dist/esm/message/index.js +2 -0
- package/dist/esm/message/phash.js +3 -1
- package/dist/esm/message/reporting-token.js +425 -0
- package/dist/esm/message/use-case-secret.js +49 -0
- package/dist/esm/protocol/appstate.js +27 -0
- package/dist/esm/protocol/browser.js +10 -18
- package/dist/esm/protocol/constants.js +6 -3
- package/dist/esm/protocol/defaults.js +6 -0
- package/dist/esm/protocol/index.js +2 -11
- package/dist/esm/protocol/jid.js +133 -52
- package/dist/esm/protocol/media.js +3 -3
- package/dist/esm/protocol/message.js +61 -1
- package/dist/esm/protocol/nodes.js +4 -0
- package/dist/esm/protocol/notification.js +3 -1
- package/dist/esm/protocol/privacy-token.js +17 -0
- package/dist/esm/protocol/privacy.js +55 -0
- package/dist/esm/protocol/stream.js +26 -1
- package/dist/esm/protocol/usync.js +11 -0
- package/dist/esm/retry/codec.js +216 -0
- package/dist/esm/retry/constants.js +1 -1
- package/dist/esm/retry/index.js +3 -2
- package/dist/esm/retry/parse.js +88 -86
- package/dist/esm/retry/replay.js +54 -51
- package/dist/esm/retry/tracker.js +94 -0
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +276 -92
- package/dist/esm/signal/api/SignalDigestSyncApi.js +17 -8
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +67 -37
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +86 -67
- package/dist/esm/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/esm/signal/api/SignalSessionSyncApi.js +36 -34
- package/dist/esm/signal/api/result-map.js +10 -0
- package/dist/esm/signal/constants.js +0 -4
- package/dist/esm/signal/crypto/WaAdvSignature.js +13 -9
- package/dist/esm/signal/{store/sqlite.js → encoding.js} +93 -60
- package/dist/esm/signal/group/SenderKeyChain.js +28 -23
- package/dist/esm/signal/group/SenderKeyCodec.js +5 -6
- package/dist/esm/signal/group/SenderKeyManager.js +144 -115
- package/dist/esm/signal/index.js +2 -0
- package/dist/esm/signal/registration/keygen.js +6 -2
- package/dist/esm/signal/registration/utils.js +1 -0
- package/dist/esm/signal/session/SignalProtocol.js +164 -53
- package/dist/esm/signal/session/SignalRatchet.js +24 -15
- package/dist/esm/signal/session/SignalSession.js +14 -9
- package/dist/esm/signal/session/resolver.js +221 -0
- package/dist/esm/store/contracts/privacy-token.store.js +1 -0
- package/dist/esm/store/createStore.js +100 -188
- package/dist/esm/store/index.js +1 -10
- package/dist/esm/store/locks/appstate.lock.js +26 -0
- package/dist/esm/store/locks/auth.lock.js +15 -0
- package/dist/esm/store/locks/contact.lock.js +20 -0
- package/dist/esm/store/locks/device-list.lock.js +20 -0
- package/dist/esm/store/locks/message.lock.js +21 -0
- package/dist/esm/store/locks/participants.lock.js +20 -0
- package/dist/esm/store/locks/privacy-token.lock.js +18 -0
- package/dist/esm/store/locks/retry.lock.js +29 -0
- package/dist/esm/store/locks/sender-key.lock.js +52 -0
- package/dist/esm/store/locks/signal.lock.js +63 -0
- package/dist/esm/store/locks/thread.lock.js +21 -0
- package/dist/esm/store/noop.store.js +4 -7
- package/dist/esm/store/providers/memory/appstate.store.js +38 -16
- package/dist/esm/store/providers/memory/contact.store.js +5 -0
- package/dist/esm/store/providers/memory/device-list.store.js +12 -34
- package/dist/esm/store/providers/memory/message.store.js +11 -5
- package/dist/esm/store/providers/memory/participants.store.js +1 -8
- package/dist/esm/store/providers/memory/privacy-token.store.js +43 -0
- package/dist/esm/store/providers/memory/retry.store.js +77 -2
- package/dist/esm/store/providers/memory/sender-key.store.js +11 -8
- package/dist/esm/store/providers/memory/signal.store.js +47 -18
- package/dist/esm/store/providers/memory/thread.store.js +5 -0
- package/dist/esm/transport/WaComms.js +28 -24
- package/dist/esm/transport/WaWebSocket.js +115 -18
- package/dist/esm/transport/binary/constants.js +0 -30
- package/dist/esm/transport/binary/decoder.js +8 -8
- package/dist/esm/transport/binary/encoder.js +10 -9
- package/dist/esm/transport/binary/index.js +0 -1
- package/dist/esm/transport/index.js +1 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +2 -8
- package/dist/esm/transport/node/WaNodeOrchestrator.js +25 -21
- package/dist/esm/transport/node/WaNodeTransport.js +0 -3
- package/dist/esm/transport/node/builders/{accountSync.js → account-sync.js} +16 -36
- package/dist/esm/transport/node/builders/business.js +129 -0
- package/dist/esm/transport/node/builders/global.js +370 -0
- package/dist/esm/transport/node/builders/index.js +7 -3
- package/dist/esm/transport/node/builders/message.js +63 -230
- package/dist/esm/transport/node/builders/pairing.js +2 -27
- package/dist/esm/transport/node/builders/privacy-token.js +41 -0
- package/dist/esm/transport/node/builders/privacy.js +48 -0
- package/dist/esm/transport/node/builders/profile.js +70 -0
- package/dist/esm/transport/node/builders/retry.js +10 -22
- package/dist/esm/transport/node/builders/usync.js +45 -0
- package/dist/esm/transport/node/helpers.js +125 -5
- package/dist/esm/transport/node/usync.js +5 -0
- package/dist/esm/transport/node/xml.js +35 -14
- package/dist/esm/transport/noise/WaClientPayload.js +10 -10
- package/dist/esm/transport/noise/WaFrameCodec.js +48 -33
- package/dist/esm/transport/noise/WaNoiseCert.js +4 -7
- package/dist/esm/transport/noise/WaNoiseSession.js +77 -29
- package/dist/esm/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/esm/transport/proxy.js +27 -0
- package/dist/esm/transport/stream/parse.js +17 -48
- package/dist/esm/util/bytes.js +67 -45
- package/dist/esm/util/coercion.js +6 -14
- package/dist/esm/util/index.js +5 -0
- package/dist/esm/util/primitives.js +40 -14
- package/dist/index.js +7 -1
- package/dist/infra/log/ConsoleLogger.js +18 -17
- package/dist/infra/log/PinoLogger.js +15 -9
- package/dist/infra/log/types.js +12 -0
- package/dist/infra/perf/BackgroundQueue.js +482 -0
- package/dist/infra/perf/BoundedTaskQueue.js +16 -18
- package/dist/infra/perf/PromiseDedup.js +24 -0
- package/dist/infra/perf/SharedExclusiveGate.js +113 -0
- package/dist/infra/perf/StoreLock.js +81 -0
- package/dist/media/WaMediaCrypto.js +95 -15
- package/dist/media/WaMediaTransferClient.js +284 -91
- package/dist/media/conn.js +10 -6
- package/dist/media/constants.js +6 -2
- package/dist/message/WaMessageClient.js +31 -33
- package/dist/message/ack.js +6 -6
- package/dist/message/addon-crypto.js +65 -0
- package/dist/message/content.js +198 -9
- package/dist/message/icdc.js +81 -0
- package/dist/message/incoming.js +127 -120
- package/dist/message/index.js +2 -0
- package/dist/message/phash.js +3 -1
- package/dist/message/reporting-token.js +429 -0
- package/dist/message/use-case-secret.js +55 -0
- package/dist/protocol/appstate.js +28 -1
- package/dist/protocol/browser.js +10 -18
- package/dist/protocol/constants.js +26 -1
- package/dist/protocol/defaults.js +6 -0
- package/dist/protocol/index.js +23 -42
- package/dist/protocol/jid.js +140 -52
- package/dist/protocol/media.js +3 -3
- package/dist/protocol/message.js +62 -2
- package/dist/protocol/nodes.js +4 -0
- package/dist/protocol/notification.js +3 -1
- package/dist/protocol/privacy-token.js +20 -0
- package/dist/protocol/privacy.js +58 -0
- package/dist/protocol/stream.js +27 -2
- package/dist/protocol/usync.js +14 -0
- package/dist/retry/codec.js +220 -0
- package/dist/retry/constants.js +1 -1
- package/dist/retry/index.js +7 -5
- package/dist/retry/parse.js +88 -85
- package/dist/retry/replay.js +52 -49
- package/dist/retry/tracker.js +97 -0
- package/dist/signal/api/SignalDeviceSyncApi.js +273 -89
- package/dist/signal/api/SignalDigestSyncApi.js +17 -8
- package/dist/signal/api/SignalIdentitySyncApi.js +66 -36
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +82 -63
- package/dist/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/signal/api/SignalSessionSyncApi.js +36 -34
- package/dist/signal/api/result-map.js +13 -0
- package/dist/signal/constants.js +1 -5
- package/dist/signal/crypto/WaAdvSignature.js +11 -7
- package/dist/signal/{store/sqlite.js → encoding.js} +94 -61
- package/dist/signal/group/SenderKeyChain.js +27 -22
- package/dist/signal/group/SenderKeyCodec.js +5 -6
- package/dist/signal/group/SenderKeyManager.js +144 -115
- package/dist/signal/index.js +15 -1
- package/dist/signal/registration/keygen.js +6 -2
- package/dist/signal/registration/utils.js +1 -0
- package/dist/signal/session/SignalProtocol.js +164 -53
- package/dist/signal/session/SignalRatchet.js +24 -15
- package/dist/signal/session/SignalSession.js +14 -9
- package/dist/signal/session/resolver.js +224 -0
- package/dist/store/contracts/privacy-token.store.js +2 -0
- package/dist/store/createStore.js +100 -188
- package/dist/store/index.js +15 -33
- package/dist/store/locks/appstate.lock.js +29 -0
- package/dist/store/locks/auth.lock.js +18 -0
- package/dist/store/locks/contact.lock.js +23 -0
- package/dist/store/locks/device-list.lock.js +23 -0
- package/dist/store/locks/message.lock.js +24 -0
- package/dist/store/locks/participants.lock.js +23 -0
- package/dist/store/locks/privacy-token.lock.js +21 -0
- package/dist/store/locks/retry.lock.js +32 -0
- package/dist/store/locks/sender-key.lock.js +55 -0
- package/dist/store/locks/signal.lock.js +66 -0
- package/dist/store/locks/thread.lock.js +24 -0
- package/dist/store/noop.store.js +4 -7
- package/dist/store/providers/memory/appstate.store.js +36 -14
- package/dist/store/providers/memory/contact.store.js +5 -0
- package/dist/store/providers/memory/device-list.store.js +12 -34
- package/dist/store/providers/memory/message.store.js +11 -5
- package/dist/store/providers/memory/participants.store.js +1 -8
- package/dist/store/providers/memory/privacy-token.store.js +47 -0
- package/dist/store/providers/memory/retry.store.js +77 -2
- package/dist/store/providers/memory/sender-key.store.js +14 -11
- package/dist/store/providers/memory/signal.store.js +54 -25
- package/dist/store/providers/memory/thread.store.js +5 -0
- package/dist/transport/WaComms.js +30 -26
- package/dist/transport/WaWebSocket.js +148 -18
- package/dist/transport/binary/constants.js +1 -31
- package/dist/transport/binary/decoder.js +8 -8
- package/dist/transport/binary/encoder.js +10 -9
- package/dist/transport/binary/index.js +0 -4
- package/dist/transport/index.js +7 -1
- package/dist/transport/keepalive/WaKeepAlive.js +1 -7
- package/dist/transport/node/WaNodeOrchestrator.js +25 -21
- package/dist/transport/node/WaNodeTransport.js +0 -3
- package/dist/transport/node/builders/{accountSync.js → account-sync.js} +15 -35
- package/dist/transport/node/builders/business.js +137 -0
- package/dist/transport/node/builders/global.js +375 -0
- package/dist/transport/node/builders/index.js +29 -17
- package/dist/transport/node/builders/message.js +64 -236
- package/dist/transport/node/builders/pairing.js +2 -29
- package/dist/transport/node/builders/privacy-token.js +46 -0
- package/dist/transport/node/builders/privacy.js +55 -0
- package/dist/transport/node/builders/profile.js +78 -0
- package/dist/transport/node/builders/retry.js +9 -21
- package/dist/transport/node/builders/usync.js +49 -0
- package/dist/transport/node/helpers.js +131 -4
- package/dist/transport/node/usync.js +8 -0
- package/dist/transport/node/xml.js +35 -14
- package/dist/transport/noise/WaClientPayload.js +13 -13
- package/dist/transport/noise/WaFrameCodec.js +47 -32
- package/dist/transport/noise/WaNoiseCert.js +5 -8
- package/dist/transport/noise/WaNoiseSession.js +77 -29
- package/dist/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/transport/proxy.js +34 -0
- package/dist/transport/stream/parse.js +20 -52
- package/dist/types/appstate/WaAppStateCrypto.d.ts +0 -1
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +5 -2
- package/dist/types/appstate/constants.d.ts +1 -0
- package/dist/types/appstate/encoding.d.ts +7 -0
- package/dist/types/appstate/index.d.ts +3 -3
- package/dist/types/appstate/utils.d.ts +0 -3
- package/dist/types/auth/WaAuthClient.d.ts +10 -12
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +1 -1
- package/dist/types/auth/index.d.ts +0 -4
- package/dist/types/auth/pairing/WaQrFlow.d.ts +1 -1
- package/dist/types/auth/types.d.ts +7 -9
- package/dist/types/client/WaClient.d.ts +42 -25
- package/dist/types/client/WaClientFactory.d.ts +33 -26
- package/dist/types/client/connection/WaConnectionManager.d.ts +66 -0
- package/dist/types/client/connection/WaKeyShareCoordinator.d.ts +14 -0
- package/dist/types/client/connection/WaReceiptQueue.d.ts +13 -0
- package/dist/types/client/coordinators/WaAppStateMutationCoordinator.d.ts +46 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +57 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +3 -2
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +29 -38
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +4 -0
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +36 -0
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +8 -0
- package/dist/types/client/coordinators/WaStreamControlCoordinator.d.ts +3 -2
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +45 -0
- package/dist/types/client/dirty.d.ts +1 -0
- package/dist/types/client/events/devices.d.ts +20 -0
- package/dist/types/client/events/group.d.ts +2 -1
- package/dist/types/client/events/identity.d.ts +9 -0
- package/dist/types/client/events/privacy-token.d.ts +7 -0
- package/dist/types/client/history-sync.d.ts +9 -6
- package/dist/types/client/incoming.d.ts +3 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/mailbox.d.ts +3 -5
- package/dist/types/client/messages.d.ts +1 -2
- package/dist/types/client/messaging/fanout.d.ts +14 -0
- package/dist/types/client/messaging/key-protocol.d.ts +18 -0
- package/dist/types/client/messaging/participants.d.ts +13 -0
- package/dist/types/client/persistence/WriteBehindPersistence.d.ts +34 -0
- package/dist/types/client/tokens/cs-token.d.ts +10 -0
- package/dist/types/client/tokens/tc-token.d.ts +5 -0
- package/dist/types/client/types.d.ts +75 -4
- package/dist/types/crypto/core/hkdf.d.ts +0 -6
- package/dist/types/crypto/core/index.d.ts +2 -3
- package/dist/types/crypto/core/nonce.d.ts +2 -0
- package/dist/types/crypto/core/primitives.d.ts +0 -1
- package/dist/types/crypto/core/random.d.ts +2 -7
- package/dist/types/crypto/index.d.ts +0 -1
- package/dist/types/crypto/math/constants.d.ts +4 -2
- package/dist/types/crypto/math/fe.d.ts +30 -0
- package/dist/types/crypto/math/mod.d.ts +0 -2
- package/dist/types/crypto/math/types.d.ts +11 -4
- package/dist/types/index.d.ts +5 -3
- package/dist/types/infra/log/ConsoleLogger.d.ts +2 -1
- package/dist/types/infra/log/PinoLogger.d.ts +1 -1
- package/dist/types/infra/log/types.d.ts +1 -0
- package/dist/types/infra/perf/BackgroundQueue.d.ts +58 -0
- package/dist/types/infra/perf/BoundedTaskQueue.d.ts +1 -1
- package/dist/types/infra/perf/PromiseDedup.d.ts +4 -0
- package/dist/types/infra/perf/SharedExclusiveGate.d.ts +17 -0
- package/dist/types/infra/perf/StoreLock.d.ts +10 -0
- package/dist/types/media/WaMediaCrypto.d.ts +3 -2
- package/dist/types/media/WaMediaTransferClient.d.ts +16 -15
- package/dist/types/media/constants.d.ts +1 -1
- package/dist/types/media/index.d.ts +1 -1
- package/dist/types/media/types.d.ts +15 -2
- package/dist/types/message/addon-crypto.d.ts +25 -0
- package/dist/types/message/content.d.ts +8 -0
- package/dist/types/message/icdc.d.ts +13 -0
- package/dist/types/message/index.d.ts +2 -0
- package/dist/types/message/reporting-token.d.ts +18 -0
- package/dist/types/message/types.d.ts +45 -6
- package/dist/types/message/use-case-secret.d.ts +20 -0
- package/dist/types/protocol/appstate.d.ts +47 -0
- package/dist/types/protocol/constants.d.ts +8 -3
- package/dist/types/protocol/defaults.d.ts +6 -0
- package/dist/types/protocol/index.d.ts +2 -11
- package/dist/types/protocol/jid.d.ts +22 -5
- package/dist/types/protocol/message.d.ts +60 -0
- package/dist/types/protocol/nodes.d.ts +4 -0
- package/dist/types/protocol/notification.d.ts +2 -0
- package/dist/types/protocol/privacy-token.d.ts +17 -0
- package/dist/types/protocol/privacy.d.ts +75 -0
- package/dist/types/protocol/stream.d.ts +30 -0
- package/dist/types/protocol/usync.d.ts +11 -0
- package/dist/types/retry/codec.d.ts +3 -0
- package/dist/types/retry/index.d.ts +4 -3
- package/dist/types/retry/parse.d.ts +5 -2
- package/dist/types/retry/replay.d.ts +0 -4
- package/dist/types/retry/tracker.d.ts +20 -0
- package/dist/types/retry/types.d.ts +10 -4
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +15 -2
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +6 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +2 -0
- package/dist/types/signal/api/SignalRotateKeyApi.d.ts +4 -5
- package/dist/types/signal/api/SignalSessionSyncApi.d.ts +8 -6
- package/dist/types/signal/api/result-map.d.ts +1 -0
- package/dist/types/signal/constants.d.ts +0 -3
- package/dist/types/signal/{store/sqlite.d.ts → encoding.d.ts} +3 -3
- package/dist/types/signal/group/SenderKeyCodec.d.ts +4 -6
- package/dist/types/signal/group/SenderKeyManager.d.ts +10 -5
- package/dist/types/signal/index.d.ts +3 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +19 -4
- package/dist/types/signal/session/resolver.d.ts +22 -0
- package/dist/types/store/contracts/appstate.store.d.ts +4 -1
- package/dist/types/store/contracts/contact.store.d.ts +1 -0
- package/dist/types/store/contracts/device-list.store.d.ts +0 -3
- package/dist/types/store/contracts/message.store.d.ts +1 -0
- package/dist/types/store/contracts/participants.store.d.ts +0 -1
- package/dist/types/store/contracts/privacy-token.store.d.ts +16 -0
- package/dist/types/store/contracts/retry.store.d.ts +7 -0
- package/dist/types/store/contracts/sender-key.store.d.ts +0 -1
- package/dist/types/store/contracts/signal.store.d.ts +13 -0
- package/dist/types/store/contracts/thread.store.d.ts +1 -0
- package/dist/types/store/createStore.d.ts +1 -1
- package/dist/types/store/index.d.ts +5 -13
- package/dist/types/store/locks/appstate.lock.d.ts +3 -0
- package/dist/types/store/locks/auth.lock.d.ts +3 -0
- package/dist/types/store/locks/contact.lock.d.ts +3 -0
- package/dist/types/store/locks/device-list.lock.d.ts +2 -0
- package/dist/types/store/locks/message.lock.d.ts +3 -0
- package/dist/types/store/locks/participants.lock.d.ts +2 -0
- package/dist/types/store/locks/privacy-token.lock.d.ts +2 -0
- package/dist/types/store/locks/retry.lock.d.ts +2 -0
- package/dist/types/store/locks/sender-key.lock.d.ts +3 -0
- package/dist/types/store/locks/signal.lock.d.ts +3 -0
- package/dist/types/store/locks/thread.lock.d.ts +3 -0
- package/dist/types/store/providers/memory/appstate.store.d.ts +3 -1
- package/dist/types/store/providers/memory/contact.store.d.ts +1 -0
- package/dist/types/store/providers/memory/device-list.store.d.ts +0 -3
- package/dist/types/store/providers/memory/message.store.d.ts +1 -0
- package/dist/types/store/providers/memory/participants.store.d.ts +0 -1
- package/dist/types/store/providers/memory/privacy-token.store.d.ts +13 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +8 -0
- package/dist/types/store/providers/memory/sender-key.store.d.ts +0 -1
- package/dist/types/store/providers/memory/signal.store.d.ts +8 -1
- package/dist/types/store/providers/memory/thread.store.d.ts +1 -0
- package/dist/types/store/types.d.ts +49 -58
- package/dist/types/transport/WaWebSocket.d.ts +3 -1
- package/dist/types/transport/binary/constants.d.ts +0 -30
- package/dist/types/transport/binary/index.d.ts +0 -1
- package/dist/types/transport/index.d.ts +2 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +0 -1
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +3 -4
- package/dist/types/transport/node/WaNodeTransport.d.ts +0 -9
- package/dist/types/transport/node/builders/business.d.ts +29 -0
- package/dist/types/transport/node/builders/global.d.ts +102 -0
- package/dist/types/transport/node/builders/group.d.ts +4 -6
- package/dist/types/transport/node/builders/index.d.ts +7 -3
- package/dist/types/transport/node/builders/message.d.ts +20 -30
- package/dist/types/transport/node/builders/pairing.d.ts +0 -2
- package/dist/types/transport/node/builders/privacy-token.d.ts +9 -0
- package/dist/types/transport/node/builders/privacy.d.ts +7 -0
- package/dist/types/transport/node/builders/profile.d.ts +8 -0
- package/dist/types/transport/node/builders/retry.d.ts +2 -5
- package/dist/types/transport/node/builders/usync.d.ts +21 -0
- package/dist/types/transport/node/helpers.d.ts +13 -0
- package/dist/types/transport/node/usync.d.ts +2 -0
- package/dist/types/transport/noise/WaFrameCodec.d.ts +3 -0
- package/dist/types/transport/noise/WaNoiseSession.d.ts +4 -2
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +4 -2
- package/dist/types/transport/proxy.d.ts +6 -0
- package/dist/types/transport/stream/parse.d.ts +0 -1
- package/dist/types/transport/types.d.ts +18 -1
- package/dist/types/util/bytes.d.ts +5 -0
- package/dist/types/util/index.d.ts +5 -0
- package/dist/types/util/primitives.d.ts +2 -0
- package/dist/util/bytes.js +72 -46
- package/dist/util/coercion.js +6 -14
- package/dist/util/index.js +23 -0
- package/dist/util/primitives.js +42 -14
- package/package.json +52 -9
- package/proto/index.js +1 -1
- package/dist/crypto/core/constants.js +0 -4
- package/dist/crypto/core/encoding.js +0 -29
- package/dist/esm/crypto/core/constants.js +0 -1
- package/dist/esm/crypto/core/encoding.js +0 -25
- package/dist/esm/retry/outbound.js +0 -83
- package/dist/esm/store/providers/sqlite/BaseSqliteStore.js +0 -37
- package/dist/esm/store/providers/sqlite/appstate.store.js +0 -169
- package/dist/esm/store/providers/sqlite/auth.store.js +0 -176
- package/dist/esm/store/providers/sqlite/connection.js +0 -240
- package/dist/esm/store/providers/sqlite/contact.store.js +0 -61
- package/dist/esm/store/providers/sqlite/device-list.store.js +0 -155
- package/dist/esm/store/providers/sqlite/message.store.js +0 -119
- package/dist/esm/store/providers/sqlite/migrations.js +0 -347
- package/dist/esm/store/providers/sqlite/participants.store.js +0 -85
- package/dist/esm/store/providers/sqlite/retry.store.js +0 -144
- package/dist/esm/store/providers/sqlite/sender-key.store.js +0 -203
- package/dist/esm/store/providers/sqlite/signal.store.js +0 -353
- package/dist/esm/store/providers/sqlite/thread.store.js +0 -72
- package/dist/esm/util/base64.js +0 -18
- package/dist/esm/util/signal-address.js +0 -5
- package/dist/retry/outbound.js +0 -88
- package/dist/store/providers/sqlite/BaseSqliteStore.js +0 -41
- package/dist/store/providers/sqlite/appstate.store.js +0 -173
- package/dist/store/providers/sqlite/auth.store.js +0 -180
- package/dist/store/providers/sqlite/connection.js +0 -276
- package/dist/store/providers/sqlite/contact.store.js +0 -65
- package/dist/store/providers/sqlite/device-list.store.js +0 -159
- package/dist/store/providers/sqlite/message.store.js +0 -123
- package/dist/store/providers/sqlite/migrations.js +0 -350
- package/dist/store/providers/sqlite/participants.store.js +0 -89
- package/dist/store/providers/sqlite/retry.store.js +0 -148
- package/dist/store/providers/sqlite/sender-key.store.js +0 -207
- package/dist/store/providers/sqlite/signal.store.js +0 -357
- package/dist/store/providers/sqlite/thread.store.js +0 -76
- package/dist/types/appstate/store/sqlite.d.ts +0 -21
- package/dist/types/crypto/core/constants.d.ts +0 -1
- package/dist/types/crypto/core/encoding.d.ts +0 -11
- package/dist/types/retry/outbound.d.ts +0 -4
- package/dist/types/store/providers/sqlite/BaseSqliteStore.d.ts +0 -12
- package/dist/types/store/providers/sqlite/appstate.store.d.ts +0 -15
- package/dist/types/store/providers/sqlite/auth.store.d.ts +0 -10
- package/dist/types/store/providers/sqlite/connection.d.ts +0 -10
- package/dist/types/store/providers/sqlite/contact.store.d.ts +0 -10
- package/dist/types/store/providers/sqlite/device-list.store.d.ts +0 -18
- package/dist/types/store/providers/sqlite/message.store.d.ts +0 -11
- package/dist/types/store/providers/sqlite/migrations.d.ts +0 -3
- package/dist/types/store/providers/sqlite/participants.store.d.ts +0 -13
- package/dist/types/store/providers/sqlite/retry.store.d.ts +0 -16
- package/dist/types/store/providers/sqlite/sender-key.store.d.ts +0 -25
- package/dist/types/store/providers/sqlite/signal.store.d.ts +0 -46
- package/dist/types/store/providers/sqlite/thread.store.d.ts +0 -11
- package/dist/types/util/base64.d.ts +0 -4
- package/dist/types/util/signal-address.d.ts +0 -2
- package/dist/util/base64.js +0 -24
- package/dist/util/signal-address.js +0 -8
- /package/dist/types/transport/node/builders/{accountSync.d.ts → account-sync.d.ts} +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function computeBucket(unixTimeS, durationS) {
|
|
2
|
+
return Math.floor(unixTimeS / durationS);
|
|
3
|
+
}
|
|
4
|
+
export function tokenExpirationCutoffS(nowS, durationS, numBuckets) {
|
|
5
|
+
const currentBucket = computeBucket(nowS, durationS);
|
|
6
|
+
const cutoffBucket = currentBucket - numBuckets;
|
|
7
|
+
return cutoffBucket * durationS;
|
|
8
|
+
}
|
|
9
|
+
export function isTokenExpired(tokenTimestampS, nowS, durationS, numBuckets) {
|
|
10
|
+
const cutoff = tokenExpirationCutoffS(nowS, durationS, numBuckets);
|
|
11
|
+
return tokenTimestampS < cutoff;
|
|
12
|
+
}
|
|
13
|
+
export function shouldSendNewToken(senderTimestampS, nowS, senderDurationS) {
|
|
14
|
+
return computeBucket(senderTimestampS, senderDurationS) !== computeBucket(nowS, senderDurationS);
|
|
15
|
+
}
|
|
16
|
+
export function clampDuration(durationS, maxDurationS) {
|
|
17
|
+
return Math.min(durationS, maxDurationS);
|
|
18
|
+
}
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import { webcrypto } from 'node:crypto';
|
|
2
2
|
import { EMPTY_BYTES, TEXT_ENCODER, toBytesView } from '../../util/bytes.js';
|
|
3
|
-
/**
|
|
4
|
-
* HKDF key derivation using SHA-256
|
|
5
|
-
*/
|
|
6
3
|
export async function hkdf(ikm, salt, info, outLength) {
|
|
7
4
|
const key = await webcrypto.subtle.importKey('raw', ikm, 'HKDF', false, ['deriveBits']);
|
|
5
|
+
const infoBytes = typeof info === 'string' ? (info === '' ? EMPTY_BYTES : TEXT_ENCODER.encode(info)) : info;
|
|
8
6
|
const bits = await webcrypto.subtle.deriveBits({
|
|
9
7
|
name: 'HKDF',
|
|
10
8
|
hash: 'SHA-256',
|
|
11
9
|
salt: salt ?? EMPTY_BYTES,
|
|
12
|
-
info:
|
|
10
|
+
info: infoBytes
|
|
13
11
|
}, key, outLength * 8);
|
|
14
12
|
return toBytesView(bits);
|
|
15
13
|
}
|
|
16
|
-
/**
|
|
17
|
-
* HKDF key derivation that outputs two 32-byte keys
|
|
18
|
-
*/
|
|
19
14
|
export async function hkdfSplit(ikm, salt, info) {
|
|
20
15
|
const out = await hkdf(ikm, salt, info, 64);
|
|
21
|
-
return [out.subarray(0, 32), out.subarray(32
|
|
16
|
+
return [out.subarray(0, 32), out.subarray(32)];
|
|
22
17
|
}
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { Ed25519 } from '../curves/Ed25519.js';
|
|
5
5
|
export { X25519 } from '../curves/X25519.js';
|
|
6
|
-
export { decodeBase64Url, assert32 } from '../core/encoding.js';
|
|
7
6
|
export { hkdf, hkdfSplit } from '../core/hkdf.js';
|
|
8
7
|
export { toSerializedPubKey, toRawPubKey, prependVersion, readVersionedContent } from '../core/keys.js';
|
|
9
8
|
export { buildNonce } from '../core/nonce.js';
|
|
10
|
-
export { randomBytesAsync, randomIntAsync } from '../core/random.js';
|
|
11
|
-
export { sha1, sha256, sha512, importAesGcmKey, aesGcmEncrypt, aesGcmDecrypt, importAesCbcKey, aesCbcEncrypt, aesCbcDecrypt, importHmacKey, importHmacSha512Key, hmacSign, pbkdf2DeriveAesCtrKey, aesCtrEncrypt, aesCtrDecrypt
|
|
9
|
+
export { randomBytesAsync, randomFillAsync, randomIntAsync } from '../core/random.js';
|
|
10
|
+
export { sha1, sha256, sha512, importAesGcmKey, aesGcmEncrypt, aesGcmDecrypt, importAesCbcKey, aesCbcEncrypt, aesCbcDecrypt, importHmacKey, importHmacSha512Key, hmacSign, pbkdf2DeriveAesCtrKey, aesCtrEncrypt, aesCtrDecrypt } from '../core/primitives.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assertByteLength } from '../../util/bytes.js';
|
|
2
|
+
const SERIALIZED_PUB_KEY_PREFIX = 5;
|
|
2
3
|
/**
|
|
3
4
|
* Converts a 32-byte raw public key to 33-byte serialized format (with 0x05 prefix)
|
|
4
5
|
*/
|
|
@@ -9,9 +10,7 @@ export function toSerializedPubKey(key) {
|
|
|
9
10
|
}
|
|
10
11
|
return key;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
throw new Error(`invalid signal public key length ${key.length}`);
|
|
14
|
-
}
|
|
13
|
+
assertByteLength(key, 32, `invalid signal public key length ${key.length}`);
|
|
15
14
|
const out = new Uint8Array(33);
|
|
16
15
|
out[0] = SERIALIZED_PUB_KEY_PREFIX;
|
|
17
16
|
out.set(key, 1);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Builds a 12-byte nonce for AES-GCM encryption with counter in the last 4 bytes.
|
|
3
|
+
* Allocates a new buffer per call because concurrent Noise encrypt/decrypt operations
|
|
4
|
+
* may hold references to different nonces simultaneously.
|
|
3
5
|
* Throws if counter exceeds uint32 range to prevent nonce reuse.
|
|
4
6
|
*/
|
|
5
7
|
export function buildNonce(counter) {
|
|
@@ -3,17 +3,20 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { createHash, webcrypto } from 'node:crypto';
|
|
5
5
|
import { EMPTY_BYTES, toBytesView } from '../../util/bytes.js';
|
|
6
|
+
async function digestBytes(algorithm, value) {
|
|
7
|
+
return toBytesView(await webcrypto.subtle.digest(algorithm, value));
|
|
8
|
+
}
|
|
6
9
|
// ============================================
|
|
7
10
|
// Hash functions
|
|
8
11
|
// ============================================
|
|
9
12
|
export async function sha256(value) {
|
|
10
|
-
return
|
|
13
|
+
return digestBytes('SHA-256', value);
|
|
11
14
|
}
|
|
12
15
|
export async function sha1(value) {
|
|
13
|
-
return
|
|
16
|
+
return digestBytes('SHA-1', value);
|
|
14
17
|
}
|
|
15
18
|
export async function sha512(value) {
|
|
16
|
-
return
|
|
19
|
+
return digestBytes('SHA-512', value);
|
|
17
20
|
}
|
|
18
21
|
export function md5Bytes(input) {
|
|
19
22
|
return toBytesView(createHash('md5').update(input).digest());
|
|
@@ -25,12 +28,10 @@ export async function importAesGcmKey(raw, usages) {
|
|
|
25
28
|
return webcrypto.subtle.importKey('raw', raw, 'AES-GCM', false, usages);
|
|
26
29
|
}
|
|
27
30
|
export async function aesGcmEncrypt(key, nonce, plaintext, aad = EMPTY_BYTES) {
|
|
28
|
-
|
|
29
|
-
return toBytesView(result);
|
|
31
|
+
return toBytesView(await webcrypto.subtle.encrypt({ name: 'AES-GCM', iv: nonce, additionalData: aad }, key, plaintext));
|
|
30
32
|
}
|
|
31
33
|
export async function aesGcmDecrypt(key, nonce, ciphertext, aad = EMPTY_BYTES) {
|
|
32
|
-
|
|
33
|
-
return toBytesView(result);
|
|
34
|
+
return toBytesView(await webcrypto.subtle.decrypt({ name: 'AES-GCM', iv: nonce, additionalData: aad }, key, ciphertext));
|
|
34
35
|
}
|
|
35
36
|
// ============================================
|
|
36
37
|
// AES-CBC (for Signal protocol)
|
|
@@ -42,12 +43,10 @@ export async function importAesCbcKey(keyBytes) {
|
|
|
42
43
|
]);
|
|
43
44
|
}
|
|
44
45
|
export async function aesCbcEncrypt(key, iv, plaintext) {
|
|
45
|
-
|
|
46
|
-
return toBytesView(result);
|
|
46
|
+
return toBytesView(await webcrypto.subtle.encrypt({ name: 'AES-CBC', iv }, key, plaintext));
|
|
47
47
|
}
|
|
48
48
|
export async function aesCbcDecrypt(key, iv, ciphertext) {
|
|
49
|
-
|
|
50
|
-
return toBytesView(result);
|
|
49
|
+
return toBytesView(await webcrypto.subtle.decrypt({ name: 'AES-CBC', iv }, key, ciphertext));
|
|
51
50
|
}
|
|
52
51
|
// ============================================
|
|
53
52
|
// HMAC-SHA256 (for Signal protocol)
|
|
@@ -86,17 +85,8 @@ export async function pbkdf2DeriveAesCtrKey(password, salt, iterations) {
|
|
|
86
85
|
// AES-CTR (for pairing code crypto)
|
|
87
86
|
// ============================================
|
|
88
87
|
export async function aesCtrEncrypt(key, counter, plaintext) {
|
|
89
|
-
|
|
90
|
-
return toBytesView(result);
|
|
88
|
+
return toBytesView(await webcrypto.subtle.encrypt({ name: 'AES-CTR', counter, length: 64 }, key, plaintext));
|
|
91
89
|
}
|
|
92
90
|
export async function aesCtrDecrypt(key, counter, ciphertext) {
|
|
93
|
-
|
|
94
|
-
return toBytesView(result);
|
|
95
|
-
}
|
|
96
|
-
// ============================================
|
|
97
|
-
// Ed25519 raw verify (for Signal variant sigs)
|
|
98
|
-
// ============================================
|
|
99
|
-
export async function ed25519VerifyRaw(publicKey, signature, message) {
|
|
100
|
-
const cryptoKey = await webcrypto.subtle.importKey('raw', publicKey, { name: 'Ed25519' }, false, ['verify']);
|
|
101
|
-
return webcrypto.subtle.verify('Ed25519', cryptoKey, signature, message);
|
|
91
|
+
return toBytesView(await webcrypto.subtle.decrypt({ name: 'AES-CTR', counter, length: 64 }, key, ciphertext));
|
|
102
92
|
}
|
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
import { randomBytes, randomInt } from 'node:crypto';
|
|
1
|
+
import { randomBytes, randomFill, randomInt } from 'node:crypto';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
2
3
|
import { toBytesView } from '../../util/bytes.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
randomBytes(size, (error, buffer) => {
|
|
9
|
-
if (error)
|
|
10
|
-
reject(error);
|
|
11
|
-
else
|
|
12
|
-
resolve(toBytesView(buffer));
|
|
13
|
-
});
|
|
14
|
-
});
|
|
4
|
+
const randomBytesAsyncImpl = promisify(randomBytes);
|
|
5
|
+
const randomIntAsyncImpl = promisify(randomInt);
|
|
6
|
+
export async function randomBytesAsync(size) {
|
|
7
|
+
return toBytesView(await randomBytesAsyncImpl(size));
|
|
15
8
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
randomInt(min, max, (error, value) => {
|
|
22
|
-
if (error)
|
|
9
|
+
export async function randomFillAsync(target, offset, size) {
|
|
10
|
+
await new Promise((resolve, reject) => {
|
|
11
|
+
const onDone = (error) => {
|
|
12
|
+
if (error) {
|
|
23
13
|
reject(error);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
resolve();
|
|
17
|
+
};
|
|
18
|
+
if (offset === undefined) {
|
|
19
|
+
randomFill(target, onDone);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (size === undefined) {
|
|
23
|
+
randomFill(target, offset, onDone);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
randomFill(target, offset, size, onDone);
|
|
27
27
|
});
|
|
28
|
+
return target;
|
|
28
29
|
}
|
|
30
|
+
export const randomIntAsync = randomIntAsyncImpl;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { webcrypto } from 'node:crypto';
|
|
2
|
-
import { assert32, decodeBase64Url } from '../core/encoding.js';
|
|
3
2
|
import { ED25519_PKCS8_PREFIX } from '../curves/constants.js';
|
|
4
3
|
import { pkcs8FromRawPrivate } from '../curves/types.js';
|
|
5
|
-
import { toBytesView } from '../../util/bytes.js';
|
|
4
|
+
import { assertByteLength, decodeBase64Url, toBytesView } from '../../util/bytes.js';
|
|
6
5
|
export class Ed25519 {
|
|
7
6
|
static async generateKeyPair() {
|
|
8
7
|
const keys = (await webcrypto.subtle.generateKey({ name: 'Ed25519' }, true, [
|
|
@@ -16,7 +15,7 @@ export class Ed25519 {
|
|
|
16
15
|
};
|
|
17
16
|
}
|
|
18
17
|
static async keyPairFromPrivateKey(privKey) {
|
|
19
|
-
|
|
18
|
+
assertByteLength(privKey, 32, 'ed25519 private key must be 32 bytes');
|
|
20
19
|
const privateKey = await webcrypto.subtle.importKey('pkcs8', pkcs8FromRawPrivate(ED25519_PKCS8_PREFIX, privKey), { name: 'Ed25519' }, true, ['sign']);
|
|
21
20
|
const privateJwk = await webcrypto.subtle.exportKey('jwk', privateKey);
|
|
22
21
|
return {
|
|
@@ -25,13 +24,13 @@ export class Ed25519 {
|
|
|
25
24
|
};
|
|
26
25
|
}
|
|
27
26
|
static async sign(message, privKey) {
|
|
28
|
-
|
|
27
|
+
assertByteLength(privKey, 32, 'ed25519 private key must be 32 bytes');
|
|
29
28
|
const privateKey = await webcrypto.subtle.importKey('pkcs8', pkcs8FromRawPrivate(ED25519_PKCS8_PREFIX, privKey), { name: 'Ed25519' }, false, ['sign']);
|
|
30
29
|
const signature = await webcrypto.subtle.sign('Ed25519', privateKey, message);
|
|
31
30
|
return toBytesView(signature);
|
|
32
31
|
}
|
|
33
32
|
static async verify(message, signature, pubKey) {
|
|
34
|
-
|
|
33
|
+
assertByteLength(pubKey, 32, 'ed25519 public key must be 32 bytes');
|
|
35
34
|
const publicKey = await webcrypto.subtle.importKey('raw', pubKey, { name: 'Ed25519' }, false, ['verify']);
|
|
36
35
|
return webcrypto.subtle.verify('Ed25519', publicKey, signature, message);
|
|
37
36
|
}
|
|
@@ -1,29 +1,43 @@
|
|
|
1
1
|
import { webcrypto } from 'node:crypto';
|
|
2
|
-
import { assert32, decodeBase64Url } from '../core/encoding.js';
|
|
3
2
|
import { X25519_PKCS8_PREFIX } from '../curves/constants.js';
|
|
4
3
|
import { pkcs8FromRawPrivate } from '../curves/types.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { toBytesView } from '../../util/bytes.js';
|
|
4
|
+
import { FE_ONE } from '../math/constants.js';
|
|
5
|
+
import { fe, feAdd, feFromBytes, feInv, feMul, fePack, feSub } from '../math/fe.js';
|
|
6
|
+
import { assertByteLength, decodeBase64Url, toBytesView } from '../../util/bytes.js';
|
|
7
|
+
// Pre-allocated temps for montgomeryToEdwardsPublic (safe: single-threaded)
|
|
8
|
+
const _mx = fe();
|
|
9
|
+
const _m1 = fe();
|
|
10
|
+
const _m2 = fe();
|
|
11
|
+
const _m3 = fe();
|
|
12
|
+
// p-1 = 2^255-20 in LE bytes: 0xEC, 0xFF×30, 0x7F
|
|
13
|
+
// Mask bit 255 before comparing (non-canonical inputs may have it set)
|
|
14
|
+
function isFieldPMinus1(b) {
|
|
15
|
+
if (b[0] !== 0xec || (b[31] & 0x7f) !== 0x7f)
|
|
16
|
+
return false;
|
|
17
|
+
for (let i = 1; i < 31; i++)
|
|
18
|
+
if (b[i] !== 0xff)
|
|
19
|
+
return false;
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
8
22
|
export function clampCurvePrivateKeyInPlace(privateKey) {
|
|
9
|
-
|
|
10
|
-
throw new Error(`invalid curve25519 private key length ${privateKey.length}`);
|
|
11
|
-
}
|
|
23
|
+
assertByteLength(privateKey, 32, `invalid curve25519 private key length ${privateKey.length}`);
|
|
12
24
|
privateKey[0] &= 248;
|
|
13
25
|
privateKey[31] &= 127;
|
|
14
26
|
privateKey[31] |= 64;
|
|
15
27
|
return privateKey;
|
|
16
28
|
}
|
|
17
29
|
export function montgomeryToEdwardsPublic(curvePublicKey, signBit) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
const x = bytesToBigIntLE(curvePublicKey);
|
|
22
|
-
if (x === FIELD_P - 1n) {
|
|
30
|
+
assertByteLength(curvePublicKey, 32, `invalid curve25519 public key length ${curvePublicKey.length}`);
|
|
31
|
+
if (isFieldPMinus1(curvePublicKey)) {
|
|
23
32
|
throw new Error('invalid curve25519 low-order public key');
|
|
24
33
|
}
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
feFromBytes(_mx, curvePublicKey);
|
|
35
|
+
feSub(_m1, _mx, FE_ONE);
|
|
36
|
+
feAdd(_m2, _mx, FE_ONE);
|
|
37
|
+
feInv(_m3, _m2);
|
|
38
|
+
feMul(_m1, _m1, _m3);
|
|
39
|
+
const encoded = new Uint8Array(32);
|
|
40
|
+
fePack(encoded, _m1);
|
|
27
41
|
encoded[31] = (encoded[31] & 0x7f) | (signBit & 0x80);
|
|
28
42
|
return encoded;
|
|
29
43
|
}
|
|
@@ -39,7 +53,7 @@ export class X25519 {
|
|
|
39
53
|
};
|
|
40
54
|
}
|
|
41
55
|
static async keyPairFromPrivateKey(privKey) {
|
|
42
|
-
|
|
56
|
+
assertByteLength(privKey, 32, 'x25519 private key must be 32 bytes');
|
|
43
57
|
const privateKey = await webcrypto.subtle.importKey('pkcs8', pkcs8FromRawPrivate(X25519_PKCS8_PREFIX, privKey), { name: 'X25519' }, true, ['deriveBits']);
|
|
44
58
|
const privateJwk = await webcrypto.subtle.exportKey('jwk', privateKey);
|
|
45
59
|
return {
|
|
@@ -48,10 +62,12 @@ export class X25519 {
|
|
|
48
62
|
};
|
|
49
63
|
}
|
|
50
64
|
static async scalarMult(privKey, pubKey) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const privateKey = await
|
|
54
|
-
|
|
65
|
+
assertByteLength(privKey, 32, 'x25519 private key must be 32 bytes');
|
|
66
|
+
assertByteLength(pubKey, 32, 'x25519 public key must be 32 bytes');
|
|
67
|
+
const [privateKey, publicKey] = await Promise.all([
|
|
68
|
+
webcrypto.subtle.importKey('pkcs8', pkcs8FromRawPrivate(X25519_PKCS8_PREFIX, privKey), { name: 'X25519' }, false, ['deriveBits']),
|
|
69
|
+
webcrypto.subtle.importKey('raw', pubKey, { name: 'X25519' }, false, [])
|
|
70
|
+
]);
|
|
55
71
|
const sharedBits = await webcrypto.subtle.deriveBits({ name: 'X25519', public: publicKey }, privateKey, 256);
|
|
56
72
|
return toBytesView(sharedBits);
|
|
57
73
|
}
|
package/dist/esm/crypto/index.js
CHANGED
|
@@ -1,41 +1,18 @@
|
|
|
1
|
+
import { fe, feFromBigInt } from '../math/fe.js';
|
|
1
2
|
export const FIELD_P = (1n << 255n) - 19n;
|
|
2
3
|
export const GROUP_L = (1n << 252n) + 27742317777372353535851937790883648493n;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
function modPowField(base, exponent) {
|
|
8
|
-
let result = 1n;
|
|
9
|
-
let current = modField(base);
|
|
10
|
-
let power = exponent;
|
|
11
|
-
while (power > 0n) {
|
|
12
|
-
if ((power & 1n) === 1n) {
|
|
13
|
-
result = modField(result * current);
|
|
14
|
-
}
|
|
15
|
-
current = modField(current * current);
|
|
16
|
-
power >>= 1n;
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
function modInvField(value) {
|
|
21
|
-
if (value === 0n) {
|
|
22
|
-
throw new Error('field inversion by zero');
|
|
23
|
-
}
|
|
24
|
-
return modPowField(value, FIELD_P - 2n);
|
|
25
|
-
}
|
|
26
|
-
const BASE_X = 15112221349535400772501151409588531511454012693041857206046113283949847762202n;
|
|
27
|
-
const BASE_Y = 46316835694926478169428394003475163141307993866256225615783033603165251855960n;
|
|
28
|
-
export const EDWARDS_D = modField(-121665n * modInvField(121666n));
|
|
29
|
-
export const TWO_D = modField(2n * EDWARDS_D);
|
|
4
|
+
export const FE_TWO_D = feFromBigInt(16295367250680780974490674513165176452449235426866156013048779062215315747161n);
|
|
5
|
+
export const FE_ZERO = fe();
|
|
6
|
+
export const FE_ONE = feFromBigInt(1n);
|
|
30
7
|
export const BASE_POINT = Object.freeze({
|
|
31
|
-
x:
|
|
32
|
-
y:
|
|
33
|
-
z: 1n,
|
|
34
|
-
t:
|
|
8
|
+
x: feFromBigInt(15112221349535400772501151409588531511454012693041857206046113283949847762202n),
|
|
9
|
+
y: feFromBigInt(46316835694926478169428394003475163141307993866256225615783033603165251855960n),
|
|
10
|
+
z: feFromBigInt(1n),
|
|
11
|
+
t: feFromBigInt(46827403850823179245072216630277197565144205554125654976674165829533817101731n)
|
|
35
12
|
});
|
|
36
13
|
export const IDENTITY_POINT = Object.freeze({
|
|
37
|
-
x: 0n,
|
|
38
|
-
y: 1n,
|
|
39
|
-
z: 1n,
|
|
40
|
-
t: 0n
|
|
14
|
+
x: feFromBigInt(0n),
|
|
15
|
+
y: feFromBigInt(1n),
|
|
16
|
+
z: feFromBigInt(1n),
|
|
17
|
+
t: feFromBigInt(0n)
|
|
41
18
|
});
|
|
@@ -1,60 +1,187 @@
|
|
|
1
|
-
import { BASE_POINT,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { BASE_POINT, FE_TWO_D, IDENTITY_POINT } from '../math/constants.js';
|
|
2
|
+
import { fe, feAdd, feCopy, feInv, feMul, feNeg, fePack, feSub } from '../math/fe.js';
|
|
3
|
+
import { modGroup } from '../math/mod.js';
|
|
4
|
+
// Pre-allocated temporaries for point operations (safe: JS is single-threaded)
|
|
5
|
+
const _a = fe();
|
|
6
|
+
const _b = fe();
|
|
7
|
+
const _c = fe();
|
|
8
|
+
const _d = fe();
|
|
9
|
+
const _e = fe();
|
|
10
|
+
const _f = fe();
|
|
11
|
+
const _g = fe();
|
|
12
|
+
const _h = fe();
|
|
13
|
+
// Pre-allocated output points for hot-path operations
|
|
14
|
+
function mutablePoint() {
|
|
15
|
+
return { x: fe(), y: fe(), z: fe(), t: fe() };
|
|
16
|
+
}
|
|
17
|
+
const _addOut = mutablePoint();
|
|
18
|
+
const _dblOut = mutablePoint();
|
|
19
|
+
const _negOut = mutablePoint();
|
|
20
|
+
// Temporaries for feInv inside encodeExtendedPoint
|
|
21
|
+
const _invZinv = fe();
|
|
22
|
+
const _invX = fe();
|
|
23
|
+
const _invY = fe();
|
|
24
|
+
const _invXBytes = new Uint8Array(32);
|
|
25
|
+
function addPointInto(out, a, b) {
|
|
26
|
+
feSub(_a, a.y, a.x);
|
|
27
|
+
feSub(_b, b.y, b.x);
|
|
28
|
+
feMul(_a, _a, _b); // aTerm
|
|
29
|
+
feAdd(_b, a.y, a.x);
|
|
30
|
+
feAdd(_c, b.y, b.x);
|
|
31
|
+
feMul(_b, _b, _c); // bTerm
|
|
32
|
+
feMul(_c, FE_TWO_D, a.t);
|
|
33
|
+
feMul(_c, _c, b.t); // cTerm
|
|
34
|
+
feAdd(_d, a.z, a.z);
|
|
35
|
+
feMul(_d, _d, b.z); // dTerm
|
|
36
|
+
feSub(_e, _b, _a); // eTerm
|
|
37
|
+
feSub(_f, _d, _c); // fTerm
|
|
38
|
+
feAdd(_g, _d, _c); // gTerm
|
|
39
|
+
feAdd(_h, _b, _a); // hTerm
|
|
40
|
+
feMul(out.x, _e, _f);
|
|
41
|
+
feMul(out.y, _g, _h);
|
|
42
|
+
feMul(out.z, _f, _g);
|
|
43
|
+
feMul(out.t, _e, _h);
|
|
44
|
+
}
|
|
45
|
+
function doublePointInto(out, point) {
|
|
46
|
+
feMul(_a, point.x, point.x); // aTerm = x^2
|
|
47
|
+
feMul(_b, point.y, point.y); // bTerm = y^2
|
|
48
|
+
feMul(_c, point.z, point.z);
|
|
49
|
+
feAdd(_c, _c, _c); // cTerm = 2*z^2
|
|
50
|
+
feNeg(_d, _a); // dTerm = -aTerm (a=-1 for ed25519)
|
|
51
|
+
feAdd(_e, point.x, point.y);
|
|
52
|
+
feMul(_e, _e, _e);
|
|
53
|
+
feAdd(_f, _a, _b);
|
|
54
|
+
feSub(_e, _e, _f); // eTerm = (x+y)^2 - aTerm - bTerm
|
|
55
|
+
feAdd(_g, _d, _b); // gTerm = dTerm + bTerm
|
|
56
|
+
feSub(_f, _g, _c); // fTerm = gTerm - cTerm
|
|
57
|
+
feSub(_h, _d, _b); // hTerm = dTerm - bTerm
|
|
58
|
+
feMul(out.x, _e, _f);
|
|
59
|
+
feMul(out.y, _g, _h);
|
|
60
|
+
feMul(out.z, _f, _g);
|
|
61
|
+
feMul(out.t, _e, _h);
|
|
62
|
+
}
|
|
63
|
+
function negatePointInto(out, p) {
|
|
64
|
+
feNeg(out.x, p.x);
|
|
65
|
+
feCopy(out.y, p.y);
|
|
66
|
+
feCopy(out.z, p.z);
|
|
67
|
+
feNeg(out.t, p.t);
|
|
68
|
+
}
|
|
69
|
+
function clonePoint(p) {
|
|
70
|
+
const x = fe();
|
|
71
|
+
const y = fe();
|
|
72
|
+
const z = fe();
|
|
73
|
+
const t = fe();
|
|
74
|
+
feCopy(x, p.x);
|
|
75
|
+
feCopy(y, p.y);
|
|
76
|
+
feCopy(z, p.z);
|
|
77
|
+
feCopy(t, p.t);
|
|
78
|
+
return { x, y, z, t };
|
|
79
|
+
}
|
|
80
|
+
// Allocating versions for precomputation (runs once at module load)
|
|
4
81
|
function addPoint(a, b) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const cTerm = mod(TWO_D * a.t * b.t);
|
|
12
|
-
const dTerm = mod(2n * a.z * b.z);
|
|
13
|
-
const eTerm = mod(bTerm - aTerm);
|
|
14
|
-
const fTerm = mod(dTerm - cTerm);
|
|
15
|
-
const gTerm = mod(dTerm + cTerm);
|
|
16
|
-
const hTerm = mod(bTerm + aTerm);
|
|
17
|
-
return {
|
|
18
|
-
x: mod(eTerm * fTerm),
|
|
19
|
-
y: mod(gTerm * hTerm),
|
|
20
|
-
z: mod(fTerm * gTerm),
|
|
21
|
-
t: mod(eTerm * hTerm)
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function doublePoint(point) {
|
|
25
|
-
const aTerm = mod(point.x * point.x);
|
|
26
|
-
const bTerm = mod(point.y * point.y);
|
|
27
|
-
const cTerm = mod(2n * point.z * point.z);
|
|
28
|
-
const dTerm = mod(-aTerm);
|
|
29
|
-
const eTerm = mod(mod((point.x + point.y) * (point.x + point.y)) - aTerm - bTerm);
|
|
30
|
-
const gTerm = mod(dTerm + bTerm);
|
|
31
|
-
const fTerm = mod(gTerm - cTerm);
|
|
32
|
-
const hTerm = mod(dTerm - bTerm);
|
|
33
|
-
return {
|
|
34
|
-
x: mod(eTerm * fTerm),
|
|
35
|
-
y: mod(gTerm * hTerm),
|
|
36
|
-
z: mod(fTerm * gTerm),
|
|
37
|
-
t: mod(eTerm * hTerm)
|
|
38
|
-
};
|
|
82
|
+
addPointInto(_addOut, a, b);
|
|
83
|
+
return clonePoint(_addOut);
|
|
84
|
+
}
|
|
85
|
+
function doublePoint(a) {
|
|
86
|
+
doublePointInto(_dblOut, a);
|
|
87
|
+
return clonePoint(_dblOut);
|
|
39
88
|
}
|
|
89
|
+
const W = 5;
|
|
90
|
+
const halfW = 1 << W;
|
|
91
|
+
const mask = halfW - 1;
|
|
92
|
+
const precomp = new Array(1 << (W - 1));
|
|
93
|
+
precomp[0] = BASE_POINT;
|
|
94
|
+
const _dbl = doublePoint(BASE_POINT);
|
|
95
|
+
for (let i = 1; i < precomp.length; i++) {
|
|
96
|
+
precomp[i] = addPoint(precomp[i - 1], _dbl);
|
|
97
|
+
}
|
|
98
|
+
// Pre-allocated scratch buffers for scalarMultBase (safe: JS is single-threaded)
|
|
99
|
+
const _naf = new Int8Array(256);
|
|
100
|
+
const _loopResult = mutablePoint();
|
|
101
|
+
const _loopDbl = mutablePoint();
|
|
102
|
+
const _loopAdd = mutablePoint();
|
|
40
103
|
export function scalarMultBase(scalar) {
|
|
41
104
|
let k = modGroup(scalar);
|
|
42
|
-
|
|
43
|
-
|
|
105
|
+
if (k === 0n)
|
|
106
|
+
return clonePoint(IDENTITY_POINT);
|
|
107
|
+
const naf = _naf;
|
|
108
|
+
naf.fill(0);
|
|
109
|
+
let nafLen = 0;
|
|
44
110
|
while (k > 0n) {
|
|
45
111
|
if ((k & 1n) === 1n) {
|
|
46
|
-
|
|
112
|
+
let digit = Number(k & BigInt(mask));
|
|
113
|
+
if (digit >= halfW >> 1)
|
|
114
|
+
digit -= halfW;
|
|
115
|
+
naf[nafLen++] = digit;
|
|
116
|
+
k -= BigInt(digit);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
nafLen++;
|
|
47
120
|
}
|
|
48
|
-
addend = doublePoint(addend);
|
|
49
121
|
k >>= 1n;
|
|
50
122
|
}
|
|
51
|
-
|
|
123
|
+
// Copy identity into loop result
|
|
124
|
+
feCopy(_loopResult.x, IDENTITY_POINT.x);
|
|
125
|
+
feCopy(_loopResult.y, IDENTITY_POINT.y);
|
|
126
|
+
feCopy(_loopResult.z, IDENTITY_POINT.z);
|
|
127
|
+
feCopy(_loopResult.t, IDENTITY_POINT.t);
|
|
128
|
+
for (let i = nafLen - 1; i >= 0; i--) {
|
|
129
|
+
doublePointInto(_loopDbl, _loopResult);
|
|
130
|
+
// swap dbl → result
|
|
131
|
+
const tmpX = _loopResult.x;
|
|
132
|
+
_loopResult.x = _loopDbl.x;
|
|
133
|
+
_loopDbl.x = tmpX;
|
|
134
|
+
const tmpY = _loopResult.y;
|
|
135
|
+
_loopResult.y = _loopDbl.y;
|
|
136
|
+
_loopDbl.y = tmpY;
|
|
137
|
+
const tmpZ = _loopResult.z;
|
|
138
|
+
_loopResult.z = _loopDbl.z;
|
|
139
|
+
_loopDbl.z = tmpZ;
|
|
140
|
+
const tmpT = _loopResult.t;
|
|
141
|
+
_loopResult.t = _loopDbl.t;
|
|
142
|
+
_loopDbl.t = tmpT;
|
|
143
|
+
const digit = naf[i];
|
|
144
|
+
if (digit > 0) {
|
|
145
|
+
addPointInto(_loopAdd, _loopResult, precomp[(digit - 1) >> 1]);
|
|
146
|
+
const ax = _loopResult.x;
|
|
147
|
+
_loopResult.x = _loopAdd.x;
|
|
148
|
+
_loopAdd.x = ax;
|
|
149
|
+
const ay = _loopResult.y;
|
|
150
|
+
_loopResult.y = _loopAdd.y;
|
|
151
|
+
_loopAdd.y = ay;
|
|
152
|
+
const az = _loopResult.z;
|
|
153
|
+
_loopResult.z = _loopAdd.z;
|
|
154
|
+
_loopAdd.z = az;
|
|
155
|
+
const at = _loopResult.t;
|
|
156
|
+
_loopResult.t = _loopAdd.t;
|
|
157
|
+
_loopAdd.t = at;
|
|
158
|
+
}
|
|
159
|
+
else if (digit < 0) {
|
|
160
|
+
negatePointInto(_negOut, precomp[(-digit - 1) >> 1]);
|
|
161
|
+
addPointInto(_loopAdd, _loopResult, _negOut);
|
|
162
|
+
const ax = _loopResult.x;
|
|
163
|
+
_loopResult.x = _loopAdd.x;
|
|
164
|
+
_loopAdd.x = ax;
|
|
165
|
+
const ay = _loopResult.y;
|
|
166
|
+
_loopResult.y = _loopAdd.y;
|
|
167
|
+
_loopAdd.y = ay;
|
|
168
|
+
const az = _loopResult.z;
|
|
169
|
+
_loopResult.z = _loopAdd.z;
|
|
170
|
+
_loopAdd.z = az;
|
|
171
|
+
const at = _loopResult.t;
|
|
172
|
+
_loopResult.t = _loopAdd.t;
|
|
173
|
+
_loopAdd.t = at;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return clonePoint(_loopResult);
|
|
52
177
|
}
|
|
53
178
|
export function encodeExtendedPoint(point) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const encoded =
|
|
58
|
-
|
|
179
|
+
feInv(_invZinv, point.z);
|
|
180
|
+
feMul(_invX, point.x, _invZinv);
|
|
181
|
+
feMul(_invY, point.y, _invZinv);
|
|
182
|
+
const encoded = new Uint8Array(32);
|
|
183
|
+
fePack(encoded, _invY);
|
|
184
|
+
fePack(_invXBytes, _invX);
|
|
185
|
+
encoded[31] = (encoded[31] & 0x7f) | ((_invXBytes[0] & 1) << 7);
|
|
59
186
|
return encoded;
|
|
60
187
|
}
|