zapo-js 1.3.0 → 1.4.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.
Files changed (34) hide show
  1. package/dist/auth/WaAuthClient.d.ts +15 -0
  2. package/dist/auth/WaAuthClient.js +47 -0
  3. package/dist/auth/pairing/WaShortcakeFlow.d.ts +93 -0
  4. package/dist/auth/pairing/WaShortcakeFlow.js +210 -0
  5. package/dist/auth/pairing/pairing-code-crypto.d.ts +1 -0
  6. package/dist/auth/pairing/pairing-code-crypto.js +3 -2
  7. package/dist/auth/pairing/shortcake-crypto.d.ts +59 -0
  8. package/dist/auth/pairing/shortcake-crypto.js +106 -0
  9. package/dist/client/WaClientFactory.js +3 -1
  10. package/dist/client/coordinators/WaRetryCoordinator.js +1 -0
  11. package/dist/client/types.d.ts +19 -0
  12. package/dist/esm/auth/WaAuthClient.js +48 -1
  13. package/dist/esm/auth/pairing/WaShortcakeFlow.js +206 -0
  14. package/dist/esm/auth/pairing/pairing-code-crypto.js +2 -2
  15. package/dist/esm/auth/pairing/shortcake-crypto.js +99 -0
  16. package/dist/esm/client/WaClientFactory.js +3 -1
  17. package/dist/esm/client/coordinators/WaRetryCoordinator.js +1 -0
  18. package/dist/esm/protocol/nodes.js +2 -0
  19. package/dist/esm/protocol/notification.js +3 -1
  20. package/dist/esm/retry/replay.js +4 -12
  21. package/dist/esm/transport/node/builders/shortcake.js +50 -0
  22. package/dist/esm/transport/noise/WaClientPayload.js +1 -1
  23. package/dist/index.d.ts +1 -0
  24. package/dist/protocol/nodes.d.ts +2 -0
  25. package/dist/protocol/nodes.js +2 -0
  26. package/dist/protocol/notification.d.ts +2 -0
  27. package/dist/protocol/notification.js +3 -1
  28. package/dist/retry/replay.d.ts +1 -0
  29. package/dist/retry/replay.js +4 -12
  30. package/dist/transport/node/builders/shortcake.d.ts +19 -0
  31. package/dist/transport/node/builders/shortcake.js +57 -0
  32. package/dist/transport/noise/WaClientPayload.d.ts +2 -0
  33. package/dist/transport/noise/WaClientPayload.js +1 -0
  34. package/package.json +1 -1
@@ -88,9 +88,9 @@ class WaRetryReplayService {
88
88
  resolveSignedDeviceIdentity(context) {
89
89
  const signedIdentity = this.options.getCurrentCredentials()?.signedIdentity;
90
90
  if (!signedIdentity) {
91
- this.options.logger.warn('retry request missing signed identity for pkmsg envelope', {
92
- context
93
- });
91
+ if (!this.options.isMobilePrimary?.()) {
92
+ this.options.logger.warn('retry request missing signed identity for pkmsg envelope', { context });
93
+ }
94
94
  return undefined;
95
95
  }
96
96
  return _proto_1.proto.ADVSignedDeviceIdentity.encode(signedIdentity).finish();
@@ -182,15 +182,7 @@ class WaRetryReplayService {
182
182
  logContext: 'group'
183
183
  })) ?? payload.plaintext;
184
184
  const encrypted = await this.options.signalProtocol.encryptMessage(requesterAddress, plaintext);
185
- let deviceIdentity;
186
- if (encrypted.type === 'pkmsg') {
187
- const signedIdentity = this.options.getCurrentCredentials()?.signedIdentity;
188
- if (!signedIdentity) {
189
- this.options.logger.warn('retry request rejected: missing signed identity for pkmsg group retry');
190
- return 'ineligible';
191
- }
192
- deviceIdentity = _proto_1.proto.ADVSignedDeviceIdentity.encode(signedIdentity).finish();
193
- }
185
+ const deviceIdentity = encrypted.type === 'pkmsg' ? this.resolveSignedDeviceIdentity('group') : undefined;
194
186
  const isStatus = (0, jid_1.isStatusBroadcastJid)(payload.to);
195
187
  const metaAttrs = {};
