zapo-js 0.1.0 → 0.1.2
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 +12 -7
- package/dist/appstate/WaAppStateCrypto.js +18 -25
- package/dist/appstate/WaAppStateSyncClient.js +181 -114
- package/dist/appstate/WaAppStateSyncResponseParser.js +16 -5
- package/dist/appstate/constants.js +4 -3
- package/dist/appstate/utils.js +10 -30
- package/dist/auth/WaAuthClient.js +48 -55
- package/dist/auth/flow/WaAuthCredentialsFlow.js +21 -14
- package/dist/auth/index.js +1 -3
- package/dist/auth/pairing/WaPairingFlow.js +21 -23
- package/dist/auth/pairing/WaQrFlow.js +37 -24
- package/dist/client/WaClient.js +103 -276
- package/dist/client/WaClientFactory.js +227 -110
- package/dist/client/connection/WaConnectionManager.js +292 -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/WaGroupCoordinator.js +27 -17
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +20 -27
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +231 -686
- package/dist/client/coordinators/WaRetryCoordinator.js +70 -37
- package/dist/client/dirty.js +35 -29
- package/dist/client/events/chat.js +4 -3
- package/dist/client/events/group.js +59 -36
- package/dist/client/history-sync.js +53 -63
- package/dist/client/incoming.js +23 -20
- package/dist/client/mailbox.js +8 -8
- package/dist/client/messages.js +4 -4
- package/dist/client/messaging/fanout.js +189 -0
- package/dist/client/messaging/key-protocol.js +130 -0
- package/dist/client/messaging/participants.js +191 -0
- package/dist/crypto/core/hkdf.js +3 -8
- package/dist/crypto/core/index.js +1 -4
- package/dist/crypto/core/keys.js +2 -3
- package/dist/crypto/core/primitives.js +12 -15
- package/dist/crypto/core/random.js +7 -26
- package/dist/crypto/curves/Ed25519.js +7 -8
- package/dist/crypto/curves/X25519.js +13 -16
- package/dist/crypto/index.js +0 -5
- package/dist/esm/appstate/WaAppStateCrypto.js +6 -13
- package/dist/esm/appstate/WaAppStateSyncClient.js +174 -107
- package/dist/esm/appstate/WaAppStateSyncResponseParser.js +17 -6
- package/dist/esm/appstate/constants.js +3 -2
- package/dist/esm/appstate/utils.js +8 -27
- package/dist/esm/auth/WaAuthClient.js +48 -55
- package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +21 -14
- package/dist/esm/auth/index.js +0 -1
- package/dist/esm/auth/pairing/WaPairingFlow.js +14 -16
- package/dist/esm/auth/pairing/WaQrFlow.js +37 -24
- package/dist/esm/client/WaClient.js +103 -276
- package/dist/esm/client/WaClientFactory.js +227 -110
- package/dist/esm/client/connection/WaConnectionManager.js +288 -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/WaGroupCoordinator.js +20 -10
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +20 -27
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +232 -687
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +71 -38
- package/dist/esm/client/dirty.js +30 -24
- package/dist/esm/client/events/chat.js +4 -3
- package/dist/esm/client/events/group.js +50 -28
- package/dist/esm/client/history-sync.js +50 -60
- package/dist/esm/client/incoming.js +23 -20
- package/dist/esm/client/mailbox.js +8 -8
- package/dist/esm/client/messages.js +1 -1
- package/dist/esm/client/messaging/fanout.js +186 -0
- package/dist/esm/client/messaging/key-protocol.js +127 -0
- package/dist/esm/client/messaging/participants.js +188 -0
- package/dist/esm/crypto/core/hkdf.js +3 -8
- package/dist/esm/crypto/core/index.js +0 -1
- package/dist/esm/crypto/core/keys.js +2 -3
- package/dist/esm/crypto/core/primitives.js +12 -15
- package/dist/esm/crypto/core/random.js +6 -25
- package/dist/esm/crypto/curves/Ed25519.js +4 -5
- package/dist/esm/crypto/curves/X25519.js +10 -13
- package/dist/esm/crypto/index.js +0 -2
- 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/BoundedTaskQueue.js +13 -17
- package/dist/esm/media/WaMediaCrypto.js +2 -4
- package/dist/esm/media/WaMediaTransferClient.js +226 -58
- package/dist/esm/media/conn.js +10 -6
- package/dist/esm/media/constants.js +4 -1
- package/dist/esm/message/WaMessageClient.js +4 -13
- package/dist/esm/message/ack.js +6 -6
- package/dist/esm/message/addon-crypto.js +59 -0
- package/dist/esm/message/incoming.js +106 -111
- package/dist/esm/message/index.js +2 -0
- package/dist/esm/message/reporting-token.js +438 -0
- package/dist/esm/message/use-case-secret.js +49 -0
- package/dist/esm/protocol/appstate.js +58 -0
- package/dist/esm/protocol/constants.js +2 -1
- package/dist/esm/protocol/index.js +2 -10
- package/dist/esm/protocol/jid.js +63 -51
- package/dist/esm/protocol/media.js +3 -3
- package/dist/esm/protocol/nodes.js +2 -0
- package/dist/esm/protocol/usync.js +11 -0
- package/dist/esm/retry/index.js +1 -0
- package/dist/esm/retry/outbound.js +4 -5
- package/dist/esm/retry/parse.js +58 -76
- package/dist/esm/retry/replay.js +48 -49
- package/dist/esm/retry/tracker.js +56 -0
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +249 -82
- package/dist/esm/signal/api/SignalDigestSyncApi.js +6 -1
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +49 -34
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +70 -62
- package/dist/esm/signal/api/SignalSessionSyncApi.js +23 -30
- package/dist/esm/signal/crypto/WaAdvSignature.js +3 -5
- package/dist/esm/signal/group/SenderKeyChain.js +28 -23
- package/dist/esm/signal/group/SenderKeyCodec.js +2 -4
- package/dist/esm/signal/group/SenderKeyManager.js +26 -16
- package/dist/esm/signal/index.js +1 -0
- package/dist/esm/signal/session/SignalProtocol.js +49 -14
- 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 +186 -0
- package/dist/esm/signal/store/sqlite.js +16 -37
- package/dist/esm/store/createStore.js +16 -18
- package/dist/esm/store/noop.store.js +3 -6
- package/dist/esm/store/providers/memory/appstate.store.js +30 -6
- package/dist/esm/store/providers/memory/contact.store.js +5 -0
- package/dist/esm/store/providers/memory/device-list.store.js +3 -30
- 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/sender-key.store.js +5 -7
- package/dist/esm/store/providers/memory/signal.store.js +13 -1
- package/dist/esm/store/providers/memory/thread.store.js +5 -0
- package/dist/esm/store/providers/sqlite/appstate.store.js +82 -1
- package/dist/esm/store/providers/sqlite/connection.js +18 -13
- package/dist/esm/store/providers/sqlite/contact.store.js +31 -18
- package/dist/esm/store/providers/sqlite/device-list.store.js +7 -35
- package/dist/esm/store/providers/sqlite/message.store.js +45 -32
- package/dist/esm/store/providers/sqlite/migrations.js +1 -1
- package/dist/esm/store/providers/sqlite/participants.store.js +1 -9
- package/dist/esm/store/providers/sqlite/retry.store.js +8 -11
- package/dist/esm/store/providers/sqlite/sender-key.store.js +25 -30
- package/dist/esm/store/providers/sqlite/signal.store.js +104 -22
- package/dist/esm/store/providers/sqlite/table-names.js +107 -0
- package/dist/esm/store/providers/sqlite/thread.store.js +35 -22
- package/dist/esm/transport/WaComms.js +25 -23
- package/dist/esm/transport/WaWebSocket.js +115 -12
- package/dist/esm/transport/binary/decoder.js +4 -4
- package/dist/esm/transport/binary/encoder.js +12 -4
- package/dist/esm/transport/index.js +1 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +2 -8
- package/dist/esm/transport/node/WaNodeOrchestrator.js +2 -4
- 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/index.js +2 -1
- package/dist/esm/transport/node/builders/message.js +9 -0
- package/dist/esm/transport/node/builders/pairing.js +4 -5
- package/dist/esm/transport/node/builders/usync.js +41 -0
- package/dist/esm/transport/node/helpers.js +107 -5
- package/dist/esm/transport/node/usync.js +35 -0
- package/dist/esm/transport/noise/WaFrameCodec.js +48 -33
- package/dist/esm/transport/noise/WaNoiseCert.js +3 -6
- package/dist/esm/transport/noise/WaNoiseSession.js +17 -10
- package/dist/esm/transport/proxy.js +27 -0
- package/dist/esm/transport/stream/parse.js +13 -48
- package/dist/esm/util/bytes.js +50 -32
- package/dist/esm/util/coercion.js +6 -14
- package/dist/esm/util/primitives.js +39 -14
- 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/BoundedTaskQueue.js +13 -17
- package/dist/media/WaMediaCrypto.js +1 -3
- package/dist/media/WaMediaTransferClient.js +259 -58
- package/dist/media/conn.js +10 -6
- package/dist/media/constants.js +4 -1
- package/dist/message/WaMessageClient.js +5 -14
- package/dist/message/ack.js +6 -6
- package/dist/message/addon-crypto.js +65 -0
- package/dist/message/incoming.js +104 -109
- package/dist/message/index.js +2 -0
- package/dist/message/reporting-token.js +443 -0
- package/dist/message/use-case-secret.js +55 -0
- package/dist/protocol/appstate.js +59 -1
- package/dist/protocol/constants.js +7 -1
- package/dist/protocol/index.js +20 -42
- package/dist/protocol/jid.js +64 -51
- package/dist/protocol/media.js +3 -3
- package/dist/protocol/nodes.js +2 -0
- package/dist/protocol/usync.js +14 -0
- package/dist/retry/index.js +3 -1
- package/dist/retry/outbound.js +6 -7
- package/dist/retry/parse.js +57 -75
- package/dist/retry/replay.js +46 -47
- package/dist/retry/tracker.js +59 -0
- package/dist/signal/api/SignalDeviceSyncApi.js +247 -80
- package/dist/signal/api/SignalDigestSyncApi.js +6 -1
- package/dist/signal/api/SignalIdentitySyncApi.js +49 -34
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +67 -59
- package/dist/signal/api/SignalSessionSyncApi.js +23 -30
- package/dist/signal/crypto/WaAdvSignature.js +2 -4
- package/dist/signal/group/SenderKeyChain.js +27 -22
- package/dist/signal/group/SenderKeyCodec.js +1 -3
- package/dist/signal/group/SenderKeyManager.js +26 -16
- package/dist/signal/index.js +3 -1
- package/dist/signal/session/SignalProtocol.js +49 -14
- package/dist/signal/session/SignalRatchet.js +24 -15
- package/dist/signal/session/SignalSession.js +14 -9
- package/dist/signal/session/resolver.js +189 -0
- package/dist/signal/store/sqlite.js +16 -37
- package/dist/store/createStore.js +16 -18
- package/dist/store/noop.store.js +3 -6
- package/dist/store/providers/memory/appstate.store.js +28 -4
- package/dist/store/providers/memory/contact.store.js +5 -0
- package/dist/store/providers/memory/device-list.store.js +3 -30
- 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/sender-key.store.js +8 -10
- package/dist/store/providers/memory/signal.store.js +21 -9
- package/dist/store/providers/memory/thread.store.js +5 -0
- package/dist/store/providers/sqlite/appstate.store.js +81 -0
- package/dist/store/providers/sqlite/connection.js +18 -13
- package/dist/store/providers/sqlite/contact.store.js +31 -18
- package/dist/store/providers/sqlite/device-list.store.js +7 -35
- package/dist/store/providers/sqlite/message.store.js +45 -32
- package/dist/store/providers/sqlite/migrations.js +1 -1
- package/dist/store/providers/sqlite/participants.store.js +1 -9
- package/dist/store/providers/sqlite/retry.store.js +8 -11
- package/dist/store/providers/sqlite/sender-key.store.js +24 -29
- package/dist/store/providers/sqlite/signal.store.js +105 -23
- package/dist/store/providers/sqlite/table-names.js +113 -0
- package/dist/store/providers/sqlite/thread.store.js +35 -22
- package/dist/transport/WaComms.js +27 -25
- package/dist/transport/WaWebSocket.js +148 -12
- package/dist/transport/binary/decoder.js +4 -4
- package/dist/transport/binary/encoder.js +12 -4
- package/dist/transport/index.js +7 -1
- package/dist/transport/keepalive/WaKeepAlive.js +1 -7
- package/dist/transport/node/WaNodeOrchestrator.js +2 -4
- 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/index.js +12 -9
- package/dist/transport/node/builders/message.js +9 -0
- package/dist/transport/node/builders/pairing.js +4 -5
- package/dist/transport/node/builders/usync.js +45 -0
- package/dist/transport/node/helpers.js +112 -4
- package/dist/transport/node/usync.js +38 -0
- package/dist/transport/noise/WaFrameCodec.js +47 -32
- package/dist/transport/noise/WaNoiseCert.js +5 -8
- package/dist/transport/noise/WaNoiseSession.js +17 -10
- package/dist/transport/proxy.js +34 -0
- package/dist/transport/stream/parse.js +17 -53
- 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/store/sqlite.d.ts +4 -18
- package/dist/types/appstate/utils.d.ts +0 -1
- package/dist/types/auth/WaAuthClient.d.ts +10 -12
- package/dist/types/auth/index.d.ts +0 -2
- package/dist/types/auth/pairing/WaQrFlow.d.ts +1 -1
- package/dist/types/auth/types.d.ts +6 -9
- package/dist/types/client/WaClient.d.ts +27 -25
- package/dist/types/client/WaClientFactory.d.ts +22 -23
- package/dist/types/client/connection/WaConnectionManager.d.ts +64 -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/WaIncomingNodeCoordinator.d.ts +0 -1
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +18 -41
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +2 -0
- package/dist/types/client/dirty.d.ts +1 -0
- package/dist/types/client/events/group.d.ts +2 -1
- package/dist/types/client/index.d.ts +1 -1
- 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/types.d.ts +24 -1
- package/dist/types/crypto/core/hkdf.d.ts +0 -6
- package/dist/types/crypto/core/index.d.ts +0 -1
- package/dist/types/crypto/core/random.d.ts +1 -7
- package/dist/types/crypto/index.d.ts +0 -2
- package/dist/types/index.d.ts +1 -1
- 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/BoundedTaskQueue.d.ts +1 -1
- package/dist/types/media/WaMediaTransferClient.d.ts +13 -3
- package/dist/types/media/types.d.ts +5 -0
- package/dist/types/message/addon-crypto.d.ts +25 -0
- package/dist/types/message/index.d.ts +2 -0
- package/dist/types/message/reporting-token.d.ts +19 -0
- package/dist/types/message/use-case-secret.d.ts +20 -0
- package/dist/types/protocol/appstate.d.ts +58 -0
- package/dist/types/protocol/constants.d.ts +2 -1
- package/dist/types/protocol/index.d.ts +2 -10
- package/dist/types/protocol/jid.d.ts +3 -3
- package/dist/types/protocol/nodes.d.ts +2 -0
- package/dist/types/protocol/usync.d.ts +11 -0
- package/dist/types/retry/index.d.ts +1 -0
- package/dist/types/retry/replay.d.ts +0 -4
- package/dist/types/retry/tracker.d.ts +19 -0
- package/dist/types/retry/types.d.ts +4 -3
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +13 -1
- package/dist/types/signal/group/SenderKeyCodec.d.ts +4 -6
- package/dist/types/signal/index.d.ts +1 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +9 -0
- package/dist/types/signal/session/resolver.d.ts +17 -0
- package/dist/types/store/contracts/appstate.store.d.ts +3 -0
- 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/sender-key.store.d.ts +0 -1
- package/dist/types/store/contracts/signal.store.d.ts +6 -0
- package/dist/types/store/contracts/thread.store.d.ts +1 -0
- package/dist/types/store/index.d.ts +1 -1
- package/dist/types/store/providers/memory/appstate.store.d.ts +2 -0
- 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/sender-key.store.d.ts +0 -1
- package/dist/types/store/providers/memory/signal.store.d.ts +6 -0
- package/dist/types/store/providers/memory/thread.store.d.ts +1 -0
- package/dist/types/store/providers/sqlite/appstate.store.d.ts +2 -0
- package/dist/types/store/providers/sqlite/contact.store.d.ts +2 -0
- package/dist/types/store/providers/sqlite/device-list.store.d.ts +0 -3
- package/dist/types/store/providers/sqlite/message.store.d.ts +2 -0
- package/dist/types/store/providers/sqlite/participants.store.d.ts +0 -1
- package/dist/types/store/providers/sqlite/retry.store.d.ts +0 -1
- package/dist/types/store/providers/sqlite/sender-key.store.d.ts +0 -1
- package/dist/types/store/providers/sqlite/signal.store.d.ts +7 -0
- package/dist/types/store/providers/sqlite/table-names.d.ts +5 -0
- package/dist/types/store/providers/sqlite/thread.store.d.ts +2 -0
- package/dist/types/store/types.d.ts +3 -0
- package/dist/types/transport/WaWebSocket.d.ts +3 -0
- package/dist/types/transport/index.d.ts +2 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +0 -1
- package/dist/types/transport/node/WaNodeTransport.d.ts +0 -9
- package/dist/types/transport/node/builders/group.d.ts +4 -6
- package/dist/types/transport/node/builders/index.d.ts +2 -1
- package/dist/types/transport/node/builders/message.d.ts +14 -25
- package/dist/types/transport/node/builders/retry.d.ts +2 -4
- package/dist/types/transport/node/builders/usync.d.ts +21 -0
- package/dist/types/transport/node/helpers.d.ts +8 -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 +1 -0
- 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/primitives.d.ts +3 -0
- package/dist/util/bytes.js +55 -33
- package/dist/util/coercion.js +6 -14
- package/dist/util/primitives.js +42 -14
- package/package.json +27 -9
- package/proto/index.d.ts +1090 -1048
- package/proto/index.js +1 -1
- package/scripts/check-node-version.cjs +0 -1
- package/dist/crypto/core/encoding.js +0 -29
- package/dist/esm/crypto/core/encoding.js +0 -25
- package/dist/esm/util/base64.js +0 -18
- package/dist/esm/util/signal-address.js +0 -5
- package/dist/types/crypto/core/encoding.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
package/dist/util/bytes.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EMPTY_BYTES = exports.TEXT_DECODER = exports.TEXT_ENCODER = void 0;
|
|
3
|
+
exports.EMPTY_BYTES = exports.ZERO_BYTES = exports.TEXT_DECODER = exports.TEXT_ENCODER = void 0;
|
|
4
4
|
exports.bytesToHex = bytesToHex;
|
|
5
5
|
exports.hexToBytes = hexToBytes;
|
|
6
6
|
exports.bytesToBase64 = bytesToBase64;
|
|
7
7
|
exports.base64ToBytes = base64ToBytes;
|
|
8
|
+
exports.base64ToBytesChecked = base64ToBytesChecked;
|
|
9
|
+
exports.decodeBase64Url = decodeBase64Url;
|
|
10
|
+
exports.assertByteLength = assertByteLength;
|
|
11
|
+
exports.decodeProtoBytes = decodeProtoBytes;
|
|
8
12
|
exports.bytesToBase64UrlSafe = bytesToBase64UrlSafe;
|
|
9
13
|
exports.concatBytes = concatBytes;
|
|
10
14
|
exports.toBytesView = toBytesView;
|
|
@@ -17,6 +21,7 @@ exports.readAllBytes = readAllBytes;
|
|
|
17
21
|
const node_crypto_1 = require("node:crypto");
|
|
18
22
|
exports.TEXT_ENCODER = new TextEncoder();
|
|
19
23
|
exports.TEXT_DECODER = new TextDecoder();
|
|
24
|
+
exports.ZERO_BYTES = new Uint8Array([0]);
|
|
20
25
|
exports.EMPTY_BYTES = Object.freeze(new Uint8Array(0));
|
|
21
26
|
const HEX_CHARS = '0123456789abcdef';
|
|
22
27
|
const HEX_TABLE = /* @__PURE__ */ (() => {
|
|
@@ -106,28 +111,52 @@ function base64ToBytes(value) {
|
|
|
106
111
|
out[j++] = ((b & 0x0f) << 4) | (c >> 2);
|
|
107
112
|
out[j++] = ((c & 0x03) << 6) | d;
|
|
108
113
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
const a = lookupBase64(value.charCodeAt(i));
|
|
115
|
+
const b = lookupBase64(value.charCodeAt(i + 1));
|
|
116
|
+
out[j++] = (a << 2) | (b >> 4);
|
|
117
|
+
if (j < outLen) {
|
|
112
118
|
const c = lookupBase64(value.charCodeAt(i + 2));
|
|
113
|
-
const d = lookupBase64(value.charCodeAt(i + 3));
|
|
114
|
-
out[j++] = (a << 2) | (b >> 4);
|
|
115
119
|
out[j++] = ((b & 0x0f) << 4) | (c >> 2);
|
|
116
|
-
|
|
120
|
+
if (j < outLen) {
|
|
121
|
+
const d = lookupBase64(value.charCodeAt(i + 3));
|
|
122
|
+
out[j++] = ((c & 0x03) << 6) | d;
|
|
123
|
+
}
|
|
117
124
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
out[j++] = ((b & 0x0f) << 4) | (c >> 2);
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
function base64ToBytesChecked(value, field, requireNonEmpty = true) {
|
|
128
|
+
if (requireNonEmpty && value.length === 0) {
|
|
129
|
+
throw new Error(`invalid base64 payload for ${field}`);
|
|
124
130
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
return base64ToBytes(value);
|
|
132
|
+
}
|
|
133
|
+
function decodeBase64Url(value, field) {
|
|
134
|
+
if (!value) {
|
|
135
|
+
throw new Error(`missing ${field}`);
|
|
136
|
+
}
|
|
137
|
+
const padded = value
|
|
138
|
+
.replace(/-/g, '+')
|
|
139
|
+
.replace(/_/g, '/')
|
|
140
|
+
.padEnd(Math.ceil(value.length / 4) * 4, '=');
|
|
141
|
+
return base64ToBytesChecked(padded, field);
|
|
142
|
+
}
|
|
143
|
+
function assertByteLength(value, expectedLength, errorMessage, throwOnMismatch = true) {
|
|
144
|
+
if (value.length !== expectedLength) {
|
|
145
|
+
if (!throwOnMismatch) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
throw new Error(errorMessage);
|
|
129
149
|
}
|
|
130
|
-
return
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
function decodeProtoBytes(value, field) {
|
|
153
|
+
if (value === null || value === undefined) {
|
|
154
|
+
throw new Error(`missing protobuf bytes field ${field}`);
|
|
155
|
+
}
|
|
156
|
+
if (value instanceof Uint8Array) {
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
return base64ToBytes(value);
|
|
131
160
|
}
|
|
132
161
|
function lookupBase64(code) {
|
|
133
162
|
if (code > 127) {
|
|
@@ -196,28 +225,21 @@ function concatBytes(parts) {
|
|
|
196
225
|
}
|
|
197
226
|
function toBytesView(value) {
|
|
198
227
|
if (value instanceof Uint8Array) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
228
|
+
return value.constructor === Uint8Array
|
|
229
|
+
? value
|
|
230
|
+
: new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
203
231
|
}
|
|
204
|
-
if (ArrayBuffer
|
|
205
|
-
return new Uint8Array(value
|
|
232
|
+
if (value instanceof ArrayBuffer) {
|
|
233
|
+
return new Uint8Array(value);
|
|
206
234
|
}
|
|
207
|
-
return new Uint8Array(value);
|
|
235
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
208
236
|
}
|
|
209
237
|
function toChunkBytes(chunk) {
|
|
210
|
-
if (chunk instanceof Uint8Array) {
|
|
211
|
-
return chunk;
|
|
212
|
-
}
|
|
213
|
-
if (chunk instanceof ArrayBuffer) {
|
|
214
|
-
return new Uint8Array(chunk);
|
|
215
|
-
}
|
|
216
238
|
if (typeof chunk === 'string') {
|
|
217
239
|
return exports.TEXT_ENCODER.encode(chunk);
|
|
218
240
|
}
|
|
219
|
-
if (ArrayBuffer.isView(chunk)) {
|
|
220
|
-
return
|
|
241
|
+
if (chunk instanceof Uint8Array || chunk instanceof ArrayBuffer || ArrayBuffer.isView(chunk)) {
|
|
242
|
+
return toBytesView(chunk);
|
|
221
243
|
}
|
|
222
244
|
throw new Error(`unsupported stream chunk type: ${typeof chunk}`);
|
|
223
245
|
}
|
package/dist/util/coercion.js
CHANGED
|
@@ -20,9 +20,8 @@ function asNumber(value, field) {
|
|
|
20
20
|
throw new Error(`invalid number value for ${field}`);
|
|
21
21
|
}
|
|
22
22
|
function asOptionalNumber(value, field = 'optional number') {
|
|
23
|
-
if (value === null || value === undefined)
|
|
23
|
+
if (value === null || value === undefined)
|
|
24
24
|
return undefined;
|
|
25
|
-
}
|
|
26
25
|
return asNumber(value, field);
|
|
27
26
|
}
|
|
28
27
|
function asString(value, field) {
|
|
@@ -32,9 +31,8 @@ function asString(value, field) {
|
|
|
32
31
|
throw new Error(`invalid string value for ${field}`);
|
|
33
32
|
}
|
|
34
33
|
function asOptionalString(value, field = 'optional string') {
|
|
35
|
-
if (value === null || value === undefined)
|
|
34
|
+
if (value === null || value === undefined)
|
|
36
35
|
return undefined;
|
|
37
|
-
}
|
|
38
36
|
return asString(value, field);
|
|
39
37
|
}
|
|
40
38
|
function asBytes(value, field) {
|
|
@@ -44,23 +42,17 @@ function asBytes(value, field) {
|
|
|
44
42
|
throw new Error(`invalid bytes value for ${field}`);
|
|
45
43
|
}
|
|
46
44
|
function asOptionalBytes(value, field = 'optional bytes') {
|
|
47
|
-
if (value === null || value === undefined)
|
|
45
|
+
if (value === null || value === undefined)
|
|
48
46
|
return undefined;
|
|
49
|
-
}
|
|
50
47
|
return asBytes(value, field);
|
|
51
48
|
}
|
|
52
49
|
function toBoolOrUndef(value) {
|
|
53
|
-
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
return Boolean(value);
|
|
50
|
+
return value === null || value === undefined ? undefined : Boolean(value);
|
|
57
51
|
}
|
|
58
52
|
function resolvePositive(value, fallback, name) {
|
|
59
|
-
if (value === undefined)
|
|
53
|
+
if (value === undefined)
|
|
60
54
|
return fallback;
|
|
61
|
-
|
|
62
|
-
if (Number.isSafeInteger(value) && value > 0) {
|
|
55
|
+
if (Number.isSafeInteger(value) && value > 0)
|
|
63
56
|
return value;
|
|
64
|
-
}
|
|
65
57
|
throw new Error(`${name} must be a positive safe integer`);
|
|
66
58
|
}
|
package/dist/util/primitives.js
CHANGED
|
@@ -3,35 +3,63 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toError = toError;
|
|
4
4
|
exports.toSafeNumber = toSafeNumber;
|
|
5
5
|
exports.longToNumber = longToNumber;
|
|
6
|
+
exports.normalizeNonNegativeInteger = normalizeNonNegativeInteger;
|
|
7
|
+
exports.parseStrictUnsignedInt = parseStrictUnsignedInt;
|
|
8
|
+
exports.parseOptionalInt = parseOptionalInt;
|
|
6
9
|
function toError(value) {
|
|
7
|
-
if (value instanceof Error)
|
|
10
|
+
if (value instanceof Error)
|
|
8
11
|
return value;
|
|
9
|
-
|
|
10
|
-
if (typeof value === 'string') {
|
|
12
|
+
if (typeof value === 'string')
|
|
11
13
|
return new Error(value);
|
|
14
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {
|
|
15
|
+
return new Error(String(value));
|
|
16
|
+
}
|
|
17
|
+
if (value && typeof value === 'object') {
|
|
18
|
+
const message = value.message;
|
|
19
|
+
if (typeof message === 'string' && message.length > 0) {
|
|
20
|
+
return new Error(message);
|
|
21
|
+
}
|
|
22
|
+
const code = value.code;
|
|
23
|
+
if (typeof code === 'string' || typeof code === 'number') {
|
|
24
|
+
return new Error(`unknown error (${code})`);
|
|
25
|
+
}
|
|
12
26
|
}
|
|
13
27
|
return new Error('unknown error');
|
|
14
28
|
}
|
|
15
29
|
function assertSafeInteger(value, field, nullishBehavior) {
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return value;
|
|
30
|
+
if (Number.isFinite(value) && Number.isSafeInteger(value))
|
|
31
|
+
return value;
|
|
32
|
+
const prefix = nullishBehavior === 'throw' ? `invalid ${field}` : 'invalid long numeric value';
|
|
33
|
+
throw new Error(`${prefix}: ${value}`);
|
|
21
34
|
}
|
|
22
35
|
function toSafeNumber(value, field) {
|
|
23
|
-
if (value === null || value === undefined)
|
|
36
|
+
if (value === null || value === undefined)
|
|
24
37
|
throw new Error(`missing ${field}`);
|
|
25
|
-
}
|
|
26
38
|
const numeric = typeof value === 'number' ? value : value.toNumber?.();
|
|
27
|
-
if (typeof numeric !== 'number')
|
|
39
|
+
if (typeof numeric !== 'number')
|
|
28
40
|
throw new Error(`invalid ${field}`);
|
|
29
|
-
}
|
|
30
41
|
return assertSafeInteger(numeric, field, 'throw');
|
|
31
42
|
}
|
|
32
43
|
function longToNumber(value) {
|
|
33
|
-
if (value === null || value === undefined)
|
|
44
|
+
if (value === null || value === undefined)
|
|
34
45
|
return 0;
|
|
35
|
-
}
|
|
36
46
|
return assertSafeInteger(typeof value === 'number' ? value : value.toNumber(), '', 'zero');
|
|
37
47
|
}
|
|
48
|
+
function normalizeNonNegativeInteger(value, fallback) {
|
|
49
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
50
|
+
return fallback;
|
|
51
|
+
return Math.max(0, Math.trunc(value));
|
|
52
|
+
}
|
|
53
|
+
function parseStrictUnsignedInt(value) {
|
|
54
|
+
if (!/^\d+$/.test(value))
|
|
55
|
+
return undefined;
|
|
56
|
+
const parsed = Number(value);
|
|
57
|
+
if (!Number.isSafeInteger(parsed))
|
|
58
|
+
return undefined;
|
|
59
|
+
return parsed;
|
|
60
|
+
}
|
|
61
|
+
function parseOptionalInt(value) {
|
|
62
|
+
if (!value)
|
|
63
|
+
return undefined;
|
|
64
|
+
return parseStrictUnsignedInt(value);
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zapo-js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "High-performance WhatsApp Web TypeScript library",
|
|
5
|
+
"funding": {
|
|
6
|
+
"type": "github",
|
|
7
|
+
"url": "https://github.com/sponsors/vinikjkkj"
|
|
8
|
+
},
|
|
5
9
|
"main": "dist/index.js",
|
|
6
10
|
"module": "dist/esm/index.js",
|
|
7
11
|
"types": "dist/types/index.d.ts",
|
|
@@ -97,6 +101,12 @@
|
|
|
97
101
|
"build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:types && npm run build:esm:finalize",
|
|
98
102
|
"proto:generate": "node ./scripts/generate-proto.cjs",
|
|
99
103
|
"example": "tsx examples/example.ts",
|
|
104
|
+
"bench:media": "node --expose-gc --import tsx bench/media-streaming.bench.ts",
|
|
105
|
+
"bench:binary": "node --expose-gc --import tsx bench/binary-codec.bench.ts",
|
|
106
|
+
"bench:crypto": "node --expose-gc --import tsx bench/crypto-core.bench.ts",
|
|
107
|
+
"bench:store:memory": "node --expose-gc --import tsx bench/store-memory.bench.ts",
|
|
108
|
+
"bench:all": "npm run bench:media && npm run bench:binary && npm run bench:crypto && npm run bench:store:memory",
|
|
109
|
+
"bench:comment": "node ./scripts/build-bench-comment.cjs",
|
|
100
110
|
"test:structure": "node ./scripts/check-tests-structure.cjs",
|
|
101
111
|
"test": "npm run test:structure && node --import tsx --test --test-skip-pattern \"\\\\[flow\\\\]\" \"src/**/__tests__/**/*.test.ts\"",
|
|
102
112
|
"test:watch": "node --import tsx --test --watch --test-skip-pattern \"\\\\[flow\\\\]\" \"src/**/__tests__/**/*.test.ts\"",
|
|
@@ -105,46 +115,54 @@
|
|
|
105
115
|
"test:coverage": "npm run test:structure && c8 --all --include \"src/**/*.ts\" --exclude \"src/**/*.d.ts\" --exclude \"src/**/__tests__/**\" --exclude \"src/**/types.ts\" --exclude \"src/store/contracts/**/*.ts\" --reporter text --reporter html --reporter lcov node --import tsx --test --test-skip-pattern \"\\\\[flow\\\\]\" \"src/**/__tests__/**/*.test.ts\"",
|
|
106
116
|
"test:coverage:open": "node -e \"require('node:child_process').execSync(process.platform === 'win32' ? 'start coverage\\\\index.html' : process.platform === 'darwin' ? 'open coverage/index.html' : 'xdg-open coverage/index.html', { stdio: 'inherit' })\"",
|
|
107
117
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
108
|
-
"lint": "eslint
|
|
109
|
-
"lint:fix": "eslint
|
|
118
|
+
"lint": "eslint . --ext .ts,.js,.cjs",
|
|
119
|
+
"lint:fix": "eslint . --ext .ts,.js,.cjs --fix",
|
|
110
120
|
"format": "prettier . --write",
|
|
111
121
|
"format:check": "prettier . --check"
|
|
112
122
|
},
|
|
113
|
-
"dependencies": {
|
|
114
|
-
"protobufjs": "^7.5.4"
|
|
115
|
-
},
|
|
123
|
+
"dependencies": {},
|
|
116
124
|
"peerDependencies": {
|
|
117
125
|
"better-sqlite3": "^11.9.1",
|
|
126
|
+
"got": "14.6.4",
|
|
118
127
|
"pino": "^9.0.0",
|
|
119
|
-
"pino-pretty": "^13.0.0"
|
|
128
|
+
"pino-pretty": "^13.0.0",
|
|
129
|
+
"ws": "^8.18.3"
|
|
120
130
|
},
|
|
121
131
|
"peerDependenciesMeta": {
|
|
122
132
|
"better-sqlite3": {
|
|
123
133
|
"optional": true
|
|
124
134
|
},
|
|
135
|
+
"got": {
|
|
136
|
+
"optional": true
|
|
137
|
+
},
|
|
125
138
|
"pino": {
|
|
126
139
|
"optional": true
|
|
127
140
|
},
|
|
128
141
|
"pino-pretty": {
|
|
129
142
|
"optional": true
|
|
143
|
+
},
|
|
144
|
+
"ws": {
|
|
145
|
+
"optional": true
|
|
130
146
|
}
|
|
131
147
|
},
|
|
132
148
|
"devDependencies": {
|
|
133
149
|
"@changesets/cli": "^2.30.0",
|
|
134
150
|
"@types/node": "^22.13.14",
|
|
151
|
+
"@types/ws": "^8.18.1",
|
|
135
152
|
"@typescript-eslint/parser": "^8.56.1",
|
|
136
153
|
"@vinikjkkj/eslint-config": "^1.0.0",
|
|
137
154
|
"better-sqlite3": "^12.6.2",
|
|
138
155
|
"c8": "^11.0.0",
|
|
139
156
|
"eslint": "^9.39.4",
|
|
140
157
|
"eslint-plugin-import": "^2.32.0",
|
|
158
|
+
"got": "14.6.4",
|
|
141
159
|
"pino": "^10.3.1",
|
|
142
160
|
"pino-pretty": "^13.1.3",
|
|
143
161
|
"prettier": "^3.8.1",
|
|
144
162
|
"tsc-alias": "^1.8.16",
|
|
145
163
|
"tsx": "^4.20.6",
|
|
146
164
|
"typescript": "^5.7.3",
|
|
147
|
-
"typescript-eslint": "^8.56.1"
|
|
165
|
+
"typescript-eslint": "^8.56.1",
|
|
166
|
+
"ws": "^8.18.3"
|
|
148
167
|
}
|
|
149
168
|
}
|
|
150
|
-
|