zapo-js 0.1.1 → 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 +8 -0
- 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 +26 -5
- 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
|
@@ -12,6 +12,12 @@ function parseSyncResponse(iqNode) {
|
|
|
12
12
|
}
|
|
13
13
|
const syncNode = (0, helpers_1.findNodeChild)(iqNode, constants_1.WA_NODE_TAGS.SYNC);
|
|
14
14
|
if (!syncNode) {
|
|
15
|
+
if (iqNode.attrs.type === constants_1.WA_IQ_TYPES.ERROR) {
|
|
16
|
+
const errorNode = (0, helpers_1.findNodeChild)(iqNode, constants_1.WA_NODE_TAGS.ERROR);
|
|
17
|
+
const code = errorNode?.attrs.code ?? 'unknown';
|
|
18
|
+
const text = errorNode?.attrs.text ?? 'unknown';
|
|
19
|
+
throw new Error(`sync iq failed (${code}: ${text})`);
|
|
20
|
+
}
|
|
15
21
|
throw new Error('sync response is missing <sync> node');
|
|
16
22
|
}
|
|
17
23
|
const payloads = [];
|
|
@@ -30,11 +36,16 @@ function parseSyncResponse(iqNode) {
|
|
|
30
36
|
}
|
|
31
37
|
version = parsedVersion;
|
|
32
38
|
}
|
|
33
|
-
const patchesNode = (0, helpers_1.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
39
|
+
const [patchesNode, snapshotNode] = (0, helpers_1.findNodeChildrenByTags)(collectionNode, [
|
|
40
|
+
constants_1.WA_NODE_TAGS.PATCHES,
|
|
41
|
+
constants_1.WA_NODE_TAGS.SNAPSHOT
|
|
42
|
+
]);
|
|
43
|
+
const patches = [];
|
|
44
|
+
if (patchesNode) {
|
|
45
|
+
for (const patchNode of (0, helpers_1.getNodeChildrenByTag)(patchesNode, constants_1.WA_NODE_TAGS.PATCH)) {
|
|
46
|
+
patches.push(_proto_1.proto.SyncdPatch.decode((0, helpers_1.decodeNodeContentBase64OrBytes)(patchNode.content, 'collection.patches.patch')));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
38
49
|
const snapshotReference = snapshotNode
|
|
39
50
|
? _proto_1.proto.ExternalBlobReference.decode((0, helpers_1.decodeNodeContentBase64OrBytes)(snapshotNode.content, 'collection.snapshot'))
|
|
40
51
|
: undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.APP_STATE_DEFAULT_COLLECTIONS = exports.APP_STATE_EMPTY_LT_HASH = exports.APP_STATE_POINT_SIZE = exports.APP_STATE_LT_HASH_SIZE = exports.APP_STATE_IV_LENGTH = exports.APP_STATE_MAC_OCTET_LENGTH = exports.APP_STATE_VALUE_MAC_LENGTH = exports.APP_STATE_DERIVED_PATCH_MAC_KEY_END = exports.APP_STATE_DERIVED_SNAPSHOT_MAC_KEY_END = exports.APP_STATE_DERIVED_VALUE_MAC_KEY_END = exports.APP_STATE_DERIVED_VALUE_ENCRYPTION_KEY_END = exports.APP_STATE_DERIVED_INDEX_KEY_END = exports.APP_STATE_DERIVED_KEY_LENGTH = void 0;
|
|
3
|
+
exports.APP_STATE_DEFAULT_COLLECTIONS = exports.APP_STATE_DEFAULT_COLLECTION_VERSION = exports.APP_STATE_EMPTY_LT_HASH = exports.APP_STATE_POINT_SIZE = exports.APP_STATE_LT_HASH_SIZE = exports.APP_STATE_IV_LENGTH = exports.APP_STATE_MAC_OCTET_LENGTH = exports.APP_STATE_VALUE_MAC_LENGTH = exports.APP_STATE_DERIVED_PATCH_MAC_KEY_END = exports.APP_STATE_DERIVED_SNAPSHOT_MAC_KEY_END = exports.APP_STATE_DERIVED_VALUE_MAC_KEY_END = exports.APP_STATE_DERIVED_VALUE_ENCRYPTION_KEY_END = exports.APP_STATE_DERIVED_INDEX_KEY_END = exports.APP_STATE_DERIVED_KEY_LENGTH = void 0;
|
|
4
4
|
const constants_1 = require("../protocol/constants");
|
|
5
5
|
exports.APP_STATE_DERIVED_KEY_LENGTH = 160;
|
|
6
6
|
exports.APP_STATE_DERIVED_INDEX_KEY_END = 32;
|
|
@@ -14,10 +14,11 @@ exports.APP_STATE_IV_LENGTH = 16;
|
|
|
14
14
|
exports.APP_STATE_LT_HASH_SIZE = 128;
|
|
15
15
|
exports.APP_STATE_POINT_SIZE = 2;
|
|
16
16
|
exports.APP_STATE_EMPTY_LT_HASH = new Uint8Array(exports.APP_STATE_LT_HASH_SIZE);
|
|
17
|
-
exports.
|
|
17
|
+
exports.APP_STATE_DEFAULT_COLLECTION_VERSION = 0;
|
|
18
|
+
exports.APP_STATE_DEFAULT_COLLECTIONS = Object.freeze([
|
|
18
19
|
constants_1.WA_APP_STATE_COLLECTIONS.CRITICAL_UNBLOCK_LOW,
|
|
19
20
|
constants_1.WA_APP_STATE_COLLECTIONS.CRITICAL_BLOCK,
|
|
20
21
|
constants_1.WA_APP_STATE_COLLECTIONS.REGULAR_LOW,
|
|
21
22
|
constants_1.WA_APP_STATE_COLLECTIONS.REGULAR,
|
|
22
23
|
constants_1.WA_APP_STATE_COLLECTIONS.REGULAR_HIGH
|
|
23
|
-
];
|
|
24
|
+
]);
|
package/dist/appstate/utils.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.keyIdToHex = keyIdToHex;
|
|
4
3
|
exports.parseCollectionName = parseCollectionName;
|
|
5
4
|
exports.keyDeviceId = keyDeviceId;
|
|
6
5
|
exports.keyEpoch = keyEpoch;
|
|
@@ -8,33 +7,18 @@ exports.pickActiveSyncKey = pickActiveSyncKey;
|
|
|
8
7
|
exports.toNetworkOrder64 = toNetworkOrder64;
|
|
9
8
|
exports.downloadExternalBlobReference = downloadExternalBlobReference;
|
|
10
9
|
const constants_1 = require("../protocol/constants");
|
|
11
|
-
const base64_1 = require("../util/base64");
|
|
12
10
|
const bytes_1 = require("../util/bytes");
|
|
13
|
-
|
|
14
|
-
return (0, bytes_1.bytesToHex)(keyId);
|
|
15
|
-
}
|
|
11
|
+
const APP_STATE_COLLECTION_NAMES = new Set(Object.values(constants_1.WA_APP_STATE_COLLECTIONS));
|
|
16
12
|
function parseCollectionName(value) {
|
|
17
|
-
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
for (const collection of Object.values(constants_1.WA_APP_STATE_COLLECTIONS)) {
|
|
21
|
-
if (collection === value) {
|
|
22
|
-
return collection;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
13
|
+
return value && APP_STATE_COLLECTION_NAMES.has(value) ? value : null;
|
|
26
14
|
}
|
|
27
15
|
function keyDeviceId(keyId) {
|
|
28
|
-
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
return (keyId[0] << 8) | keyId[1];
|
|
16
|
+
return keyId.byteLength < 6 ? null : (keyId[0] << 8) | keyId[1];
|
|
32
17
|
}
|
|
33
18
|
function keyEpoch(keyId) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return new DataView(keyId.buffer, keyId.byteOffset, keyId.byteLength).getUint32(2, false);
|
|
19
|
+
return keyId.byteLength < 6
|
|
20
|
+
? -1
|
|
21
|
+
: keyId[2] * 16777216 + keyId[3] * 65536 + keyId[4] * 256 + keyId[5];
|
|
38
22
|
}
|
|
39
23
|
function pickActiveSyncKey(keys) {
|
|
40
24
|
let active = null;
|
|
@@ -61,19 +45,15 @@ function pickActiveSyncKey(keys) {
|
|
|
61
45
|
return active;
|
|
62
46
|
}
|
|
63
47
|
function toNetworkOrder64(value) {
|
|
64
|
-
|
|
65
|
-
const view = new DataView(out.buffer);
|
|
66
|
-
view.setUint32(0, Math.floor(value / 4294967296), false);
|
|
67
|
-
view.setUint32(4, value >>> 0, false);
|
|
68
|
-
return out;
|
|
48
|
+
return (0, bytes_1.intToBytes)(8, value);
|
|
69
49
|
}
|
|
70
50
|
async function downloadExternalBlobReference(mediaTransfer, reference) {
|
|
71
51
|
if (!reference.directPath) {
|
|
72
52
|
throw new Error('external blob reference is missing directPath');
|
|
73
53
|
}
|
|
74
|
-
const mediaKey = (0,
|
|
75
|
-
const fileSha256 = (0,
|
|
76
|
-
const fileEncSha256 = (0,
|
|
54
|
+
const mediaKey = (0, bytes_1.decodeProtoBytes)(reference.mediaKey, 'external blob mediaKey');
|
|
55
|
+
const fileSha256 = (0, bytes_1.decodeProtoBytes)(reference.fileSha256, 'external blob fileSha256');
|
|
56
|
+
const fileEncSha256 = (0, bytes_1.decodeProtoBytes)(reference.fileEncSha256, 'external blob fileEncSha256');
|
|
77
57
|
return mediaTransfer.downloadAndDecrypt({
|
|
78
58
|
directPath: reference.directPath,
|
|
79
59
|
mediaType: constants_1.WA_APP_STATE_KEY_TYPES.MD_APP_STATE,
|
|
@@ -53,7 +53,7 @@ class WaAuthClient {
|
|
|
53
53
|
getState(connected = false) {
|
|
54
54
|
return {
|
|
55
55
|
connected,
|
|
56
|
-
registered: this.credentials
|
|
56
|
+
registered: hasMeJid(this.credentials),
|
|
57
57
|
hasQr: this.qrFlow.hasQr(),
|
|
58
58
|
hasPairingCode: this.pairingFlow.hasPairingSession()
|
|
59
59
|
};
|
|
@@ -70,7 +70,7 @@ class WaAuthClient {
|
|
|
70
70
|
signalStore: this.signalStore
|
|
71
71
|
});
|
|
72
72
|
this.logger.info('auth client credentials ready', {
|
|
73
|
-
registered: this.credentials
|
|
73
|
+
registered: hasMeJid(this.credentials)
|
|
74
74
|
});
|
|
75
75
|
return this.credentials;
|
|
76
76
|
});
|
|
@@ -144,51 +144,47 @@ class WaAuthClient {
|
|
|
144
144
|
}
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
|
-
async persistMeLid(meLid) {
|
|
148
|
-
await this.persistSuccessAttributes({
|
|
149
|
-
meLid
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
147
|
async persistSuccessAttributes(attributes) {
|
|
153
|
-
let changes = {};
|
|
154
148
|
await this.patchCredentials((credentials) => {
|
|
155
|
-
const nextMeLid = attributes.meLid ?? credentials.meLid;
|
|
156
|
-
const nextMeDisplayName = attributes.meDisplayName ?? credentials.meDisplayName;
|
|
157
|
-
const nextCompanionEncStatic = attributes.companionEncStatic ?? credentials.companionEncStatic;
|
|
158
|
-
const nextLastSuccessTs = attributes.lastSuccessTs ?? credentials.lastSuccessTs;
|
|
159
|
-
const nextPropsVersion = attributes.propsVersion ?? credentials.propsVersion;
|
|
160
|
-
const nextAbPropsVersion = attributes.abPropsVersion ?? credentials.abPropsVersion;
|
|
161
|
-
const nextConnectionLocation = attributes.connectionLocation ?? credentials.connectionLocation;
|
|
162
|
-
const nextAccountCreationTs = attributes.accountCreationTs ?? credentials.accountCreationTs;
|
|
163
|
-
changes = {
|
|
164
|
-
lidChanged: nextMeLid !== credentials.meLid,
|
|
165
|
-
displayNameChanged: nextMeDisplayName !== credentials.meDisplayName,
|
|
166
|
-
companionChanged: (credentials.companionEncStatic === undefined) !==
|
|
167
|
-
(nextCompanionEncStatic === undefined) ||
|
|
168
|
-
(credentials.companionEncStatic !== undefined &&
|
|
169
|
-
nextCompanionEncStatic !== undefined &&
|
|
170
|
-
!(0, bytes_1.uint8Equal)(credentials.companionEncStatic, nextCompanionEncStatic)),
|
|
171
|
-
lastSuccessTsChanged: nextLastSuccessTs !== credentials.lastSuccessTs,
|
|
172
|
-
propsVersionChanged: nextPropsVersion !== credentials.propsVersion,
|
|
173
|
-
abPropsVersionChanged: nextAbPropsVersion !== credentials.abPropsVersion,
|
|
174
|
-
connectionLocationChanged: nextConnectionLocation !== credentials.connectionLocation,
|
|
175
|
-
accountCreationTsChanged: nextAccountCreationTs !== credentials.accountCreationTs
|
|
176
|
-
};
|
|
177
149
|
return {
|
|
178
150
|
...credentials,
|
|
179
|
-
meLid:
|
|
180
|
-
meDisplayName:
|
|
181
|
-
companionEncStatic:
|
|
182
|
-
lastSuccessTs:
|
|
183
|
-
propsVersion:
|
|
184
|
-
abPropsVersion:
|
|
185
|
-
connectionLocation:
|
|
186
|
-
accountCreationTs:
|
|
151
|
+
meLid: attributes.meLid ?? credentials.meLid,
|
|
152
|
+
meDisplayName: attributes.meDisplayName ?? credentials.meDisplayName,
|
|
153
|
+
companionEncStatic: attributes.companionEncStatic ?? credentials.companionEncStatic,
|
|
154
|
+
lastSuccessTs: attributes.lastSuccessTs ?? credentials.lastSuccessTs,
|
|
155
|
+
propsVersion: attributes.propsVersion ?? credentials.propsVersion,
|
|
156
|
+
abPropsVersion: attributes.abPropsVersion ?? credentials.abPropsVersion,
|
|
157
|
+
connectionLocation: attributes.connectionLocation ?? credentials.connectionLocation,
|
|
158
|
+
accountCreationTs: attributes.accountCreationTs ?? credentials.accountCreationTs
|
|
187
159
|
};
|
|
188
160
|
}, {
|
|
189
|
-
shouldPersist: () =>
|
|
190
|
-
|
|
191
|
-
|
|
161
|
+
shouldPersist: (current, next) => next.meLid !== current.meLid ||
|
|
162
|
+
next.meDisplayName !== current.meDisplayName ||
|
|
163
|
+
(current.companionEncStatic === undefined) !==
|
|
164
|
+
(next.companionEncStatic === undefined) ||
|
|
165
|
+
(current.companionEncStatic !== undefined &&
|
|
166
|
+
next.companionEncStatic !== undefined &&
|
|
167
|
+
!(0, bytes_1.uint8Equal)(current.companionEncStatic, next.companionEncStatic)) ||
|
|
168
|
+
next.lastSuccessTs !== current.lastSuccessTs ||
|
|
169
|
+
next.propsVersion !== current.propsVersion ||
|
|
170
|
+
next.abPropsVersion !== current.abPropsVersion ||
|
|
171
|
+
next.connectionLocation !== current.connectionLocation ||
|
|
172
|
+
next.accountCreationTs !== current.accountCreationTs,
|
|
173
|
+
onPersist: (current, next) => {
|
|
174
|
+
this.logger.debug('persisting success attributes', {
|
|
175
|
+
lidChanged: next.meLid !== current.meLid,
|
|
176
|
+
displayNameChanged: next.meDisplayName !== current.meDisplayName,
|
|
177
|
+
companionChanged: (current.companionEncStatic === undefined) !==
|
|
178
|
+
(next.companionEncStatic === undefined) ||
|
|
179
|
+
(current.companionEncStatic !== undefined &&
|
|
180
|
+
next.companionEncStatic !== undefined &&
|
|
181
|
+
!(0, bytes_1.uint8Equal)(current.companionEncStatic, next.companionEncStatic)),
|
|
182
|
+
lastSuccessTsChanged: next.lastSuccessTs !== current.lastSuccessTs,
|
|
183
|
+
propsVersionChanged: next.propsVersion !== current.propsVersion,
|
|
184
|
+
abPropsVersionChanged: next.abPropsVersion !== current.abPropsVersion,
|
|
185
|
+
connectionLocationChanged: next.connectionLocation !== current.connectionLocation,
|
|
186
|
+
accountCreationTsChanged: next.accountCreationTs !== current.accountCreationTs
|
|
187
|
+
});
|
|
192
188
|
}
|
|
193
189
|
});
|
|
194
190
|
}
|
|
@@ -203,24 +199,18 @@ class WaAuthClient {
|
|
|
203
199
|
return this.runHandled(() => this.pairingFlow.fetchPairingCountryCodeIso());
|
|
204
200
|
}
|
|
205
201
|
async handleIncomingIqSet(node) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return this.pairingFlow.handleIncomingIqSet(node);
|
|
209
|
-
});
|
|
202
|
+
this.logger.trace('auth client handleIncomingIqSet', { id: node.attrs.id });
|
|
203
|
+
return this.runHandled(() => this.pairingFlow.handleIncomingIqSet(node));
|
|
210
204
|
}
|
|
211
205
|
async handleLinkCodeNotification(node) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return this.pairingFlow.handleLinkCodeNotification(node);
|
|
215
|
-
});
|
|
206
|
+
this.logger.trace('auth client handleLinkCodeNotification', { id: node.attrs.id });
|
|
207
|
+
return this.runHandled(() => this.pairingFlow.handleLinkCodeNotification(node));
|
|
216
208
|
}
|
|
217
209
|
async handleCompanionRegRefreshNotification(node) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
id: node.attrs.id
|
|
221
|
-
});
|
|
222
|
-
return this.pairingFlow.handleCompanionRegRefreshNotification(node);
|
|
210
|
+
this.logger.trace('auth client handleCompanionRegRefreshNotification', {
|
|
211
|
+
id: node.attrs.id
|
|
223
212
|
});
|
|
213
|
+
return this.runHandled(() => this.pairingFlow.handleCompanionRegRefreshNotification(node));
|
|
224
214
|
}
|
|
225
215
|
async patchCredentials(buildNext, options = {}) {
|
|
226
216
|
const current = this.requireCredentials();
|
|
@@ -243,7 +233,7 @@ class WaAuthClient {
|
|
|
243
233
|
}
|
|
244
234
|
async updateCredentials(credentials) {
|
|
245
235
|
this.logger.trace('auth client update credentials', {
|
|
246
|
-
registered: credentials
|
|
236
|
+
registered: hasMeJid(credentials)
|
|
247
237
|
});
|
|
248
238
|
this.credentials = credentials;
|
|
249
239
|
await (0, WaAuthCredentialsFlow_1.persistCredentials)({
|
|
@@ -264,3 +254,6 @@ class WaAuthClient {
|
|
|
264
254
|
}
|
|
265
255
|
}
|
|
266
256
|
exports.WaAuthClient = WaAuthClient;
|
|
257
|
+
function hasMeJid(credentials) {
|
|
258
|
+
return credentials?.meJid !== null && credentials?.meJid !== undefined;
|
|
259
|
+
}
|
|
@@ -9,22 +9,23 @@ const X25519_1 = require("../../crypto/curves/X25519");
|
|
|
9
9
|
const jid_1 = require("../../protocol/jid");
|
|
10
10
|
const WaAdvSignature_1 = require("../../signal/crypto/WaAdvSignature");
|
|
11
11
|
const utils_1 = require("../../signal/registration/utils");
|
|
12
|
+
const proxy_1 = require("../../transport/proxy");
|
|
12
13
|
const primitives_1 = require("../../util/primitives");
|
|
13
14
|
async function loadOrCreateCredentials(args) {
|
|
14
15
|
args.logger.trace('auth credentials loadOrCreate start');
|
|
15
16
|
const existing = await args.authStore.load();
|
|
16
17
|
if (!existing) {
|
|
17
|
-
const credentials = await
|
|
18
|
+
const credentials = await createFreshAndPersistCredentials(args);
|
|
18
19
|
args.logger.info('created fresh auth credentials');
|
|
19
20
|
return credentials;
|
|
20
21
|
}
|
|
21
22
|
args.logger.debug('auth credentials loaded from store', {
|
|
22
|
-
registered: existing
|
|
23
|
+
registered: isRegistered(existing),
|
|
23
24
|
hasServerStaticKey: existing.serverStaticKey !== null && existing.serverStaticKey !== undefined
|
|
24
25
|
});
|
|
25
26
|
if (!existing.meJid && !(await hasValidSignedPreKey(args.logger, existing))) {
|
|
26
27
|
args.logger.warn('signed pre-key is invalid, regenerating credentials');
|
|
27
|
-
const fresh = await
|
|
28
|
+
const fresh = await createFreshAndPersistCredentials(args);
|
|
28
29
|
args.logger.info('regenerated credentials due to invalid signed pre-key');
|
|
29
30
|
return fresh;
|
|
30
31
|
}
|
|
@@ -34,13 +35,15 @@ async function loadOrCreateCredentials(args) {
|
|
|
34
35
|
}
|
|
35
36
|
async function persistCredentials(args, credentials) {
|
|
36
37
|
args.logger.trace('persisting auth credentials', {
|
|
37
|
-
registered: credentials
|
|
38
|
+
registered: isRegistered(credentials)
|
|
38
39
|
});
|
|
39
40
|
await args.authStore.save(credentials);
|
|
40
41
|
}
|
|
41
42
|
function buildCommsConfig(logger, credentials, socketOptions, clientOptions) {
|
|
42
|
-
const
|
|
43
|
-
const
|
|
43
|
+
const meJid = credentials.meJid;
|
|
44
|
+
const registered = meJid !== null && meJid !== undefined;
|
|
45
|
+
const loginIdentity = registered ? (0, jid_1.getLoginIdentity)(meJid) : null;
|
|
46
|
+
const wsProxy = socketOptions.proxy?.ws;
|
|
44
47
|
logger.debug('building comms config from credentials', {
|
|
45
48
|
registered,
|
|
46
49
|
hasServerStaticKey: credentials.serverStaticKey !== null && credentials.serverStaticKey !== undefined
|
|
@@ -49,6 +52,8 @@ function buildCommsConfig(logger, credentials, socketOptions, clientOptions) {
|
|
|
49
52
|
url: socketOptions.url,
|
|
50
53
|
urls: socketOptions.urls,
|
|
51
54
|
protocols: socketOptions.protocols,
|
|
55
|
+
dispatcher: (0, proxy_1.toProxyDispatcher)(wsProxy),
|
|
56
|
+
agent: (0, proxy_1.toProxyAgent)(wsProxy),
|
|
52
57
|
connectTimeoutMs: socketOptions.connectTimeoutMs,
|
|
53
58
|
reconnectIntervalMs: socketOptions.reconnectIntervalMs,
|
|
54
59
|
timeoutIntervalMs: socketOptions.timeoutIntervalMs,
|
|
@@ -93,9 +98,10 @@ async function createFreshCredentials(signalStore, logger) {
|
|
|
93
98
|
advSecretKey
|
|
94
99
|
};
|
|
95
100
|
}
|
|
96
|
-
async function
|
|
101
|
+
async function createFreshAndPersistCredentials(args) {
|
|
97
102
|
const credentials = await createFreshCredentials(args.signalStore, args.logger);
|
|
98
|
-
await
|
|
103
|
+
await args.authStore.save(credentials);
|
|
104
|
+
await restoreSignalStore(args.signalStore, credentials);
|
|
99
105
|
return credentials;
|
|
100
106
|
}
|
|
101
107
|
async function hasValidSignedPreKey(logger, credentials) {
|
|
@@ -113,11 +119,12 @@ async function hasValidSignedPreKey(logger, credentials) {
|
|
|
113
119
|
}
|
|
114
120
|
}
|
|
115
121
|
async function restoreSignalStore(signalStore, credentials) {
|
|
116
|
-
await
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
await Promise.all([
|
|
123
|
+
signalStore.setRegistrationInfo(credentials.registrationInfo),
|
|
124
|
+
signalStore.setSignedPreKey(credentials.signedPreKey),
|
|
125
|
+
signalStore.setServerHasPreKeys(credentials.serverHasPreKeys === true)
|
|
126
|
+
]);
|
|
119
127
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
await restoreSignalStore(args.signalStore, credentials);
|
|
128
|
+
function isRegistered(credentials) {
|
|
129
|
+
return credentials.meJid !== null && credentials.meJid !== undefined;
|
|
123
130
|
}
|
package/dist/auth/index.js
CHANGED
|
@@ -14,10 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.WaAuthSqliteStore = exports.createCompanionHello = exports.completeCompanionFinish = exports.WaAuthClient =
|
|
17
|
+
exports.WaAuthSqliteStore = exports.createCompanionHello = exports.completeCompanionFinish = exports.WaAuthClient = void 0;
|
|
18
18
|
__exportStar(require("./types"), exports);
|
|
19
|
-
var jid_1 = require("../protocol/jid");
|
|
20
|
-
Object.defineProperty(exports, "getLoginIdentity", { enumerable: true, get: function () { return jid_1.getLoginIdentity; } });
|
|
21
19
|
var WaAuthClient_1 = require("./WaAuthClient");
|
|
22
20
|
Object.defineProperty(exports, "WaAuthClient", { enumerable: true, get: function () { return WaAuthClient_1.WaAuthClient; } });
|
|
23
21
|
var WaPairingCodeCrypto_1 = require("./pairing/WaPairingCodeCrypto");
|
|
@@ -9,8 +9,8 @@ const jid_1 = require("../../protocol/jid");
|
|
|
9
9
|
const WaAdvSignature_1 = require("../../signal/crypto/WaAdvSignature");
|
|
10
10
|
const pairing_1 = require("../../transport/node/builders/pairing");
|
|
11
11
|
const helpers_1 = require("../../transport/node/helpers");
|
|
12
|
-
const base64_1 = require("../../util/base64");
|
|
13
12
|
const bytes_1 = require("../../util/bytes");
|
|
13
|
+
const bytes_2 = require("../../util/bytes");
|
|
14
14
|
class WaPairingFlow {
|
|
15
15
|
constructor(options) {
|
|
16
16
|
this.opts = options;
|
|
@@ -129,7 +129,7 @@ class WaPairingFlow {
|
|
|
129
129
|
return true;
|
|
130
130
|
}
|
|
131
131
|
const ref = (0, helpers_1.decodeNodeContentUtf8OrBytes)(refNode.content, 'refresh_code.link_code_pairing_ref');
|
|
132
|
-
if ((0,
|
|
132
|
+
if ((0, bytes_2.uint8Equal)(ref, this.pairingSession.ref)) {
|
|
133
133
|
this.opts.logger.info('received pairing refresh notification', {
|
|
134
134
|
forceManualRefresh: linkCodeNode.attrs.force_manual_refresh === 'true'
|
|
135
135
|
});
|
|
@@ -156,9 +156,7 @@ class WaPairingFlow {
|
|
|
156
156
|
return true;
|
|
157
157
|
}
|
|
158
158
|
async handlePairDevice(iqNode, pairDeviceNode) {
|
|
159
|
-
const refs = (0, helpers_1.
|
|
160
|
-
.map((child) => bytes_1.TEXT_DECODER.decode((0, helpers_1.decodeNodeContentUtf8OrBytes)(child.content, 'pair-device.ref')))
|
|
161
|
-
.filter((ref) => ref.length > 0);
|
|
159
|
+
const refs = (0, helpers_1.getNodeChildrenNonEmptyUtf8ByTag)(pairDeviceNode, constants_1.WA_NODE_TAGS.REF, 'pair-device.ref');
|
|
162
160
|
await this.rotateAdvSecret(this.requireCredentials());
|
|
163
161
|
this.opts.qrFlow.setRefs(refs);
|
|
164
162
|
this.opts.logger.info('pair-device refs updated', { refsCount: refs.length });
|
|
@@ -167,9 +165,7 @@ class WaPairingFlow {
|
|
|
167
165
|
async handlePairSuccess(iqNode, pairSuccessNode) {
|
|
168
166
|
this.opts.logger.info('processing pair-success node');
|
|
169
167
|
const credentials = this.requireCredentials();
|
|
170
|
-
const deviceIdentityNode = (0, helpers_1.
|
|
171
|
-
const deviceNode = (0, helpers_1.findNodeChild)(pairSuccessNode, 'device');
|
|
172
|
-
const platformNode = (0, helpers_1.findNodeChild)(pairSuccessNode, constants_1.WA_NODE_TAGS.PLATFORM);
|
|
168
|
+
const [deviceIdentityNode, deviceNode, platformNode] = (0, helpers_1.findNodeChildrenByTags)(pairSuccessNode, [constants_1.WA_NODE_TAGS.DEVICE_IDENTITY, 'device', constants_1.WA_NODE_TAGS.PLATFORM]);
|
|
173
169
|
if (!deviceIdentityNode || !deviceNode || !platformNode) {
|
|
174
170
|
this.opts.logger.error('pair-success missing required nodes', {
|
|
175
171
|
hasDeviceIdentity: !!deviceIdentityNode,
|
|
@@ -179,15 +175,15 @@ class WaPairingFlow {
|
|
|
179
175
|
throw new Error('pair-success stanza is missing required nodes');
|
|
180
176
|
}
|
|
181
177
|
const wrappedIdentity = _proto_1.proto.ADVSignedDeviceIdentityHMAC.decode((0, helpers_1.decodeNodeContentUtf8OrBytes)(deviceIdentityNode.content, 'pair-success.device-identity'));
|
|
182
|
-
const wrappedDetails = (0,
|
|
183
|
-
const wrappedHmac = (0,
|
|
178
|
+
const wrappedDetails = (0, bytes_1.decodeProtoBytes)(wrappedIdentity.details, 'ADVSignedDeviceIdentityHMAC.details');
|
|
179
|
+
const wrappedHmac = (0, bytes_1.decodeProtoBytes)(wrappedIdentity.hmac, 'ADVSignedDeviceIdentityHMAC.hmac');
|
|
184
180
|
const accountType = wrappedIdentity.accountType ?? _proto_1.proto.ADVEncryptionType.E2EE;
|
|
185
181
|
const isHosted = accountType === _proto_1.proto.ADVEncryptionType.HOSTED;
|
|
186
182
|
const hmacInput = isHosted
|
|
187
|
-
? (0,
|
|
183
|
+
? (0, bytes_2.concatBytes)([WaAdvSignature_1.ADV_PREFIX_HOSTED_ACCOUNT_SIGNATURE, wrappedDetails])
|
|
188
184
|
: wrappedDetails;
|
|
189
185
|
const expectedHmac = await (0, WaAdvSignature_1.computeAdvIdentityHmac)(credentials.advSecretKey, hmacInput);
|
|
190
|
-
if (!(0,
|
|
186
|
+
if (!(0, bytes_2.uint8Equal)(expectedHmac, wrappedHmac)) {
|
|
191
187
|
this.opts.logger.error('pair-success hmac mismatch');
|
|
192
188
|
throw new Error('pair-success HMAC validation failed');
|
|
193
189
|
}
|
|
@@ -234,9 +230,9 @@ class WaPairingFlow {
|
|
|
234
230
|
}
|
|
235
231
|
async buildPairSuccessResponseIdentity(credentials, wrappedDetails, isHosted) {
|
|
236
232
|
const signedIdentity = _proto_1.proto.ADVSignedDeviceIdentity.decode(wrappedDetails);
|
|
237
|
-
const details = (0,
|
|
238
|
-
const accountSignature = (0,
|
|
239
|
-
const accountSignatureKey = (0,
|
|
233
|
+
const details = (0, bytes_1.decodeProtoBytes)(signedIdentity.details, 'ADVSignedDeviceIdentity.details');
|
|
234
|
+
const accountSignature = (0, bytes_1.decodeProtoBytes)(signedIdentity.accountSignature, 'ADVSignedDeviceIdentity.accountSignature');
|
|
235
|
+
const accountSignatureKey = (0, bytes_1.decodeProtoBytes)(signedIdentity.accountSignatureKey, 'ADVSignedDeviceIdentity.accountSignatureKey');
|
|
240
236
|
const localIdentity = credentials.registrationInfo.identityKeyPair;
|
|
241
237
|
const validAccountSignature = await (0, WaAdvSignature_1.verifyDeviceIdentityAccountSignature)(details, accountSignature, localIdentity.pubKey, accountSignatureKey, isHosted);
|
|
242
238
|
if (!validAccountSignature) {
|
|
@@ -270,14 +266,16 @@ class WaPairingFlow {
|
|
|
270
266
|
if (pairingSession.attempts > 3) {
|
|
271
267
|
throw new Error('pairing code exceeded maximum primary hello attempts');
|
|
272
268
|
}
|
|
273
|
-
const refNode = (0, helpers_1.
|
|
274
|
-
|
|
275
|
-
|
|
269
|
+
const [refNode, wrappedPrimaryNode, primaryIdentityNode] = (0, helpers_1.findNodeChildrenByTags)(linkCodeNode, [
|
|
270
|
+
constants_1.WA_NODE_TAGS.LINK_CODE_PAIRING_REF,
|
|
271
|
+
'link_code_pairing_wrapped_primary_ephemeral_pub',
|
|
272
|
+
'primary_identity_pub'
|
|
273
|
+
]);
|
|
276
274
|
if (!refNode || !wrappedPrimaryNode || !primaryIdentityNode) {
|
|
277
275
|
throw new Error('primary_hello notification is missing fields');
|
|
278
276
|
}
|
|
279
277
|
const ref = (0, helpers_1.decodeNodeContentUtf8OrBytes)(refNode.content, 'primary_hello.link_code_pairing_ref');
|
|
280
|
-
if (!pairingSession.ref || !(0,
|
|
278
|
+
if (!pairingSession.ref || !(0, bytes_2.uint8Equal)(ref, pairingSession.ref)) {
|
|
281
279
|
this.opts.logger.warn('primary_hello ref mismatch ignored');
|
|
282
280
|
return;
|
|
283
281
|
}
|
|
@@ -293,10 +291,6 @@ class WaPairingFlow {
|
|
|
293
291
|
companionEphemeralPrivKey: pairingSession.companionEphemeralKeyPair.privKey,
|
|
294
292
|
registrationIdentityKeyPair: credentials.registrationInfo.identityKeyPair
|
|
295
293
|
});
|
|
296
|
-
await this.opts.auth.updateCredentials({
|
|
297
|
-
...credentials,
|
|
298
|
-
advSecretKey: finish.advSecret
|
|
299
|
-
});
|
|
300
294
|
const result = await this.opts.socket.query((0, pairing_1.buildCompanionFinishRequestNode)({
|
|
301
295
|
phoneJid: pairingSession.phoneJid,
|
|
302
296
|
wrappedKeyBundle: finish.wrappedKeyBundle,
|
|
@@ -306,6 +300,10 @@ class WaPairingFlow {
|
|
|
306
300
|
if (result.attrs.type === constants_1.WA_IQ_TYPES.ERROR) {
|
|
307
301
|
throw new Error('companion_finish returned error');
|
|
308
302
|
}
|
|
303
|
+
await this.opts.auth.updateCredentials({
|
|
304
|
+
...credentials,
|
|
305
|
+
advSecretKey: finish.advSecret
|
|
306
|
+
});
|
|
309
307
|
pairingSession.finished = true;
|
|
310
308
|
this.opts.logger.info('primary_hello completed with companion_finish success');
|
|
311
309
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WaQrFlow = void 0;
|
|
4
4
|
const constants_1 = require("../../protocol/constants");
|
|
5
|
-
const
|
|
5
|
+
const bytes_1 = require("../../util/bytes");
|
|
6
6
|
class WaQrFlow {
|
|
7
7
|
constructor(args) {
|
|
8
8
|
this.logger = args.logger;
|
|
@@ -10,11 +10,11 @@ class WaQrFlow {
|
|
|
10
10
|
this.getDevicePlatform = args.getDevicePlatform;
|
|
11
11
|
this.emitQr = args.emitQr;
|
|
12
12
|
this.qrRefs = [];
|
|
13
|
-
this.
|
|
13
|
+
this.qrRefIndex = 0;
|
|
14
14
|
this.currentQrTimer = null;
|
|
15
15
|
}
|
|
16
16
|
hasQr() {
|
|
17
|
-
return this.qrRefs.length
|
|
17
|
+
return this.qrRefIndex < this.qrRefs.length || this.currentQrTimer !== null;
|
|
18
18
|
}
|
|
19
19
|
clear() {
|
|
20
20
|
this.logger.trace('qr flow clear');
|
|
@@ -23,28 +23,32 @@ class WaQrFlow {
|
|
|
23
23
|
this.currentQrTimer = null;
|
|
24
24
|
}
|
|
25
25
|
this.qrRefs = [];
|
|
26
|
-
this.
|
|
26
|
+
this.qrRefIndex = 0;
|
|
27
27
|
}
|
|
28
28
|
refreshCurrentQr() {
|
|
29
|
-
if (
|
|
29
|
+
if (this.qrRefIndex === 0) {
|
|
30
30
|
this.logger.trace('qr flow refresh skipped: no active ref');
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
33
|
+
const ref = this.qrRefs[this.qrRefIndex - 1];
|
|
33
34
|
const credentials = this.getCredentials();
|
|
34
35
|
if (!credentials) {
|
|
35
36
|
this.logger.warn('qr flow refresh skipped: missing credentials');
|
|
36
37
|
return false;
|
|
37
38
|
}
|
|
38
|
-
const ttlMs = this.qrRefs.length === 5
|
|
39
|
+
const ttlMs = this.qrRefs.length - this.qrRefIndex === 5
|
|
39
40
|
? constants_1.WA_DEFAULTS.QR_INITIAL_TTL_MS
|
|
40
41
|
: constants_1.WA_DEFAULTS.QR_ROTATION_TTL_MS;
|
|
41
|
-
this.logger.debug('qr flow refresh emit', {
|
|
42
|
-
|
|
42
|
+
this.logger.debug('qr flow refresh emit', {
|
|
43
|
+
ttlMs,
|
|
44
|
+
remainingRefs: this.qrRefs.length - this.qrRefIndex
|
|
45
|
+
});
|
|
46
|
+
this.emitQr(this.buildQr(ref, credentials), ttlMs);
|
|
43
47
|
return true;
|
|
44
48
|
}
|
|
45
49
|
setRefs(refs) {
|
|
46
50
|
this.clear();
|
|
47
|
-
this.qrRefs =
|
|
51
|
+
this.qrRefs = refs;
|
|
48
52
|
this.logger.info('qr refs updated', { count: this.qrRefs.length });
|
|
49
53
|
if (this.qrRefs.length === 0) {
|
|
50
54
|
return;
|
|
@@ -57,30 +61,39 @@ class WaQrFlow {
|
|
|
57
61
|
this.clear();
|
|
58
62
|
return;
|
|
59
63
|
}
|
|
60
|
-
|
|
61
|
-
if (!ref) {
|
|
64
|
+
if (this.qrRefIndex >= this.qrRefs.length) {
|
|
62
65
|
this.clear();
|
|
63
66
|
return;
|
|
64
67
|
}
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.logger.trace('qr flow emit new code', { ttlMs, remainingRefs: this.qrRefs.length });
|
|
70
|
-
this.emitQr(this.buildQr(ref, credentials), ttlMs);
|
|
68
|
+
const ref = this.qrRefs[this.qrRefIndex++];
|
|
69
|
+
const remainingRefs = this.qrRefs.length - this.qrRefIndex;
|
|
70
|
+
const ttlMs = remainingRefs === 5 ? constants_1.WA_DEFAULTS.QR_INITIAL_TTL_MS : constants_1.WA_DEFAULTS.QR_ROTATION_TTL_MS;
|
|
71
|
+
this.logger.trace('qr flow emit new code', { ttlMs, remainingRefs });
|
|
71
72
|
this.currentQrTimer = setTimeout(() => {
|
|
72
73
|
this.currentQrTimer = null;
|
|
73
74
|
this.rotateRef();
|
|
74
75
|
}, ttlMs);
|
|
76
|
+
try {
|
|
77
|
+
this.emitQr(this.buildQr(ref, credentials), ttlMs);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (this.currentQrTimer) {
|
|
81
|
+
clearTimeout(this.currentQrTimer);
|
|
82
|
+
this.currentQrTimer = null;
|
|
83
|
+
}
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
75
86
|
}
|
|
76
87
|
buildQr(ref, credentials) {
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
(0,
|
|
80
|
-
|
|
81
|
-
(0,
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
return (ref +
|
|
89
|
+
',' +
|
|
90
|
+
(0, bytes_1.bytesToBase64)(credentials.noiseKeyPair.pubKey) +
|
|
91
|
+
',' +
|
|
92
|
+
(0, bytes_1.bytesToBase64)(credentials.registrationInfo.identityKeyPair.pubKey) +
|
|
93
|
+
',' +
|
|
94
|
+
(0, bytes_1.bytesToBase64)(credentials.advSecretKey) +
|
|
95
|
+
',' +
|
|
96
|
+
this.getDevicePlatform());
|
|
84
97
|
}
|
|
85
98
|
}
|
|
86
99
|
exports.WaQrFlow = WaQrFlow;
|