196
188
  if (isStatus) {
@@ -0,0 +1,19 @@
1
+ import type { BinaryNode } from '../../types';
2
+ /** `<iq type="get" xmlns="md"><passkey_request_options/></iq>` */
3
+ export declare function buildGetPasskeyRequestOptionsRequestNode(): BinaryNode;
4
+ /** `<iq type="get" xmlns="md"><ref/></iq>` */
5
+ export declare function buildShortcakeGetRefRequestNode(): BinaryNode;
6
+ /**
7
+ * `<iq type="set" xmlns="md"><passkey_prologue><credential_id/><webauthn_assertion/>`
8
+ * `<prologue_payload/>[<pairing_handoff_proof/>]</passkey_prologue></iq>`
9
+ */
10
+ export declare function buildSetPasskeyPrologueRequestNode(args: {
11
+ readonly credentialId: Uint8Array;
12
+ readonly webauthnAssertion: Uint8Array;
13
+ readonly prologuePayload: Uint8Array;
14
+ readonly pairingHandoffProof?: Uint8Array;
15
+ }): BinaryNode;
16
+ /** `<iq type="set" xmlns="md"><companion_nonce/></iq>` */
17
+ export declare function buildSetCompanionNonceRequestNode(companionNonce: Uint8Array): BinaryNode;
18
+ /** `<iq type="set" xmlns="md"><encrypted_pairing_request/></iq>` */
19
+ export declare function buildSetEncryptedPairingRequestRequestNode(encryptedPairingRequest: Uint8Array): BinaryNode;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildGetPasskeyRequestOptionsRequestNode = buildGetPasskeyRequestOptionsRequestNode;
4
+ exports.buildShortcakeGetRefRequestNode = buildShortcakeGetRefRequestNode;
5
+ exports.buildSetPasskeyPrologueRequestNode = buildSetPasskeyPrologueRequestNode;
6
+ exports.buildSetCompanionNonceRequestNode = buildSetCompanionNonceRequestNode;
7
+ exports.buildSetEncryptedPairingRequestRequestNode = buildSetEncryptedPairingRequestRequestNode;
8
+ const constants_1 = require("../../../protocol/constants");
9
+ const query_1 = require("../../node/query");
10
+ /**
11
+ * IQ builders for the WhatsApp "Shortcake" companion-linking protocol
12
+ * (`xmlns="md"`). Wire shapes mirror the official client's
13
+ * `WASmaxOutMd…Request` builders. The stanza `id` is assigned by the socket
14
+ * query layer, matching the other pairing builders.
15
+ */
16
+ function mdIq(type, content) {
17
+ return (0, query_1.buildIqNode)(type, constants_1.WA_DEFAULTS.HOST_DOMAIN, constants_1.WA_XMLNS.MD, content);
18
+ }
19
+ /** `<iq type="get" xmlns="md"><passkey_request_options/></iq>` */
20
+ function buildGetPasskeyRequestOptionsRequestNode() {
21
+ return mdIq(constants_1.WA_IQ_TYPES.GET, [
22
+ { tag: constants_1.WA_NODE_TAGS.PASSKEY_REQUEST_OPTIONS, attrs: {}, content: undefined }
23
+ ]);
24
+ }
25
+ /** `<iq type="get" xmlns="md"><ref/></iq>` */
26
+ function buildShortcakeGetRefRequestNode() {
27
+ return mdIq(constants_1.WA_IQ_TYPES.GET, [{ tag: constants_1.WA_NODE_TAGS.REF, attrs: {}, content: undefined }]);
28
+ }
29
+ /**
30
+ * `<iq type="set" xmlns="md"><passkey_prologue><credential_id/><webauthn_assertion/>`
31
+ * `<prologue_payload/>[<pairing_handoff_proof/>]</passkey_prologue></iq>`
32
+ */
33
+ function buildSetPasskeyPrologueRequestNode(args) {
34
+ const children = [
35
+ { tag: 'credential_id', attrs: {}, content: args.credentialId },
36
+ { tag: 'webauthn_assertion', attrs: {}, content: args.webauthnAssertion },
37
+ { tag: 'prologue_payload', attrs: {}, content: args.prologuePayload }
38
+ ];
39
+ if (args.pairingHandoffProof) {
40
+ children.push({
41
+ tag: 'pairing_handoff_proof',
42
+ attrs: {},
43
+ content: args.pairingHandoffProof
44
+ });
45
+ }
46
+ return mdIq(constants_1.WA_IQ_TYPES.SET, [{ tag: 'passkey_prologue', attrs: {}, content: children }]);
47
+ }
48
+ /** `<iq type="set" xmlns="md"><companion_nonce/></iq>` */
49
+ function buildSetCompanionNonceRequestNode(companionNonce) {
50
+ return mdIq(constants_1.WA_IQ_TYPES.SET, [{ tag: 'companion_nonce', attrs: {}, content: companionNonce }]);
51
+ }
52
+ /** `<iq type="set" xmlns="md"><encrypted_pairing_request/></iq>` */
53
+ function buildSetEncryptedPairingRequestRequestNode(encryptedPairingRequest) {
54
+ return mdIq(constants_1.WA_IQ_TYPES.SET, [
55
+ { tag: 'encrypted_pairing_request', attrs: {}, content: encryptedPairingRequest }
56
+ ]);
57
+ }
@@ -1,3 +1,5 @@
1
+ import { proto } from '../../proto';
1
2
  import type { WaLoginPayloadConfig, WaRegistrationPayloadConfig } from '../noise/types';
3
+ export declare function resolveDevicePropsPlatformType(deviceBrowser?: string): proto.DeviceProps.PlatformType;
2
4
  export declare function buildLoginPayload(config: WaLoginPayloadConfig): Uint8Array;
3
5
  export declare function buildRegistrationPayload(config: WaRegistrationPayloadConfig): Uint8Array;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveDevicePropsPlatformType = resolveDevicePropsPlatformType;
3
4
  exports.buildLoginPayload = buildLoginPayload;
4
5
  exports.buildRegistrationPayload = buildRegistrationPayload;
5
6
  const node_crypto_1 = require("node:crypto");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zapo-js",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "High-performance WhatsApp Web TypeScript library",
5
5
  "license": "MIT",
6
6
  "author": "vinikjkkj <contact@vinicius.email> (https://github.com/vinikjkkj)",