@open-e2ee/signal-protocol-sdk 0.1.0-alpha.1
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/ADAPTERS.md +195 -0
- package/ARCHITECTURE.md +206 -0
- package/CHANGELOG.md +13 -0
- package/LICENSE +661 -0
- package/NOTICE +27 -0
- package/README.md +152 -0
- package/SECURITY.md +125 -0
- package/THIRD_PARTY_NOTICES.md +31 -0
- package/TROUBLESHOOTING.md +203 -0
- package/blocking/README.md +42 -0
- package/client/README.md +169 -0
- package/device/README.md +166 -0
- package/dist/blocking/index.d.ts +4 -0
- package/dist/blocking/index.d.ts.map +1 -0
- package/dist/blocking/index.js +2 -0
- package/dist/blocking/index.js.map +1 -0
- package/dist/blocking/manager.d.ts +27 -0
- package/dist/blocking/manager.d.ts.map +1 -0
- package/dist/blocking/manager.js +61 -0
- package/dist/blocking/manager.js.map +1 -0
- package/dist/blocking/types.d.ts +43 -0
- package/dist/blocking/types.d.ts.map +1 -0
- package/dist/blocking/types.js +9 -0
- package/dist/blocking/types.js.map +1 -0
- package/dist/client/client.d.ts +1281 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +2296 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/compose.d.ts +105 -0
- package/dist/client/compose.d.ts.map +1 -0
- package/dist/client/compose.js +41 -0
- package/dist/client/compose.js.map +1 -0
- package/dist/client/config.d.ts +707 -0
- package/dist/client/config.d.ts.map +1 -0
- package/dist/client/config.js +19 -0
- package/dist/client/config.js.map +1 -0
- package/dist/client/constants.d.ts +48 -0
- package/dist/client/constants.d.ts.map +1 -0
- package/dist/client/constants.js +40 -0
- package/dist/client/constants.js.map +1 -0
- package/dist/client/content-adapter.d.ts +106 -0
- package/dist/client/content-adapter.d.ts.map +1 -0
- package/dist/client/content-adapter.js +423 -0
- package/dist/client/content-adapter.js.map +1 -0
- package/dist/client/dual-store.d.ts +70 -0
- package/dist/client/dual-store.d.ts.map +1 -0
- package/dist/client/dual-store.js +123 -0
- package/dist/client/dual-store.js.map +1 -0
- package/dist/client/endorsement-manager.d.ts +143 -0
- package/dist/client/endorsement-manager.d.ts.map +1 -0
- package/dist/client/endorsement-manager.js +259 -0
- package/dist/client/endorsement-manager.js.map +1 -0
- package/dist/client/event-hooks.d.ts +330 -0
- package/dist/client/event-hooks.d.ts.map +1 -0
- package/dist/client/event-hooks.js +59 -0
- package/dist/client/event-hooks.js.map +1 -0
- package/dist/client/files.d.ts +73 -0
- package/dist/client/files.d.ts.map +1 -0
- package/dist/client/files.js +192 -0
- package/dist/client/files.js.map +1 -0
- package/dist/client/groups.d.ts +204 -0
- package/dist/client/groups.d.ts.map +1 -0
- package/dist/client/groups.js +340 -0
- package/dist/client/groups.js.map +1 -0
- package/dist/client/headless.d.ts +99 -0
- package/dist/client/headless.d.ts.map +1 -0
- package/dist/client/headless.js +163 -0
- package/dist/client/headless.js.map +1 -0
- package/dist/client/index.d.ts +33 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +7 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/key-rotation-core.d.ts +167 -0
- package/dist/client/key-rotation-core.d.ts.map +1 -0
- package/dist/client/key-rotation-core.js +459 -0
- package/dist/client/key-rotation-core.js.map +1 -0
- package/dist/client/key-rotation.d.ts +45 -0
- package/dist/client/key-rotation.d.ts.map +1 -0
- package/dist/client/key-rotation.js +174 -0
- package/dist/client/key-rotation.js.map +1 -0
- package/dist/client/media.d.ts +173 -0
- package/dist/client/media.d.ts.map +1 -0
- package/dist/client/media.js +476 -0
- package/dist/client/media.js.map +1 -0
- package/dist/client/messages.d.ts +131 -0
- package/dist/client/messages.d.ts.map +1 -0
- package/dist/client/messages.js +546 -0
- package/dist/client/messages.js.map +1 -0
- package/dist/client/multi-device.d.ts +73 -0
- package/dist/client/multi-device.d.ts.map +1 -0
- package/dist/client/multi-device.js +104 -0
- package/dist/client/multi-device.js.map +1 -0
- package/dist/client/prekeys.d.ts +133 -0
- package/dist/client/prekeys.d.ts.map +1 -0
- package/dist/client/prekeys.js +608 -0
- package/dist/client/prekeys.js.map +1 -0
- package/dist/client/relay-subscription.d.ts +83 -0
- package/dist/client/relay-subscription.d.ts.map +1 -0
- package/dist/client/relay-subscription.js +353 -0
- package/dist/client/relay-subscription.js.map +1 -0
- package/dist/client/retry-utils.d.ts +42 -0
- package/dist/client/retry-utils.d.ts.map +1 -0
- package/dist/client/retry-utils.js +107 -0
- package/dist/client/retry-utils.js.map +1 -0
- package/dist/client/retry.d.ts +121 -0
- package/dist/client/retry.d.ts.map +1 -0
- package/dist/client/retry.js +499 -0
- package/dist/client/retry.js.map +1 -0
- package/dist/client/sealed-sender-ops.d.ts +61 -0
- package/dist/client/sealed-sender-ops.d.ts.map +1 -0
- package/dist/client/sealed-sender-ops.js +173 -0
- package/dist/client/sealed-sender-ops.js.map +1 -0
- package/dist/client/sessions.d.ts +108 -0
- package/dist/client/sessions.d.ts.map +1 -0
- package/dist/client/sessions.js +367 -0
- package/dist/client/sessions.js.map +1 -0
- package/dist/client/signal-service-cipher.d.ts +331 -0
- package/dist/client/signal-service-cipher.d.ts.map +1 -0
- package/dist/client/signal-service-cipher.js +1506 -0
- package/dist/client/signal-service-cipher.js.map +1 -0
- package/dist/client/state.d.ts +147 -0
- package/dist/client/state.d.ts.map +1 -0
- package/dist/client/state.js +226 -0
- package/dist/client/state.js.map +1 -0
- package/dist/client/types.d.ts +423 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +42 -0
- package/dist/client/types.js.map +1 -0
- package/dist/device/connection.d.ts +46 -0
- package/dist/device/connection.d.ts.map +1 -0
- package/dist/device/connection.js +239 -0
- package/dist/device/connection.js.map +1 -0
- package/dist/device/constants.d.ts +69 -0
- package/dist/device/constants.d.ts.map +1 -0
- package/dist/device/constants.js +64 -0
- package/dist/device/constants.js.map +1 -0
- package/dist/device/device-id.d.ts +45 -0
- package/dist/device/device-id.d.ts.map +1 -0
- package/dist/device/device-id.js +87 -0
- package/dist/device/device-id.js.map +1 -0
- package/dist/device/device-name-crypto.d.ts +39 -0
- package/dist/device/device-name-crypto.d.ts.map +1 -0
- package/dist/device/device-name-crypto.js +165 -0
- package/dist/device/device-name-crypto.js.map +1 -0
- package/dist/device/index.d.ts +31 -0
- package/dist/device/index.d.ts.map +1 -0
- package/dist/device/index.js +35 -0
- package/dist/device/index.js.map +1 -0
- package/dist/device/lifecycle/index.d.ts +25 -0
- package/dist/device/lifecycle/index.d.ts.map +1 -0
- package/dist/device/lifecycle/index.js +3 -0
- package/dist/device/lifecycle/index.js.map +1 -0
- package/dist/device/lifecycle/manager.d.ts +273 -0
- package/dist/device/lifecycle/manager.d.ts.map +1 -0
- package/dist/device/lifecycle/manager.js +1229 -0
- package/dist/device/lifecycle/manager.js.map +1 -0
- package/dist/device/lifecycle/types.d.ts +372 -0
- package/dist/device/lifecycle/types.d.ts.map +1 -0
- package/dist/device/lifecycle/types.js +10 -0
- package/dist/device/lifecycle/types.js.map +1 -0
- package/dist/device/lifecycle/utils.d.ts +37 -0
- package/dist/device/lifecycle/utils.d.ts.map +1 -0
- package/dist/device/lifecycle/utils.js +79 -0
- package/dist/device/lifecycle/utils.js.map +1 -0
- package/dist/device/provisioning.d.ts +249 -0
- package/dist/device/provisioning.d.ts.map +1 -0
- package/dist/device/provisioning.js +439 -0
- package/dist/device/provisioning.js.map +1 -0
- package/dist/device/transfer.d.ts +231 -0
- package/dist/device/transfer.d.ts.map +1 -0
- package/dist/device/transfer.js +628 -0
- package/dist/device/transfer.js.map +1 -0
- package/dist/device/types.d.ts +275 -0
- package/dist/device/types.d.ts.map +1 -0
- package/dist/device/types.js +42 -0
- package/dist/device/types.js.map +1 -0
- package/dist/encoding/base64.d.ts +14 -0
- package/dist/encoding/base64.d.ts.map +1 -0
- package/dist/encoding/base64.js +2 -0
- package/dist/encoding/base64.js.map +1 -0
- package/dist/encoding/hex.d.ts +14 -0
- package/dist/encoding/hex.d.ts.map +1 -0
- package/dist/encoding/hex.js +2 -0
- package/dist/encoding/hex.js.map +1 -0
- package/dist/encoding/index.d.ts +17 -0
- package/dist/encoding/index.d.ts.map +1 -0
- package/dist/encoding/index.js +3 -0
- package/dist/encoding/index.js.map +1 -0
- package/dist/files/index.d.ts +16 -0
- package/dist/files/index.d.ts.map +1 -0
- package/dist/files/index.js +15 -0
- package/dist/files/index.js.map +1 -0
- package/dist/groups/index.d.ts +12 -0
- package/dist/groups/index.d.ts.map +1 -0
- package/dist/groups/index.js +9 -0
- package/dist/groups/index.js.map +1 -0
- package/dist/hooks/index.d.ts +20 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +6 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/use-connection-presence.d.ts +68 -0
- package/dist/hooks/use-connection-presence.d.ts.map +1 -0
- package/dist/hooks/use-connection-presence.js +300 -0
- package/dist/hooks/use-connection-presence.js.map +1 -0
- package/dist/hooks/use-group-membership.d.ts +66 -0
- package/dist/hooks/use-group-membership.d.ts.map +1 -0
- package/dist/hooks/use-group-membership.js +156 -0
- package/dist/hooks/use-group-membership.js.map +1 -0
- package/dist/hooks/use-key-rotation.d.ts +119 -0
- package/dist/hooks/use-key-rotation.d.ts.map +1 -0
- package/dist/hooks/use-key-rotation.js +198 -0
- package/dist/hooks/use-key-rotation.js.map +1 -0
- package/dist/hooks/use-session-health.d.ts +51 -0
- package/dist/hooks/use-session-health.d.ts.map +1 -0
- package/dist/hooks/use-session-health.js +59 -0
- package/dist/hooks/use-session-health.js.map +1 -0
- package/dist/hooks/use-single-flight.d.ts +29 -0
- package/dist/hooks/use-single-flight.d.ts.map +1 -0
- package/dist/hooks/use-single-flight.js +59 -0
- package/dist/hooks/use-single-flight.js.map +1 -0
- package/dist/index.d.ts +203 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +169 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/crypto/ec/ed25519.d.ts +78 -0
- package/dist/internal/crypto/ec/ed25519.d.ts.map +1 -0
- package/dist/internal/crypto/ec/ed25519.js +108 -0
- package/dist/internal/crypto/ec/ed25519.js.map +1 -0
- package/dist/internal/crypto/ec/index.d.ts +5 -0
- package/dist/internal/crypto/ec/index.d.ts.map +1 -0
- package/dist/internal/crypto/ec/index.js +4 -0
- package/dist/internal/crypto/ec/index.js.map +1 -0
- package/dist/internal/crypto/ec/x25519-validation.d.ts +70 -0
- package/dist/internal/crypto/ec/x25519-validation.d.ts.map +1 -0
- package/dist/internal/crypto/ec/x25519-validation.js +137 -0
- package/dist/internal/crypto/ec/x25519-validation.js.map +1 -0
- package/dist/internal/crypto/ec/x25519.d.ts +91 -0
- package/dist/internal/crypto/ec/x25519.d.ts.map +1 -0
- package/dist/internal/crypto/ec/x25519.js +124 -0
- package/dist/internal/crypto/ec/x25519.js.map +1 -0
- package/dist/internal/crypto/hash/index.d.ts +4 -0
- package/dist/internal/crypto/hash/index.d.ts.map +1 -0
- package/dist/internal/crypto/hash/index.js +3 -0
- package/dist/internal/crypto/hash/index.js.map +1 -0
- package/dist/internal/crypto/hash/sha256.d.ts +24 -0
- package/dist/internal/crypto/hash/sha256.d.ts.map +1 -0
- package/dist/internal/crypto/hash/sha256.js +23 -0
- package/dist/internal/crypto/hash/sha256.js.map +1 -0
- package/dist/internal/crypto/hash/sha512.d.ts +16 -0
- package/dist/internal/crypto/hash/sha512.d.ts.map +1 -0
- package/dist/internal/crypto/hash/sha512.js +27 -0
- package/dist/internal/crypto/hash/sha512.js.map +1 -0
- package/dist/internal/crypto/index.d.ts +60 -0
- package/dist/internal/crypto/index.d.ts.map +1 -0
- package/dist/internal/crypto/index.js +107 -0
- package/dist/internal/crypto/index.js.map +1 -0
- package/dist/internal/crypto/kdf/hkdf.d.ts +300 -0
- package/dist/internal/crypto/kdf/hkdf.d.ts.map +1 -0
- package/dist/internal/crypto/kdf/hkdf.js +452 -0
- package/dist/internal/crypto/kdf/hkdf.js.map +1 -0
- package/dist/internal/crypto/kdf/index.d.ts +4 -0
- package/dist/internal/crypto/kdf/index.d.ts.map +1 -0
- package/dist/internal/crypto/kdf/index.js +3 -0
- package/dist/internal/crypto/kdf/index.js.map +1 -0
- package/dist/internal/crypto/kdf/pbkdf2.d.ts +42 -0
- package/dist/internal/crypto/kdf/pbkdf2.d.ts.map +1 -0
- package/dist/internal/crypto/kdf/pbkdf2.js +44 -0
- package/dist/internal/crypto/kdf/pbkdf2.js.map +1 -0
- package/dist/internal/crypto/key-prefix.d.ts +82 -0
- package/dist/internal/crypto/key-prefix.d.ts.map +1 -0
- package/dist/internal/crypto/key-prefix.js +116 -0
- package/dist/internal/crypto/key-prefix.js.map +1 -0
- package/dist/internal/crypto/pq/index.d.ts +3 -0
- package/dist/internal/crypto/pq/index.d.ts.map +1 -0
- package/dist/internal/crypto/pq/index.js +2 -0
- package/dist/internal/crypto/pq/index.js.map +1 -0
- package/dist/internal/crypto/pq/kyber.d.ts +232 -0
- package/dist/internal/crypto/pq/kyber.d.ts.map +1 -0
- package/dist/internal/crypto/pq/kyber.js +317 -0
- package/dist/internal/crypto/pq/kyber.js.map +1 -0
- package/dist/internal/crypto/random.d.ts +22 -0
- package/dist/internal/crypto/random.d.ts.map +1 -0
- package/dist/internal/crypto/random.js +45 -0
- package/dist/internal/crypto/random.js.map +1 -0
- package/dist/internal/crypto/symmetric/aes-ctr.d.ts +73 -0
- package/dist/internal/crypto/symmetric/aes-ctr.d.ts.map +1 -0
- package/dist/internal/crypto/symmetric/aes-ctr.js +98 -0
- package/dist/internal/crypto/symmetric/aes-ctr.js.map +1 -0
- package/dist/internal/crypto/symmetric/aes-gcm-siv.d.ts +77 -0
- package/dist/internal/crypto/symmetric/aes-gcm-siv.d.ts.map +1 -0
- package/dist/internal/crypto/symmetric/aes-gcm-siv.js +111 -0
- package/dist/internal/crypto/symmetric/aes-gcm-siv.js.map +1 -0
- package/dist/internal/crypto/symmetric/aes.d.ts +211 -0
- package/dist/internal/crypto/symmetric/aes.d.ts.map +1 -0
- package/dist/internal/crypto/symmetric/aes.js +386 -0
- package/dist/internal/crypto/symmetric/aes.js.map +1 -0
- package/dist/internal/crypto/symmetric/hmac.d.ts +32 -0
- package/dist/internal/crypto/symmetric/hmac.d.ts.map +1 -0
- package/dist/internal/crypto/symmetric/hmac.js +20 -0
- package/dist/internal/crypto/symmetric/hmac.js.map +1 -0
- package/dist/internal/crypto/symmetric/index.d.ts +9 -0
- package/dist/internal/crypto/symmetric/index.d.ts.map +1 -0
- package/dist/internal/crypto/symmetric/index.js +8 -0
- package/dist/internal/crypto/symmetric/index.js.map +1 -0
- package/dist/internal/crypto/symmetric/mac.d.ts +154 -0
- package/dist/internal/crypto/symmetric/mac.d.ts.map +1 -0
- package/dist/internal/crypto/symmetric/mac.js +292 -0
- package/dist/internal/crypto/symmetric/mac.js.map +1 -0
- package/dist/internal/crypto/symmetric/padding.d.ts +55 -0
- package/dist/internal/crypto/symmetric/padding.d.ts.map +1 -0
- package/dist/internal/crypto/symmetric/padding.js +90 -0
- package/dist/internal/crypto/symmetric/padding.js.map +1 -0
- package/dist/internal/crypto/symmetric/streaming-aead.d.ts +89 -0
- package/dist/internal/crypto/symmetric/streaming-aead.d.ts.map +1 -0
- package/dist/internal/crypto/symmetric/streaming-aead.js +253 -0
- package/dist/internal/crypto/symmetric/streaming-aead.js.map +1 -0
- package/dist/internal/crypto/utils.d.ts +119 -0
- package/dist/internal/crypto/utils.d.ts.map +1 -0
- package/dist/internal/crypto/utils.js +366 -0
- package/dist/internal/crypto/utils.js.map +1 -0
- package/dist/internal/crypto/validation.d.ts +45 -0
- package/dist/internal/crypto/validation.d.ts.map +1 -0
- package/dist/internal/crypto/validation.js +37 -0
- package/dist/internal/crypto/validation.js.map +1 -0
- package/dist/internal/encoding/index.d.ts +2 -0
- package/dist/internal/encoding/index.d.ts.map +1 -0
- package/dist/internal/encoding/index.js +2 -0
- package/dist/internal/encoding/index.js.map +1 -0
- package/dist/internal/encoding/proto/envelope.d.ts +120 -0
- package/dist/internal/encoding/proto/envelope.d.ts.map +1 -0
- package/dist/internal/encoding/proto/envelope.js +160 -0
- package/dist/internal/encoding/proto/envelope.js.map +1 -0
- package/dist/internal/encoding/proto/index.d.ts +25 -0
- package/dist/internal/encoding/proto/index.d.ts.map +1 -0
- package/dist/internal/encoding/proto/index.js +30 -0
- package/dist/internal/encoding/proto/index.js.map +1 -0
- package/dist/internal/encoding/proto/pq-ratchet-serialize.d.ts +118 -0
- package/dist/internal/encoding/proto/pq-ratchet-serialize.d.ts.map +1 -0
- package/dist/internal/encoding/proto/pq-ratchet-serialize.js +383 -0
- package/dist/internal/encoding/proto/pq-ratchet-serialize.js.map +1 -0
- package/dist/internal/encoding/proto/primitives.d.ts +98 -0
- package/dist/internal/encoding/proto/primitives.d.ts.map +1 -0
- package/dist/internal/encoding/proto/primitives.js +179 -0
- package/dist/internal/encoding/proto/primitives.js.map +1 -0
- package/dist/internal/encoding/proto/sender-key-message.d.ts +147 -0
- package/dist/internal/encoding/proto/sender-key-message.d.ts.map +1 -0
- package/dist/internal/encoding/proto/sender-key-message.js +220 -0
- package/dist/internal/encoding/proto/sender-key-message.js.map +1 -0
- package/dist/internal/encoding/proto/signal-message.d.ts +174 -0
- package/dist/internal/encoding/proto/signal-message.d.ts.map +1 -0
- package/dist/internal/encoding/proto/signal-message.js +372 -0
- package/dist/internal/encoding/proto/signal-message.js.map +1 -0
- package/dist/internal/groups/group-id.d.ts +74 -0
- package/dist/internal/groups/group-id.d.ts.map +1 -0
- package/dist/internal/groups/group-id.js +63 -0
- package/dist/internal/groups/group-id.js.map +1 -0
- package/dist/internal/groups/index.d.ts +15 -0
- package/dist/internal/groups/index.d.ts.map +1 -0
- package/dist/internal/groups/index.js +2 -0
- package/dist/internal/groups/index.js.map +1 -0
- package/dist/internal/groups-v2/access-control.d.ts +101 -0
- package/dist/internal/groups-v2/access-control.d.ts.map +1 -0
- package/dist/internal/groups-v2/access-control.js +184 -0
- package/dist/internal/groups-v2/access-control.js.map +1 -0
- package/dist/internal/groups-v2/change-actions.d.ts +35 -0
- package/dist/internal/groups-v2/change-actions.d.ts.map +1 -0
- package/dist/internal/groups-v2/change-actions.js +358 -0
- package/dist/internal/groups-v2/change-actions.js.map +1 -0
- package/dist/internal/groups-v2/encrypted-state.d.ts +121 -0
- package/dist/internal/groups-v2/encrypted-state.d.ts.map +1 -0
- package/dist/internal/groups-v2/encrypted-state.js +455 -0
- package/dist/internal/groups-v2/encrypted-state.js.map +1 -0
- package/dist/internal/groups-v2/index.d.ts +14 -0
- package/dist/internal/groups-v2/index.d.ts.map +1 -0
- package/dist/internal/groups-v2/index.js +11 -0
- package/dist/internal/groups-v2/index.js.map +1 -0
- package/dist/internal/groups-v2/invite-link.d.ts +55 -0
- package/dist/internal/groups-v2/invite-link.d.ts.map +1 -0
- package/dist/internal/groups-v2/invite-link.js +111 -0
- package/dist/internal/groups-v2/invite-link.js.map +1 -0
- package/dist/internal/groups-v2/manager.d.ts +351 -0
- package/dist/internal/groups-v2/manager.d.ts.map +1 -0
- package/dist/internal/groups-v2/manager.js +1093 -0
- package/dist/internal/groups-v2/manager.js.map +1 -0
- package/dist/internal/groups-v2/types.d.ts +371 -0
- package/dist/internal/groups-v2/types.d.ts.map +1 -0
- package/dist/internal/groups-v2/types.js +61 -0
- package/dist/internal/groups-v2/types.js.map +1 -0
- package/dist/internal/manager/index.d.ts +16 -0
- package/dist/internal/manager/index.d.ts.map +1 -0
- package/dist/internal/manager/index.js +2 -0
- package/dist/internal/manager/index.js.map +1 -0
- package/dist/internal/manager/manager.d.ts +378 -0
- package/dist/internal/manager/manager.d.ts.map +1 -0
- package/dist/internal/manager/manager.js +1079 -0
- package/dist/internal/manager/manager.js.map +1 -0
- package/dist/internal/protocol/double-ratchet/chains.d.ts +135 -0
- package/dist/internal/protocol/double-ratchet/chains.d.ts.map +1 -0
- package/dist/internal/protocol/double-ratchet/chains.js +417 -0
- package/dist/internal/protocol/double-ratchet/chains.js.map +1 -0
- package/dist/internal/protocol/double-ratchet/index.d.ts +20 -0
- package/dist/internal/protocol/double-ratchet/index.d.ts.map +1 -0
- package/dist/internal/protocol/double-ratchet/index.js +21 -0
- package/dist/internal/protocol/double-ratchet/index.js.map +1 -0
- package/dist/internal/protocol/double-ratchet/ratchet.d.ts +231 -0
- package/dist/internal/protocol/double-ratchet/ratchet.d.ts.map +1 -0
- package/dist/internal/protocol/double-ratchet/ratchet.js +198 -0
- package/dist/internal/protocol/double-ratchet/ratchet.js.map +1 -0
- package/dist/internal/protocol/index.d.ts +24 -0
- package/dist/internal/protocol/index.d.ts.map +1 -0
- package/dist/internal/protocol/index.js +9 -0
- package/dist/internal/protocol/index.js.map +1 -0
- package/dist/internal/protocol/pqxdh/index.d.ts +19 -0
- package/dist/internal/protocol/pqxdh/index.d.ts.map +1 -0
- package/dist/internal/protocol/pqxdh/index.js +16 -0
- package/dist/internal/protocol/pqxdh/index.js.map +1 -0
- package/dist/internal/protocol/pqxdh/pqxdh.d.ts +141 -0
- package/dist/internal/protocol/pqxdh/pqxdh.d.ts.map +1 -0
- package/dist/internal/protocol/pqxdh/pqxdh.js +399 -0
- package/dist/internal/protocol/pqxdh/pqxdh.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/certificate.d.ts +94 -0
- package/dist/internal/protocol/sealed-sender/certificate.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/certificate.js +254 -0
- package/dist/internal/protocol/sealed-sender/certificate.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/decryption-v2.d.ts +46 -0
- package/dist/internal/protocol/sealed-sender/decryption-v2.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/decryption-v2.js +184 -0
- package/dist/internal/protocol/sealed-sender/decryption-v2.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/decryption.d.ts +59 -0
- package/dist/internal/protocol/sealed-sender/decryption.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/decryption.js +268 -0
- package/dist/internal/protocol/sealed-sender/decryption.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/delivery-token.d.ts +48 -0
- package/dist/internal/protocol/sealed-sender/delivery-token.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/delivery-token.js +71 -0
- package/dist/internal/protocol/sealed-sender/delivery-token.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/encryption-v2.d.ts +56 -0
- package/dist/internal/protocol/sealed-sender/encryption-v2.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/encryption-v2.js +169 -0
- package/dist/internal/protocol/sealed-sender/encryption-v2.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/encryption.d.ts +66 -0
- package/dist/internal/protocol/sealed-sender/encryption.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/encryption.js +174 -0
- package/dist/internal/protocol/sealed-sender/encryption.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/index.d.ts +23 -0
- package/dist/internal/protocol/sealed-sender/index.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/index.js +61 -0
- package/dist/internal/protocol/sealed-sender/index.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/proto/index.d.ts +129 -0
- package/dist/internal/protocol/sealed-sender/proto/index.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/proto/index.js +267 -0
- package/dist/internal/protocol/sealed-sender/proto/index.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/types.d.ts +461 -0
- package/dist/internal/protocol/sealed-sender/types.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/types.js +99 -0
- package/dist/internal/protocol/sealed-sender/types.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/v2-binary.d.ts +124 -0
- package/dist/internal/protocol/sealed-sender/v2-binary.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/v2-binary.js +295 -0
- package/dist/internal/protocol/sealed-sender/v2-binary.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/v2-helpers.d.ts +107 -0
- package/dist/internal/protocol/sealed-sender/v2-helpers.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/v2-helpers.js +185 -0
- package/dist/internal/protocol/sealed-sender/v2-helpers.js.map +1 -0
- package/dist/internal/protocol/sender-keys/index.d.ts +11 -0
- package/dist/internal/protocol/sender-keys/index.d.ts.map +1 -0
- package/dist/internal/protocol/sender-keys/index.js +2 -0
- package/dist/internal/protocol/sender-keys/index.js.map +1 -0
- package/dist/internal/protocol/sender-keys/manager.d.ts +298 -0
- package/dist/internal/protocol/sender-keys/manager.d.ts.map +1 -0
- package/dist/internal/protocol/sender-keys/manager.js +839 -0
- package/dist/internal/protocol/sender-keys/manager.js.map +1 -0
- package/dist/internal/protocol/spqr/braid-serialize.d.ts +128 -0
- package/dist/internal/protocol/spqr/braid-serialize.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/braid-serialize.js +373 -0
- package/dist/internal/protocol/spqr/braid-serialize.js.map +1 -0
- package/dist/internal/protocol/spqr/braid.d.ts +164 -0
- package/dist/internal/protocol/spqr/braid.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/braid.js +305 -0
- package/dist/internal/protocol/spqr/braid.js.map +1 -0
- package/dist/internal/protocol/spqr/index.d.ts +161 -0
- package/dist/internal/protocol/spqr/index.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/index.js +115 -0
- package/dist/internal/protocol/spqr/index.js.map +1 -0
- package/dist/internal/protocol/spqr/message.d.ts +237 -0
- package/dist/internal/protocol/spqr/message.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/message.js +298 -0
- package/dist/internal/protocol/spqr/message.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/authenticator.d.ts +174 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/authenticator.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/authenticator.js +248 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/authenticator.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/chunk-domain.d.ts +29 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/chunk-domain.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/chunk-domain.js +43 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/chunk-domain.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/errors.d.ts +170 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/errors.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/errors.js +249 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/errors.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/incremental-kem.d.ts +84 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/incremental-kem.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/incremental-kem.js +138 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/incremental-kem.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/index.d.ts +45 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/index.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/index.js +94 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/index.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/kdf.d.ts +52 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/kdf.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/kdf.js +121 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/kdf.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/arithmetic.d.ts +12 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/arithmetic.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/arithmetic.js +15 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/arithmetic.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/index.d.ts +136 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/index.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/index.js +796 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/index.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/codec.d.ts +454 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/codec.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/codec.js +790 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/codec.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/galois/field.d.ts +108 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/galois/field.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/galois/field.js +125 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/galois/field.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/galois/index.d.ts +12 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/galois/index.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/galois/index.js +5 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/galois/index.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/galois/tables-16.d.ts +28 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/galois/tables-16.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/galois/tables-16.js +13953 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/galois/tables-16.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/index.d.ts +40 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/index.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/index.js +52 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/index.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/lagrange.d.ts +151 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/lagrange.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/lagrange.js +297 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/lagrange.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/polynomial.d.ts +97 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/polynomial.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/polynomial.js +201 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/polynomial.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/serialize.d.ts +249 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/serialize.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/serialize.js +731 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/serialize.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/state-machine.d.ts +127 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/state-machine.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/state-machine.js +894 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/state-machine.js.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/types.d.ts +387 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/types.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/types.js +121 -0
- package/dist/internal/protocol/spqr/ml-kem-braid/types.js.map +1 -0
- package/dist/internal/protocol/spqr/serialize.d.ts +149 -0
- package/dist/internal/protocol/spqr/serialize.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/serialize.js +370 -0
- package/dist/internal/protocol/spqr/serialize.js.map +1 -0
- package/dist/internal/protocol/spqr/spqr.d.ts +486 -0
- package/dist/internal/protocol/spqr/spqr.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/spqr.js +1031 -0
- package/dist/internal/protocol/spqr/spqr.js.map +1 -0
- package/dist/internal/protocol/spqr/validate.d.ts +35 -0
- package/dist/internal/protocol/spqr/validate.d.ts.map +1 -0
- package/dist/internal/protocol/spqr/validate.js +62 -0
- package/dist/internal/protocol/spqr/validate.js.map +1 -0
- package/dist/internal/protocol/triple-ratchet/index.d.ts +21 -0
- package/dist/internal/protocol/triple-ratchet/index.d.ts.map +1 -0
- package/dist/internal/protocol/triple-ratchet/index.js +19 -0
- package/dist/internal/protocol/triple-ratchet/index.js.map +1 -0
- package/dist/internal/protocol/triple-ratchet/ratchet.d.ts +233 -0
- package/dist/internal/protocol/triple-ratchet/ratchet.d.ts.map +1 -0
- package/dist/internal/protocol/triple-ratchet/ratchet.js +254 -0
- package/dist/internal/protocol/triple-ratchet/ratchet.js.map +1 -0
- package/dist/internal/protocol/username/generate.d.ts +9 -0
- package/dist/internal/protocol/username/generate.d.ts.map +1 -0
- package/dist/internal/protocol/username/generate.js +16 -0
- package/dist/internal/protocol/username/generate.js.map +1 -0
- package/dist/internal/protocol/username/hash.d.ts +74 -0
- package/dist/internal/protocol/username/hash.d.ts.map +1 -0
- package/dist/internal/protocol/username/hash.js +228 -0
- package/dist/internal/protocol/username/hash.js.map +1 -0
- package/dist/internal/protocol/username/link.d.ts +50 -0
- package/dist/internal/protocol/username/link.d.ts.map +1 -0
- package/dist/internal/protocol/username/link.js +187 -0
- package/dist/internal/protocol/username/link.js.map +1 -0
- package/dist/internal/protocol/username/proof.d.ts +34 -0
- package/dist/internal/protocol/username/proof.d.ts.map +1 -0
- package/dist/internal/protocol/username/proof.js +83 -0
- package/dist/internal/protocol/username/proof.js.map +1 -0
- package/dist/internal/protocol/version.d.ts +184 -0
- package/dist/internal/protocol/version.d.ts.map +1 -0
- package/dist/internal/protocol/version.js +163 -0
- package/dist/internal/protocol/version.js.map +1 -0
- package/dist/internal/protocol/x3dh/index.d.ts +15 -0
- package/dist/internal/protocol/x3dh/index.d.ts.map +1 -0
- package/dist/internal/protocol/x3dh/index.js +13 -0
- package/dist/internal/protocol/x3dh/index.js.map +1 -0
- package/dist/internal/protocol/x3dh/x3dh.d.ts +131 -0
- package/dist/internal/protocol/x3dh/x3dh.d.ts.map +1 -0
- package/dist/internal/protocol/x3dh/x3dh.js +261 -0
- package/dist/internal/protocol/x3dh/x3dh.js.map +1 -0
- package/dist/internal/protocol/zk/credentials/attributes.d.ts +157 -0
- package/dist/internal/protocol/zk/credentials/attributes.d.ts.map +1 -0
- package/dist/internal/protocol/zk/credentials/attributes.js +177 -0
- package/dist/internal/protocol/zk/credentials/attributes.js.map +1 -0
- package/dist/internal/protocol/zk/credentials/credentials.d.ts +129 -0
- package/dist/internal/protocol/zk/credentials/credentials.d.ts.map +1 -0
- package/dist/internal/protocol/zk/credentials/credentials.js +204 -0
- package/dist/internal/protocol/zk/credentials/credentials.js.map +1 -0
- package/dist/internal/protocol/zk/credentials/endorsements.d.ts +235 -0
- package/dist/internal/protocol/zk/credentials/endorsements.d.ts.map +1 -0
- package/dist/internal/protocol/zk/credentials/endorsements.js +520 -0
- package/dist/internal/protocol/zk/credentials/endorsements.js.map +1 -0
- package/dist/internal/protocol/zk/credentials/index.d.ts +14 -0
- package/dist/internal/protocol/zk/credentials/index.d.ts.map +1 -0
- package/dist/internal/protocol/zk/credentials/index.js +6 -0
- package/dist/internal/protocol/zk/credentials/index.js.map +1 -0
- package/dist/internal/protocol/zk/credentials/issuance.d.ts +135 -0
- package/dist/internal/protocol/zk/credentials/issuance.d.ts.map +1 -0
- package/dist/internal/protocol/zk/credentials/issuance.js +338 -0
- package/dist/internal/protocol/zk/credentials/issuance.js.map +1 -0
- package/dist/internal/protocol/zk/credentials/presentation.d.ts +160 -0
- package/dist/internal/protocol/zk/credentials/presentation.d.ts.map +1 -0
- package/dist/internal/protocol/zk/credentials/presentation.js +447 -0
- package/dist/internal/protocol/zk/credentials/presentation.js.map +1 -0
- package/dist/internal/protocol/zk/groups/auth-credential.d.ts +191 -0
- package/dist/internal/protocol/zk/groups/auth-credential.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/auth-credential.js +377 -0
- package/dist/internal/protocol/zk/groups/auth-credential.js.map +1 -0
- package/dist/internal/protocol/zk/groups/client-zk-group-cipher.d.ts +73 -0
- package/dist/internal/protocol/zk/groups/client-zk-group-cipher.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/client-zk-group-cipher.js +140 -0
- package/dist/internal/protocol/zk/groups/client-zk-group-cipher.js.map +1 -0
- package/dist/internal/protocol/zk/groups/group-params.d.ts +93 -0
- package/dist/internal/protocol/zk/groups/group-params.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/group-params.js +184 -0
- package/dist/internal/protocol/zk/groups/group-params.js.map +1 -0
- package/dist/internal/protocol/zk/groups/group-send-endorsement.d.ts +245 -0
- package/dist/internal/protocol/zk/groups/group-send-endorsement.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/group-send-endorsement.js +404 -0
- package/dist/internal/protocol/zk/groups/group-send-endorsement.js.map +1 -0
- package/dist/internal/protocol/zk/groups/index.d.ts +19 -0
- package/dist/internal/protocol/zk/groups/index.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/index.js +12 -0
- package/dist/internal/protocol/zk/groups/index.js.map +1 -0
- package/dist/internal/protocol/zk/groups/lizard.d.ts +51 -0
- package/dist/internal/protocol/zk/groups/lizard.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/lizard.js +478 -0
- package/dist/internal/protocol/zk/groups/lizard.js.map +1 -0
- package/dist/internal/protocol/zk/groups/profile-key-commitment.d.ts +35 -0
- package/dist/internal/protocol/zk/groups/profile-key-commitment.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/profile-key-commitment.js +99 -0
- package/dist/internal/protocol/zk/groups/profile-key-commitment.js.map +1 -0
- package/dist/internal/protocol/zk/groups/profile-key-credential.d.ts +195 -0
- package/dist/internal/protocol/zk/groups/profile-key-credential.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/profile-key-credential.js +370 -0
- package/dist/internal/protocol/zk/groups/profile-key-credential.js.map +1 -0
- package/dist/internal/protocol/zk/groups/profile-key-encryption.d.ts +45 -0
- package/dist/internal/protocol/zk/groups/profile-key-encryption.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/profile-key-encryption.js +125 -0
- package/dist/internal/protocol/zk/groups/profile-key-encryption.js.map +1 -0
- package/dist/internal/protocol/zk/groups/profile-key-struct.d.ts +33 -0
- package/dist/internal/protocol/zk/groups/profile-key-struct.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/profile-key-struct.js +62 -0
- package/dist/internal/protocol/zk/groups/profile-key-struct.js.map +1 -0
- package/dist/internal/protocol/zk/groups/profile-key-version.d.ts +17 -0
- package/dist/internal/protocol/zk/groups/profile-key-version.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/profile-key-version.js +33 -0
- package/dist/internal/protocol/zk/groups/profile-key-version.js.map +1 -0
- package/dist/internal/protocol/zk/groups/server-params.d.ts +114 -0
- package/dist/internal/protocol/zk/groups/server-params.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/server-params.js +146 -0
- package/dist/internal/protocol/zk/groups/server-params.js.map +1 -0
- package/dist/internal/protocol/zk/groups/uid-encryption.d.ts +41 -0
- package/dist/internal/protocol/zk/groups/uid-encryption.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/uid-encryption.js +113 -0
- package/dist/internal/protocol/zk/groups/uid-encryption.js.map +1 -0
- package/dist/internal/protocol/zk/groups/uid-struct.d.ts +48 -0
- package/dist/internal/protocol/zk/groups/uid-struct.d.ts.map +1 -0
- package/dist/internal/protocol/zk/groups/uid-struct.js +77 -0
- package/dist/internal/protocol/zk/groups/uid-struct.js.map +1 -0
- package/dist/internal/protocol/zk/proofs/args.d.ts +33 -0
- package/dist/internal/protocol/zk/proofs/args.d.ts.map +1 -0
- package/dist/internal/protocol/zk/proofs/args.js +43 -0
- package/dist/internal/protocol/zk/proofs/args.js.map +1 -0
- package/dist/internal/protocol/zk/proofs/index.d.ts +13 -0
- package/dist/internal/protocol/zk/proofs/index.d.ts.map +1 -0
- package/dist/internal/protocol/zk/proofs/index.js +7 -0
- package/dist/internal/protocol/zk/proofs/index.js.map +1 -0
- package/dist/internal/protocol/zk/proofs/proof.d.ts +30 -0
- package/dist/internal/protocol/zk/proofs/proof.d.ts.map +1 -0
- package/dist/internal/protocol/zk/proofs/proof.js +48 -0
- package/dist/internal/protocol/zk/proofs/proof.js.map +1 -0
- package/dist/internal/protocol/zk/proofs/sho-sha256.d.ts +34 -0
- package/dist/internal/protocol/zk/proofs/sho-sha256.d.ts.map +1 -0
- package/dist/internal/protocol/zk/proofs/sho-sha256.js +138 -0
- package/dist/internal/protocol/zk/proofs/sho-sha256.js.map +1 -0
- package/dist/internal/protocol/zk/proofs/sho.d.ts +120 -0
- package/dist/internal/protocol/zk/proofs/sho.d.ts.map +1 -0
- package/dist/internal/protocol/zk/proofs/sho.js +221 -0
- package/dist/internal/protocol/zk/proofs/sho.js.map +1 -0
- package/dist/internal/protocol/zk/proofs/sign.d.ts +29 -0
- package/dist/internal/protocol/zk/proofs/sign.d.ts.map +1 -0
- package/dist/internal/protocol/zk/proofs/sign.js +34 -0
- package/dist/internal/protocol/zk/proofs/sign.js.map +1 -0
- package/dist/internal/protocol/zk/proofs/statement.d.ts +103 -0
- package/dist/internal/protocol/zk/proofs/statement.d.ts.map +1 -0
- package/dist/internal/protocol/zk/proofs/statement.js +282 -0
- package/dist/internal/protocol/zk/proofs/statement.js.map +1 -0
- package/dist/internal/sesame/device-registry.d.ts +208 -0
- package/dist/internal/sesame/device-registry.d.ts.map +1 -0
- package/dist/internal/sesame/device-registry.js +431 -0
- package/dist/internal/sesame/device-registry.js.map +1 -0
- package/dist/internal/sesame/index.d.ts +31 -0
- package/dist/internal/sesame/index.d.ts.map +1 -0
- package/dist/internal/sesame/index.js +40 -0
- package/dist/internal/sesame/index.js.map +1 -0
- package/dist/internal/sesame/manager.d.ts +351 -0
- package/dist/internal/sesame/manager.d.ts.map +1 -0
- package/dist/internal/sesame/manager.js +1760 -0
- package/dist/internal/sesame/manager.js.map +1 -0
- package/dist/internal/sesame/types.d.ts +840 -0
- package/dist/internal/sesame/types.d.ts.map +1 -0
- package/dist/internal/sesame/types.js +290 -0
- package/dist/internal/sesame/types.js.map +1 -0
- package/dist/internal/sesame/validation.d.ts +72 -0
- package/dist/internal/sesame/validation.d.ts.map +1 -0
- package/dist/internal/sesame/validation.js +136 -0
- package/dist/internal/sesame/validation.js.map +1 -0
- package/dist/internal/session/builder.d.ts +94 -0
- package/dist/internal/session/builder.d.ts.map +1 -0
- package/dist/internal/session/builder.js +266 -0
- package/dist/internal/session/builder.js.map +1 -0
- package/dist/internal/session/cipher.d.ts +256 -0
- package/dist/internal/session/cipher.d.ts.map +1 -0
- package/dist/internal/session/cipher.js +1222 -0
- package/dist/internal/session/cipher.js.map +1 -0
- package/dist/internal/session/decryption.d.ts +37 -0
- package/dist/internal/session/decryption.d.ts.map +1 -0
- package/dist/internal/session/decryption.js +256 -0
- package/dist/internal/session/decryption.js.map +1 -0
- package/dist/internal/session/factory.d.ts +161 -0
- package/dist/internal/session/factory.d.ts.map +1 -0
- package/dist/internal/session/factory.js +211 -0
- package/dist/internal/session/factory.js.map +1 -0
- package/dist/internal/session/handshake.d.ts +72 -0
- package/dist/internal/session/handshake.d.ts.map +1 -0
- package/dist/internal/session/handshake.js +343 -0
- package/dist/internal/session/handshake.js.map +1 -0
- package/dist/internal/session/identity-binding.d.ts +5 -0
- package/dist/internal/session/identity-binding.d.ts.map +1 -0
- package/dist/internal/session/identity-binding.js +15 -0
- package/dist/internal/session/identity-binding.js.map +1 -0
- package/dist/internal/session/index.d.ts +73 -0
- package/dist/internal/session/index.d.ts.map +1 -0
- package/dist/internal/session/index.js +75 -0
- package/dist/internal/session/index.js.map +1 -0
- package/dist/internal/session/keys.d.ts +220 -0
- package/dist/internal/session/keys.d.ts.map +1 -0
- package/dist/internal/session/keys.js +78 -0
- package/dist/internal/session/keys.js.map +1 -0
- package/dist/internal/session/ratchet.d.ts +97 -0
- package/dist/internal/session/ratchet.d.ts.map +1 -0
- package/dist/internal/session/ratchet.js +187 -0
- package/dist/internal/session/ratchet.js.map +1 -0
- package/dist/internal/session/session-resolver.d.ts +138 -0
- package/dist/internal/session/session-resolver.d.ts.map +1 -0
- package/dist/internal/session/session-resolver.js +190 -0
- package/dist/internal/session/session-resolver.js.map +1 -0
- package/dist/internal/session/state.d.ts +278 -0
- package/dist/internal/session/state.d.ts.map +1 -0
- package/dist/internal/session/state.js +167 -0
- package/dist/internal/session/state.js.map +1 -0
- package/dist/internal/session/types.d.ts +192 -0
- package/dist/internal/session/types.d.ts.map +1 -0
- package/dist/internal/session/types.js +16 -0
- package/dist/internal/session/types.js.map +1 -0
- package/dist/internal/session/validation.d.ts +145 -0
- package/dist/internal/session/validation.d.ts.map +1 -0
- package/dist/internal/session/validation.js +340 -0
- package/dist/internal/session/validation.js.map +1 -0
- package/dist/keys/branded.d.ts +85 -0
- package/dist/keys/branded.d.ts.map +1 -0
- package/dist/keys/branded.js +26 -0
- package/dist/keys/branded.js.map +1 -0
- package/dist/keys/generation.d.ts +101 -0
- package/dist/keys/generation.d.ts.map +1 -0
- package/dist/keys/generation.js +181 -0
- package/dist/keys/generation.js.map +1 -0
- package/dist/keys/identity.d.ts +27 -0
- package/dist/keys/identity.d.ts.map +1 -0
- package/dist/keys/identity.js +200 -0
- package/dist/keys/identity.js.map +1 -0
- package/dist/keys/index.d.ts +24 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +22 -0
- package/dist/keys/index.js.map +1 -0
- package/dist/keys/prekey-signature.d.ts +13 -0
- package/dist/keys/prekey-signature.d.ts.map +1 -0
- package/dist/keys/prekey-signature.js +46 -0
- package/dist/keys/prekey-signature.js.map +1 -0
- package/dist/keys/types.d.ts +255 -0
- package/dist/keys/types.d.ts.map +1 -0
- package/dist/keys/types.js +11 -0
- package/dist/keys/types.js.map +1 -0
- package/dist/layers.d.ts +228 -0
- package/dist/layers.d.ts.map +1 -0
- package/dist/layers.js +328 -0
- package/dist/layers.js.map +1 -0
- package/dist/local/store/expo/adapter.d.ts +243 -0
- package/dist/local/store/expo/adapter.d.ts.map +1 -0
- package/dist/local/store/expo/adapter.js +619 -0
- package/dist/local/store/expo/adapter.js.map +1 -0
- package/dist/local/store/expo/database-key.d.ts +142 -0
- package/dist/local/store/expo/database-key.d.ts.map +1 -0
- package/dist/local/store/expo/database-key.js +312 -0
- package/dist/local/store/expo/database-key.js.map +1 -0
- package/dist/local/store/expo/db.d.ts +92 -0
- package/dist/local/store/expo/db.d.ts.map +1 -0
- package/dist/local/store/expo/db.js +142 -0
- package/dist/local/store/expo/db.js.map +1 -0
- package/dist/local/store/expo/index.d.ts +22 -0
- package/dist/local/store/expo/index.d.ts.map +1 -0
- package/dist/local/store/expo/index.js +10 -0
- package/dist/local/store/expo/index.js.map +1 -0
- package/dist/local/store/expo/key-storage.d.ts +422 -0
- package/dist/local/store/expo/key-storage.d.ts.map +1 -0
- package/dist/local/store/expo/key-storage.js +1292 -0
- package/dist/local/store/expo/key-storage.js.map +1 -0
- package/dist/local/store/expo/maintenance.d.ts +4 -0
- package/dist/local/store/expo/maintenance.d.ts.map +1 -0
- package/dist/local/store/expo/maintenance.js +36 -0
- package/dist/local/store/expo/maintenance.js.map +1 -0
- package/dist/local/store/expo/models/ec-one-time-prekey.d.ts +155 -0
- package/dist/local/store/expo/models/ec-one-time-prekey.d.ts.map +1 -0
- package/dist/local/store/expo/models/ec-one-time-prekey.js +309 -0
- package/dist/local/store/expo/models/ec-one-time-prekey.js.map +1 -0
- package/dist/local/store/expo/models/ec-signed-prekey.d.ts +189 -0
- package/dist/local/store/expo/models/ec-signed-prekey.d.ts.map +1 -0
- package/dist/local/store/expo/models/ec-signed-prekey.js +359 -0
- package/dist/local/store/expo/models/ec-signed-prekey.js.map +1 -0
- package/dist/local/store/expo/models/identity-key-id.d.ts +9 -0
- package/dist/local/store/expo/models/identity-key-id.d.ts.map +1 -0
- package/dist/local/store/expo/models/identity-key-id.js +10 -0
- package/dist/local/store/expo/models/identity-key-id.js.map +1 -0
- package/dist/local/store/expo/models/index.d.ts +20 -0
- package/dist/local/store/expo/models/index.d.ts.map +1 -0
- package/dist/local/store/expo/models/index.js +80 -0
- package/dist/local/store/expo/models/index.js.map +1 -0
- package/dist/local/store/expo/models/kyber-one-time-prekey.d.ts +183 -0
- package/dist/local/store/expo/models/kyber-one-time-prekey.d.ts.map +1 -0
- package/dist/local/store/expo/models/kyber-one-time-prekey.js +353 -0
- package/dist/local/store/expo/models/kyber-one-time-prekey.js.map +1 -0
- package/dist/local/store/expo/models/kyber-prekey-used.d.ts +37 -0
- package/dist/local/store/expo/models/kyber-prekey-used.d.ts.map +1 -0
- package/dist/local/store/expo/models/kyber-prekey-used.js +59 -0
- package/dist/local/store/expo/models/kyber-prekey-used.js.map +1 -0
- package/dist/local/store/expo/models/kyber-prekey.d.ts +172 -0
- package/dist/local/store/expo/models/kyber-prekey.d.ts.map +1 -0
- package/dist/local/store/expo/models/kyber-prekey.js +314 -0
- package/dist/local/store/expo/models/kyber-prekey.js.map +1 -0
- package/dist/local/store/expo/models/local-identity.d.ts +52 -0
- package/dist/local/store/expo/models/local-identity.d.ts.map +1 -0
- package/dist/local/store/expo/models/local-identity.js +166 -0
- package/dist/local/store/expo/models/local-identity.js.map +1 -0
- package/dist/local/store/expo/models/message-record.d.ts +198 -0
- package/dist/local/store/expo/models/message-record.d.ts.map +1 -0
- package/dist/local/store/expo/models/message-record.js +298 -0
- package/dist/local/store/expo/models/message-record.js.map +1 -0
- package/dist/local/store/expo/models/recipient-identity.d.ts +21 -0
- package/dist/local/store/expo/models/recipient-identity.d.ts.map +1 -0
- package/dist/local/store/expo/models/recipient-identity.js +66 -0
- package/dist/local/store/expo/models/recipient-identity.js.map +1 -0
- package/dist/local/store/expo/models/replaced-prekey-utils.d.ts +33 -0
- package/dist/local/store/expo/models/replaced-prekey-utils.d.ts.map +1 -0
- package/dist/local/store/expo/models/replaced-prekey-utils.js +54 -0
- package/dist/local/store/expo/models/replaced-prekey-utils.js.map +1 -0
- package/dist/local/store/expo/models/sender-key.d.ts +210 -0
- package/dist/local/store/expo/models/sender-key.d.ts.map +1 -0
- package/dist/local/store/expo/models/sender-key.js +379 -0
- package/dist/local/store/expo/models/sender-key.js.map +1 -0
- package/dist/local/store/expo/models/session.d.ts +175 -0
- package/dist/local/store/expo/models/session.d.ts.map +1 -0
- package/dist/local/store/expo/models/session.js +496 -0
- package/dist/local/store/expo/models/session.js.map +1 -0
- package/dist/local/store/expo/schema.d.ts +1734 -0
- package/dist/local/store/expo/schema.d.ts.map +1 -0
- package/dist/local/store/expo/schema.js +155 -0
- package/dist/local/store/expo/schema.js.map +1 -0
- package/dist/local/store/expo/secure-store-options.d.ts +10 -0
- package/dist/local/store/expo/secure-store-options.d.ts.map +1 -0
- package/dist/local/store/expo/secure-store-options.js +5 -0
- package/dist/local/store/expo/secure-store-options.js.map +1 -0
- package/dist/local/store/index.d.ts +41 -0
- package/dist/local/store/index.d.ts.map +1 -0
- package/dist/local/store/index.js +34 -0
- package/dist/local/store/index.js.map +1 -0
- package/dist/local/store/mock/adapter.d.ts +185 -0
- package/dist/local/store/mock/adapter.d.ts.map +1 -0
- package/dist/local/store/mock/adapter.js +875 -0
- package/dist/local/store/mock/adapter.js.map +1 -0
- package/dist/local/store/mock/index.d.ts +10 -0
- package/dist/local/store/mock/index.d.ts.map +1 -0
- package/dist/local/store/mock/index.js +6 -0
- package/dist/local/store/mock/index.js.map +1 -0
- package/dist/local/store/node/adapter.d.ts +85 -0
- package/dist/local/store/node/adapter.d.ts.map +1 -0
- package/dist/local/store/node/adapter.js +274 -0
- package/dist/local/store/node/adapter.js.map +1 -0
- package/dist/local/store/node/database-encryption.d.ts +109 -0
- package/dist/local/store/node/database-encryption.d.ts.map +1 -0
- package/dist/local/store/node/database-encryption.js +202 -0
- package/dist/local/store/node/database-encryption.js.map +1 -0
- package/dist/local/store/node/database-key.d.ts +124 -0
- package/dist/local/store/node/database-key.d.ts.map +1 -0
- package/dist/local/store/node/database-key.js +264 -0
- package/dist/local/store/node/database-key.js.map +1 -0
- package/dist/local/store/node/database.d.ts +156 -0
- package/dist/local/store/node/database.d.ts.map +1 -0
- package/dist/local/store/node/database.js +630 -0
- package/dist/local/store/node/database.js.map +1 -0
- package/dist/local/store/node/index.d.ts +11 -0
- package/dist/local/store/node/index.d.ts.map +1 -0
- package/dist/local/store/node/index.js +8 -0
- package/dist/local/store/node/index.js.map +1 -0
- package/dist/local/store/react-native/adapter.d.ts +240 -0
- package/dist/local/store/react-native/adapter.d.ts.map +1 -0
- package/dist/local/store/react-native/adapter.js +1108 -0
- package/dist/local/store/react-native/adapter.js.map +1 -0
- package/dist/local/store/react-native/index.d.ts +19 -0
- package/dist/local/store/react-native/index.d.ts.map +1 -0
- package/dist/local/store/react-native/index.js +6 -0
- package/dist/local/store/react-native/index.js.map +1 -0
- package/dist/local/store/react-native/storage.d.ts +39 -0
- package/dist/local/store/react-native/storage.d.ts.map +1 -0
- package/dist/local/store/react-native/storage.js +2 -0
- package/dist/local/store/react-native/storage.js.map +1 -0
- package/dist/local/store/session-codec.d.ts +5 -0
- package/dist/local/store/session-codec.d.ts.map +1 -0
- package/dist/local/store/session-codec.js +42 -0
- package/dist/local/store/session-codec.js.map +1 -0
- package/dist/local/store/web/adapter.d.ts +190 -0
- package/dist/local/store/web/adapter.d.ts.map +1 -0
- package/dist/local/store/web/adapter.js +1188 -0
- package/dist/local/store/web/adapter.js.map +1 -0
- package/dist/local/store/web/index.d.ts +11 -0
- package/dist/local/store/web/index.d.ts.map +1 -0
- package/dist/local/store/web/index.js +8 -0
- package/dist/local/store/web/index.js.map +1 -0
- package/dist/local/vault/expo-secure-store.d.ts +10 -0
- package/dist/local/vault/expo-secure-store.d.ts.map +1 -0
- package/dist/local/vault/expo-secure-store.js +23 -0
- package/dist/local/vault/expo-secure-store.js.map +1 -0
- package/dist/local/vault/index.d.ts +7 -0
- package/dist/local/vault/index.d.ts.map +1 -0
- package/dist/local/vault/index.js +2 -0
- package/dist/local/vault/index.js.map +1 -0
- package/dist/logger.d.ts +18 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +71 -0
- package/dist/logger.js.map +1 -0
- package/dist/media/index.d.ts +524 -0
- package/dist/media/index.d.ts.map +1 -0
- package/dist/media/index.js +2053 -0
- package/dist/media/index.js.map +1 -0
- package/dist/profile/cipher.d.ts +125 -0
- package/dist/profile/cipher.d.ts.map +1 -0
- package/dist/profile/cipher.js +197 -0
- package/dist/profile/cipher.js.map +1 -0
- package/dist/profile/contact-state.d.ts +33 -0
- package/dist/profile/contact-state.d.ts.map +1 -0
- package/dist/profile/contact-state.js +77 -0
- package/dist/profile/contact-state.js.map +1 -0
- package/dist/profile/crypto.d.ts +65 -0
- package/dist/profile/crypto.d.ts.map +1 -0
- package/dist/profile/crypto.js +93 -0
- package/dist/profile/crypto.js.map +1 -0
- package/dist/profile/index.d.ts +26 -0
- package/dist/profile/index.d.ts.map +1 -0
- package/dist/profile/index.js +30 -0
- package/dist/profile/index.js.map +1 -0
- package/dist/profile/profile-key.d.ts +102 -0
- package/dist/profile/profile-key.d.ts.map +1 -0
- package/dist/profile/profile-key.js +229 -0
- package/dist/profile/profile-key.js.map +1 -0
- package/dist/profile/storage.d.ts +61 -0
- package/dist/profile/storage.d.ts.map +1 -0
- package/dist/profile/storage.js +145 -0
- package/dist/profile/storage.js.map +1 -0
- package/dist/profile/update-service.d.ts +53 -0
- package/dist/profile/update-service.d.ts.map +1 -0
- package/dist/profile/update-service.js +67 -0
- package/dist/profile/update-service.js.map +1 -0
- package/dist/remote/object-store/convex-r2/index.d.ts +11 -0
- package/dist/remote/object-store/convex-r2/index.d.ts.map +1 -0
- package/dist/remote/object-store/convex-r2/index.js +13 -0
- package/dist/remote/object-store/convex-r2/index.js.map +1 -0
- package/dist/remote/object-store/convex-r2/server/index.d.ts +2 -0
- package/dist/remote/object-store/convex-r2/server/index.d.ts.map +1 -0
- package/dist/remote/object-store/convex-r2/server/index.js +2 -0
- package/dist/remote/object-store/convex-r2/server/index.js.map +1 -0
- package/dist/remote/object-store/convex-r2/server.d.ts +126 -0
- package/dist/remote/object-store/convex-r2/server.d.ts.map +1 -0
- package/dist/remote/object-store/convex-r2/server.js +232 -0
- package/dist/remote/object-store/convex-r2/server.js.map +1 -0
- package/dist/remote/object-store/convex-r2/storage.d.ts +47 -0
- package/dist/remote/object-store/convex-r2/storage.d.ts.map +1 -0
- package/dist/remote/object-store/convex-r2/storage.js +55 -0
- package/dist/remote/object-store/convex-r2/storage.js.map +1 -0
- package/dist/remote/object-store/index.d.ts +8 -0
- package/dist/remote/object-store/index.d.ts.map +1 -0
- package/dist/remote/object-store/index.js +2 -0
- package/dist/remote/object-store/index.js.map +1 -0
- package/dist/remote/object-store/s3/index.d.ts +8 -0
- package/dist/remote/object-store/s3/index.d.ts.map +1 -0
- package/dist/remote/object-store/s3/index.js +10 -0
- package/dist/remote/object-store/s3/index.js.map +1 -0
- package/dist/remote/object-store/s3/storage.d.ts +44 -0
- package/dist/remote/object-store/s3/storage.d.ts.map +1 -0
- package/dist/remote/object-store/s3/storage.js +41 -0
- package/dist/remote/object-store/s3/storage.js.map +1 -0
- package/dist/remote/object-store/types.d.ts +80 -0
- package/dist/remote/object-store/types.d.ts.map +1 -0
- package/dist/remote/object-store/types.js +2 -0
- package/dist/remote/object-store/types.js.map +1 -0
- package/dist/remote/object-store/validation.d.ts +6 -0
- package/dist/remote/object-store/validation.d.ts.map +1 -0
- package/dist/remote/object-store/validation.js +93 -0
- package/dist/remote/object-store/validation.js.map +1 -0
- package/dist/remote/relay/convex/group-server.d.ts +118 -0
- package/dist/remote/relay/convex/group-server.d.ts.map +1 -0
- package/dist/remote/relay/convex/group-server.js +150 -0
- package/dist/remote/relay/convex/group-server.js.map +1 -0
- package/dist/remote/relay/convex/index.d.ts +39 -0
- package/dist/remote/relay/convex/index.d.ts.map +1 -0
- package/dist/remote/relay/convex/index.js +36 -0
- package/dist/remote/relay/convex/index.js.map +1 -0
- package/dist/remote/relay/convex/relay.d.ts +339 -0
- package/dist/remote/relay/convex/relay.d.ts.map +1 -0
- package/dist/remote/relay/convex/relay.js +1086 -0
- package/dist/remote/relay/convex/relay.js.map +1 -0
- package/dist/remote/relay/convex/types.d.ts +111 -0
- package/dist/remote/relay/convex/types.d.ts.map +1 -0
- package/dist/remote/relay/convex/types.js +19 -0
- package/dist/remote/relay/convex/types.js.map +1 -0
- package/dist/remote/relay/index.d.ts +34 -0
- package/dist/remote/relay/index.d.ts.map +1 -0
- package/dist/remote/relay/index.js +28 -0
- package/dist/remote/relay/index.js.map +1 -0
- package/dist/remote/relay/mock/adapter.d.ts +237 -0
- package/dist/remote/relay/mock/adapter.d.ts.map +1 -0
- package/dist/remote/relay/mock/adapter.js +939 -0
- package/dist/remote/relay/mock/adapter.js.map +1 -0
- package/dist/remote/relay/mock/index.d.ts +10 -0
- package/dist/remote/relay/mock/index.d.ts.map +1 -0
- package/dist/remote/relay/mock/index.js +6 -0
- package/dist/remote/relay/mock/index.js.map +1 -0
- package/dist/remote/relay/types.d.ts +756 -0
- package/dist/remote/relay/types.d.ts.map +1 -0
- package/dist/remote/relay/types.js +11 -0
- package/dist/remote/relay/types.js.map +1 -0
- package/dist/safety/core.d.ts +108 -0
- package/dist/safety/core.d.ts.map +1 -0
- package/dist/safety/core.js +299 -0
- package/dist/safety/core.js.map +1 -0
- package/dist/safety/fingerprint.d.ts +277 -0
- package/dist/safety/fingerprint.d.ts.map +1 -0
- package/dist/safety/fingerprint.js +339 -0
- package/dist/safety/fingerprint.js.map +1 -0
- package/dist/safety/index.d.ts +141 -0
- package/dist/safety/index.d.ts.map +1 -0
- package/dist/safety/index.js +230 -0
- package/dist/safety/index.js.map +1 -0
- package/dist/safety/protobuf.d.ts +34 -0
- package/dist/safety/protobuf.d.ts.map +1 -0
- package/dist/safety/protobuf.js +142 -0
- package/dist/safety/protobuf.js.map +1 -0
- package/dist/safety/url.d.ts +133 -0
- package/dist/safety/url.d.ts.map +1 -0
- package/dist/safety/url.js +242 -0
- package/dist/safety/url.js.map +1 -0
- package/dist/sealed-sender/index.d.ts +7 -0
- package/dist/sealed-sender/index.d.ts.map +1 -0
- package/dist/sealed-sender/index.js +6 -0
- package/dist/sealed-sender/index.js.map +1 -0
- package/dist/server-clock.d.ts +10 -0
- package/dist/server-clock.d.ts.map +1 -0
- package/dist/server-clock.js +27 -0
- package/dist/server-clock.js.map +1 -0
- package/dist/types/address.d.ts +171 -0
- package/dist/types/address.d.ts.map +1 -0
- package/dist/types/address.js +241 -0
- package/dist/types/address.js.map +1 -0
- package/dist/types/api.d.ts +1222 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +5 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/errors.d.ts +772 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +937 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +33 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/messages.d.ts +257 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/messages.js +96 -0
- package/dist/types/messages.js.map +1 -0
- package/dist/types/protocol-config.d.ts +337 -0
- package/dist/types/protocol-config.d.ts.map +1 -0
- package/dist/types/protocol-config.js +178 -0
- package/dist/types/protocol-config.js.map +1 -0
- package/dist/types/protocol-constants.d.ts +122 -0
- package/dist/types/protocol-constants.d.ts.map +1 -0
- package/dist/types/protocol-constants.js +115 -0
- package/dist/types/protocol-constants.js.map +1 -0
- package/dist/types/session.d.ts +721 -0
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/session.js +340 -0
- package/dist/types/session.js.map +1 -0
- package/dist/types/trust.d.ts +168 -0
- package/dist/types/trust.d.ts.map +1 -0
- package/dist/types/trust.js +84 -0
- package/dist/types/trust.js.map +1 -0
- package/dist/types/utils.d.ts +93 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/utils.js +89 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/username/index.d.ts +12 -0
- package/dist/username/index.d.ts.map +1 -0
- package/dist/username/index.js +11 -0
- package/dist/username/index.js.map +1 -0
- package/dist/username/link.d.ts +52 -0
- package/dist/username/link.d.ts.map +1 -0
- package/dist/username/link.js +87 -0
- package/dist/username/link.js.map +1 -0
- package/dist/utils/binary-transfer.d.ts +18 -0
- package/dist/utils/binary-transfer.d.ts.map +1 -0
- package/dist/utils/binary-transfer.js +27 -0
- package/dist/utils/binary-transfer.js.map +1 -0
- package/dist/utils/errors.d.ts +9 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +15 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/retry.d.ts +59 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +136 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/versions.d.ts +62 -0
- package/dist/versions.d.ts.map +1 -0
- package/dist/versions.js +78 -0
- package/dist/versions.js.map +1 -0
- package/dist/zk/credentials.d.ts +10 -0
- package/dist/zk/credentials.d.ts.map +1 -0
- package/dist/zk/credentials.js +9 -0
- package/dist/zk/credentials.js.map +1 -0
- package/dist/zk/groups.d.ts +12 -0
- package/dist/zk/groups.d.ts.map +1 -0
- package/dist/zk/groups.js +11 -0
- package/dist/zk/groups.js.map +1 -0
- package/docs/ASSURANCE.md +102 -0
- package/docs/CLIENT_COMPOSITION.md +189 -0
- package/docs/DOCUMENTATION_STANDARDS.md +107 -0
- package/docs/E2EE.md +35 -0
- package/docs/ERROR_HANDLING.md +396 -0
- package/docs/GETTING_STARTED.md +714 -0
- package/docs/INTERFACES.md +187 -0
- package/docs/PACKAGE_SURFACE.md +235 -0
- package/docs/PROTOCOL_POLICY.md +109 -0
- package/docs/RECIPES.md +389 -0
- package/docs/SECURITY.md +199 -0
- package/docs/api/README.md +471 -0
- package/docs/api/classes/EncryptionError.md +112 -0
- package/docs/api/classes/EndorsementManager.md +307 -0
- package/docs/api/classes/SealedSenderAuthError.md +127 -0
- package/docs/api/classes/ServerDerivedKeyPair.md +68 -0
- package/docs/api/classes/ServerDerivedPublicKey.md +33 -0
- package/docs/api/classes/ServerRootKeyPair.md +94 -0
- package/docs/api/classes/ServerRootPublicKey.md +72 -0
- package/docs/api/classes/SignalBlockingManager.md +106 -0
- package/docs/api/classes/SignalProtocolClient.md +2651 -0
- package/docs/api/classes/VerificationFailure.md +25 -0
- package/docs/api/enumerations/ContentHint.md +63 -0
- package/docs/api/enumerations/EncryptionErrorCode.md +488 -0
- package/docs/api/enumerations/IdentityKeyChange.md +65 -0
- package/docs/api/enumerations/MessageType.md +29 -0
- package/docs/api/enumerations/TrustDirection.md +33 -0
- package/docs/api/enumerations/TypingAction.md +31 -0
- package/docs/api/functions/createDefaultSignalContentAdapter.md +13 -0
- package/docs/api/functions/createDefaultSignalLogger.md +36 -0
- package/docs/api/functions/createGroupId.md +32 -0
- package/docs/api/functions/createSignalProtocolClient.md +36 -0
- package/docs/api/functions/createSignalProtocolClientConfig.md +24 -0
- package/docs/api/functions/extractGroupId.md +32 -0
- package/docs/api/functions/formatVersion.md +25 -0
- package/docs/api/functions/isCompatible.md +31 -0
- package/docs/api/functions/isGroupId.md +37 -0
- package/docs/api/functions/isSealedSenderAuthError.md +25 -0
- package/docs/api/functions/parseVersion.md +29 -0
- package/docs/api/functions/resolveSPQRLimits.md +21 -0
- package/docs/api/functions/resolveSignalLogger.md +42 -0
- package/docs/api/interfaces/AccountIdentityProvisioning.md +43 -0
- package/docs/api/interfaces/AccountIdentityRotation.md +69 -0
- package/docs/api/interfaces/AttachmentTransferOptions.md +49 -0
- package/docs/api/interfaces/BlockedRecipientEntry.md +25 -0
- package/docs/api/interfaces/BlockedRecipientsSyncInput.md +27 -0
- package/docs/api/interfaces/ConfigurationSyncInput.md +19 -0
- package/docs/api/interfaces/CredentialPublicKey.md +25 -0
- package/docs/api/interfaces/DataMessageInput.md +21 -0
- package/docs/api/interfaces/DecryptedEnvelope.md +95 -0
- package/docs/api/interfaces/DecryptedGroup.md +86 -0
- package/docs/api/interfaces/DeviceInfo.md +79 -0
- package/docs/api/interfaces/DeviceRecord.md +87 -0
- package/docs/api/interfaces/DeviceRegistration.md +27 -0
- package/docs/api/interfaces/DoubleRatchetConfig.md +36 -0
- package/docs/api/interfaces/EcOneTimePreKey.md +27 -0
- package/docs/api/interfaces/EcSignedPreKey.md +39 -0
- package/docs/api/interfaces/EcSignedPreKeyUpload.md +50 -0
- package/docs/api/interfaces/EncryptionErrorContext.md +51 -0
- package/docs/api/interfaces/Envelope.md +154 -0
- package/docs/api/interfaces/ForceKeyResetResult.md +37 -0
- package/docs/api/interfaces/GroupAuthorization.md +23 -0
- package/docs/api/interfaces/GroupChangeEntry.md +42 -0
- package/docs/api/interfaces/GroupMemberDevice.md +26 -0
- package/docs/api/interfaces/IEcOneTimePreKeyStore.md +86 -0
- package/docs/api/interfaces/IEcSignedPreKeyStore.md +132 -0
- package/docs/api/interfaces/IGroupServer.md +120 -0
- package/docs/api/interfaces/IGroupStateStore.md +128 -0
- package/docs/api/interfaces/IIdentityKeyStore.md +312 -0
- package/docs/api/interfaces/IKemPreKeyStore.md +144 -0
- package/docs/api/interfaces/IKyberLastResortPreKeyStore.md +111 -0
- package/docs/api/interfaces/ILogger.md +117 -0
- package/docs/api/interfaces/IProtocolStore.md +1033 -0
- package/docs/api/interfaces/ISenderKeyStore.md +417 -0
- package/docs/api/interfaces/ISesameStore.md +249 -0
- package/docs/api/interfaces/ISessionStore.md +178 -0
- package/docs/api/interfaces/ISignalLocalSecretVault.md +71 -0
- package/docs/api/interfaces/ISignalLocalStore.md +2053 -0
- package/docs/api/interfaces/ISignalProtocolClient.md +1183 -0
- package/docs/api/interfaces/ISignalProtocolManager.md +272 -0
- package/docs/api/interfaces/ISignalRelayServer.md +1329 -0
- package/docs/api/interfaces/IdentityKeyPair.md +49 -0
- package/docs/api/interfaces/IncomingEnvelope.md +91 -0
- package/docs/api/interfaces/InspectedSignalContent.md +43 -0
- package/docs/api/interfaces/KDFChain.md +31 -0
- package/docs/api/interfaces/KemLastResortPreKeyUpload.md +50 -0
- package/docs/api/interfaces/KeyPair.md +23 -0
- package/docs/api/interfaces/KyberPreKey.md +42 -0
- package/docs/api/interfaces/MLKEMBraidAgentState.md +191 -0
- package/docs/api/interfaces/MLKEMBraidMessage.md +49 -0
- package/docs/api/interfaces/MediaAttachmentDeleteSyncInput.md +31 -0
- package/docs/api/interfaces/MessageHeader.md +49 -0
- package/docs/api/interfaces/MessageRecord.md +86 -0
- package/docs/api/interfaces/ParsedReceiptContent.md +19 -0
- package/docs/api/interfaces/ParsedTypingContent.md +19 -0
- package/docs/api/interfaces/PreKeyMaintenanceStore.md +87 -0
- package/docs/api/interfaces/PreKeyMessage.md +159 -0
- package/docs/api/interfaces/PreKeyStatusResult.md +21 -0
- package/docs/api/interfaces/PreKeyUpload.md +42 -0
- package/docs/api/interfaces/ProcessEnvelopeOptions.md +72 -0
- package/docs/api/interfaces/ProtocolAddress.md +38 -0
- package/docs/api/interfaces/ProtocolStrategyConfig.md +91 -0
- package/docs/api/interfaces/RatchetMessage.md +96 -0
- package/docs/api/interfaces/ReadSyncEntryInput.md +19 -0
- package/docs/api/interfaces/ReceiverChain.md +43 -0
- package/docs/api/interfaces/RecipientUsernameSyncInput.md +31 -0
- package/docs/api/interfaces/RelayPreKeyBundle.md +254 -0
- package/docs/api/interfaces/RemoteObjectDownload.md +33 -0
- package/docs/api/interfaces/RemoteObjectUpload.md +49 -0
- package/docs/api/interfaces/ResolvedSPQRInfoStrings.md +27 -0
- package/docs/api/interfaces/ResolvedSPQRLimits.md +37 -0
- package/docs/api/interfaces/RetryRequest.md +80 -0
- package/docs/api/interfaces/SCKAState.md +65 -0
- package/docs/api/interfaces/SPQRLimits.md +40 -0
- package/docs/api/interfaces/SPQRState.md +191 -0
- package/docs/api/interfaces/SafetyNumber.md +60 -0
- package/docs/api/interfaces/SafetyNumberConfirmation.md +46 -0
- package/docs/api/interfaces/SealedSenderConfig.md +70 -0
- package/docs/api/interfaces/SendOptions.md +191 -0
- package/docs/api/interfaces/SendResult.md +93 -0
- package/docs/api/interfaces/SenderKeyDistributionMessage.md +43 -0
- package/docs/api/interfaces/SenderKeyState.md +76 -0
- package/docs/api/interfaces/SenderKeysConfig.md +65 -0
- package/docs/api/interfaces/SentSyncTranscriptInput.md +31 -0
- package/docs/api/interfaces/ServiceId.md +19 -0
- package/docs/api/interfaces/SesameMessage.md +84 -0
- package/docs/api/interfaces/SesameStats.md +57 -0
- package/docs/api/interfaces/SessionHealthResult.md +120 -0
- package/docs/api/interfaces/SessionRecord.md +80 -0
- package/docs/api/interfaces/SessionRecordMetadata.md +109 -0
- package/docs/api/interfaces/SessionState.md +368 -0
- package/docs/api/interfaces/SessionTrustCommit.md +58 -0
- package/docs/api/interfaces/SignalBlockingHooks.md +44 -0
- package/docs/api/interfaces/SignalBlockingManagerOptions.md +31 -0
- package/docs/api/interfaces/SignalBlockingMirror.md +30 -0
- package/docs/api/interfaces/SignalBlockingStore.md +83 -0
- package/docs/api/interfaces/SignalContentAdapter.md +325 -0
- package/docs/api/interfaces/SignalProtocolClientAdapterConfig.md +44 -0
- package/docs/api/interfaces/SignalProtocolClientCompositionOptions.md +693 -0
- package/docs/api/interfaces/SignalProtocolClientConfig.md +839 -0
- package/docs/api/interfaces/SignalProtocolClientDeleteLocalAttachmentInput.md +25 -0
- package/docs/api/interfaces/SignalProtocolClientHooks.md +506 -0
- package/docs/api/interfaces/SignalProtocolClientIdentityConfig.md +35 -0
- package/docs/api/interfaces/SignalProtocolClientLoadLocalAttachmentInput.md +187 -0
- package/docs/api/interfaces/SignalProtocolClientLoadedLocalAttachment.md +19 -0
- package/docs/api/interfaces/SignalProtocolClientMedia.md +83 -0
- package/docs/api/interfaces/SignalProtocolClientMediaCompletedResult.md +25 -0
- package/docs/api/interfaces/SignalProtocolClientMediaConfig.md +157 -0
- package/docs/api/interfaces/SignalProtocolClientMediaDownloadCompletedResult.md +37 -0
- package/docs/api/interfaces/SignalProtocolClientMediaDownloadNotNeededResult.md +25 -0
- package/docs/api/interfaces/SignalProtocolClientMediaFailedResult.md +19 -0
- package/docs/api/interfaces/SignalProtocolClientMediaOperationOptions.md +53 -0
- package/docs/api/interfaces/SignalProtocolClientMediaPendingResult.md +19 -0
- package/docs/api/interfaces/SignalProtocolClientMediaProcessResult.md +43 -0
- package/docs/api/interfaces/SignalProtocolClientMediaSkippedResult.md +25 -0
- package/docs/api/interfaces/SignalProtocolClientMediaUploadCompletedResult.md +31 -0
- package/docs/api/interfaces/SignalProtocolClientProcessPendingMediaOptions.md +87 -0
- package/docs/api/interfaces/SignalProtocolClientSaveDownloadedAttachmentInput.md +25 -0
- package/docs/api/interfaces/SignalProtocolClientSaveUploadedAttachmentInput.md +25 -0
- package/docs/api/interfaces/SignalProtocolClientSyncDeleteInput.md +19 -0
- package/docs/api/interfaces/SignalProtocolConfig.md +50 -0
- package/docs/api/interfaces/SignalRemoteObjectStore.md +88 -0
- package/docs/api/interfaces/SkippedSenderMessageKey.md +26 -0
- package/docs/api/interfaces/TaskNotificationAckSyncInput.md +31 -0
- package/docs/api/interfaces/TripleRatchetState.md +64 -0
- package/docs/api/interfaces/UserRecord.md +71 -0
- package/docs/api/interfaces/UsernameStateSyncInput.md +19 -0
- package/docs/api/interfaces/VerificationStateSyncInput.md +31 -0
- package/docs/api/interfaces/VersionNegotiationState.md +84 -0
- package/docs/api/interfaces/ViewOnceOpenSyncInput.md +19 -0
- package/docs/api/namespaces/ProtocolAddress/README.md +33 -0
- package/docs/api/namespaces/ProtocolAddress/functions/create.md +41 -0
- package/docs/api/namespaces/ProtocolAddress/functions/equals.md +39 -0
- package/docs/api/namespaces/ProtocolAddress/functions/fromStorageKey.md +36 -0
- package/docs/api/namespaces/ProtocolAddress/functions/isUser.md +39 -0
- package/docs/api/namespaces/ProtocolAddress/functions/isValid.md +34 -0
- package/docs/api/namespaces/ProtocolAddress/functions/parse.md +41 -0
- package/docs/api/namespaces/ProtocolAddress/functions/toStorageKey.md +38 -0
- package/docs/api/namespaces/ProtocolAddress/functions/toString.md +34 -0
- package/docs/api/namespaces/SessionRecord/README.md +30 -0
- package/docs/api/namespaces/SessionRecord/functions/archiveCurrent.md +40 -0
- package/docs/api/namespaces/SessionRecord/functions/archiveCurrentState.md +34 -0
- package/docs/api/namespaces/SessionRecord/functions/create.md +25 -0
- package/docs/api/namespaces/SessionRecord/functions/deserialize.md +29 -0
- package/docs/api/namespaces/SessionRecord/functions/findSession.md +34 -0
- package/docs/api/namespaces/SessionRecord/functions/getAllSessions.md +25 -0
- package/docs/api/namespaces/SessionRecord/functions/getArchivedCount.md +25 -0
- package/docs/api/namespaces/SessionRecord/functions/hasCurrentSession.md +25 -0
- package/docs/api/namespaces/SessionRecord/functions/hasUsableSenderChain.md +36 -0
- package/docs/api/namespaces/SessionRecord/functions/promoteSession.md +34 -0
- package/docs/api/namespaces/SessionRecord/functions/serialize.md +28 -0
- package/docs/api/namespaces/SessionRecord/variables/MAX_ARCHIVED_SESSIONS.md +14 -0
- package/docs/api/namespaces/SessionState/README.md +15 -0
- package/docs/api/namespaces/SessionState/functions/getSessionId.md +32 -0
- package/docs/api/namespaces/blocking/README.md +43 -0
- package/docs/api/namespaces/encoding/README.md +33 -0
- package/docs/api/namespaces/encoding/functions/base64ToUrlSafe.md +28 -0
- package/docs/api/namespaces/encoding/functions/bytesToBase64.md +21 -0
- package/docs/api/namespaces/encoding/functions/bytesToString.md +21 -0
- package/docs/api/namespaces/encoding/functions/bytesToUrlSafeBase64.md +33 -0
- package/docs/api/namespaces/encoding/functions/concatBytes.md +21 -0
- package/docs/api/namespaces/encoding/functions/stringToBytes.md +21 -0
- package/docs/api/namespaces/encoding/functions/urlSafeToBase64.md +27 -0
- package/docs/api/namespaces/keys/README.md +126 -0
- package/docs/api/namespaces/keys/functions/acceptContactIdentityRotation.md +33 -0
- package/docs/api/namespaces/keys/functions/assertIdentityCommitment.md +25 -0
- package/docs/api/namespaces/keys/functions/compositeIdentitiesEqual.md +23 -0
- package/docs/api/namespaces/keys/functions/createCompositeIdentityV1.md +19 -0
- package/docs/api/namespaces/keys/functions/createPreKeySignatureContext.md +31 -0
- package/docs/api/namespaces/keys/functions/createUnverifiedContactIdentityRecord.md +23 -0
- package/docs/api/namespaces/keys/functions/decodeCompositeIdentityV1.md +19 -0
- package/docs/api/namespaces/keys/functions/deriveIdentityCommitment.md +19 -0
- package/docs/api/namespaces/keys/functions/encodeCompositeIdentityV1.md +19 -0
- package/docs/api/namespaces/keys/functions/evaluateContactIdentityCandidate.md +27 -0
- package/docs/api/namespaces/keys/functions/generateEcOneTimePreKeys.md +37 -0
- package/docs/api/namespaces/keys/functions/generateEcSignedPreKey.md +39 -0
- package/docs/api/namespaces/keys/functions/generateEcSignedPreKeyId.md +21 -0
- package/docs/api/namespaces/keys/functions/generateIdentityKeyPair.md +24 -0
- package/docs/api/namespaces/keys/functions/generateKemOneTimePreKeys.md +47 -0
- package/docs/api/namespaces/keys/functions/generateKyberLastResortPreKey.md +37 -0
- package/docs/api/namespaces/keys/functions/generateRegistrationId.md +13 -0
- package/docs/api/namespaces/keys/functions/signMlKem1024PreKey.md +29 -0
- package/docs/api/namespaces/keys/functions/signPreKey.md +31 -0
- package/docs/api/namespaces/keys/functions/validateContactIdentityRecord.md +19 -0
- package/docs/api/namespaces/keys/functions/verifyContactIdentityRecord.md +31 -0
- package/docs/api/namespaces/keys/functions/verifyMlKem1024PreKey.md +33 -0
- package/docs/api/namespaces/keys/functions/verifyPreKeySignature.md +35 -0
- package/docs/api/namespaces/keys/interfaces/CompositeIdentityV1.md +33 -0
- package/docs/api/namespaces/keys/interfaces/ContactIdentityRecord.md +53 -0
- package/docs/api/namespaces/keys/interfaces/KemOneTimePreKey.md +43 -0
- package/docs/api/namespaces/keys/type-aliases/IdentityCandidateStatus.md +9 -0
- package/docs/api/namespaces/keys/type-aliases/IdentityTrustState.md +9 -0
- package/docs/api/namespaces/keys/type-aliases/IdentityType.md +9 -0
- package/docs/api/namespaces/keys/variables/COMPOSITE_IDENTITY_V1_ED25519_TAG.md +9 -0
- package/docs/api/namespaces/keys/variables/COMPOSITE_IDENTITY_V1_LENGTH.md +9 -0
- package/docs/api/namespaces/keys/variables/COMPOSITE_IDENTITY_V1_VERSION.md +9 -0
- package/docs/api/namespaces/keys/variables/COMPOSITE_IDENTITY_V1_X25519_TAG.md +9 -0
- package/docs/api/namespaces/keys/variables/IDENTITY_COMMITMENT_V1_DOMAIN.md +9 -0
- package/docs/api/namespaces/keys/variables/PREKEY_ALGORITHM_ML_KEM_1024.md +9 -0
- package/docs/api/namespaces/keys/variables/PREKEY_ALGORITHM_X25519.md +9 -0
- package/docs/api/namespaces/keys/variables/PREKEY_SIGNATURE_V1_DOMAIN.md +9 -0
- package/docs/api/namespaces/media/README.md +105 -0
- package/docs/api/namespaces/media/classes/MediaAttachmentError.md +57 -0
- package/docs/api/namespaces/media/functions/createByteRangeMediaAttachmentTransfer.md +19 -0
- package/docs/api/namespaces/media/functions/createMediaAttachmentDeliveryId.md +29 -0
- package/docs/api/namespaces/media/functions/createMediaAttachmentId.md +19 -0
- package/docs/api/namespaces/media/functions/createMediaAttachmentMessage.md +25 -0
- package/docs/api/namespaces/media/functions/createMediaAttachmentPointer.md +19 -0
- package/docs/api/namespaces/media/functions/createTusMediaAttachmentTransfer.md +19 -0
- package/docs/api/namespaces/media/functions/deleteMediaAttachment.md +23 -0
- package/docs/api/namespaces/media/functions/executeMediaAttachmentJob.md +23 -0
- package/docs/api/namespaces/media/functions/isMediaAttachmentFlagSet.md +19 -0
- package/docs/api/namespaces/media/functions/parseMediaAttachmentMessage.md +19 -0
- package/docs/api/namespaces/media/functions/planMediaAttachmentCleanup.md +23 -0
- package/docs/api/namespaces/media/functions/planMediaAttachmentCleanupJobs.md +19 -0
- package/docs/api/namespaces/media/functions/planMediaAttachmentDeleteSync.md +19 -0
- package/docs/api/namespaces/media/functions/planMediaAttachmentDownloadJob.md +19 -0
- package/docs/api/namespaces/media/functions/planMediaAttachmentOpen.md +19 -0
- package/docs/api/namespaces/media/functions/planMediaAttachmentProcessing.md +19 -0
- package/docs/api/namespaces/media/functions/planMediaAttachmentUploadJob.md +19 -0
- package/docs/api/namespaces/media/functions/prepareMediaAttachmentUpload.md +30 -0
- package/docs/api/namespaces/media/functions/resolveMediaAttachment.md +30 -0
- package/docs/api/namespaces/media/functions/serializeMediaAttachmentMessage.md +25 -0
- package/docs/api/namespaces/media/functions/validateMediaAttachmentPolicy.md +23 -0
- package/docs/api/namespaces/media/interfaces/ByteRangeMediaAttachmentPartialStore.md +68 -0
- package/docs/api/namespaces/media/interfaces/ByteRangeMediaAttachmentTransferOptions.md +91 -0
- package/docs/api/namespaces/media/interfaces/DeleteMediaAttachmentOptions.md +25 -0
- package/docs/api/namespaces/media/interfaces/DeleteMediaAttachmentResult.md +19 -0
- package/docs/api/namespaces/media/interfaces/ExecuteMediaAttachmentJobOptions.md +157 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentBackgroundJob.md +85 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentCleanupPlan.md +37 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentJobExecutionResult.md +55 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentMessage.md +31 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentOpenDecision.md +31 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentPointer.md +133 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentPolicy.md +67 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentProcessingPlan.md +73 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentProgress.md +69 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentResumeState.md +37 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentRetryOptions.md +31 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentTransfer.md +51 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentTransferCheckpoint.md +69 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentTransferOptions.md +67 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentUploadJobData.md +19 -0
- package/docs/api/namespaces/media/interfaces/MediaAttachmentUploadResponse.md +25 -0
- package/docs/api/namespaces/media/interfaces/PlanMediaAttachmentCleanupJobsInput.md +61 -0
- package/docs/api/namespaces/media/interfaces/PlanMediaAttachmentDeleteSyncInput.md +25 -0
- package/docs/api/namespaces/media/interfaces/PlanMediaAttachmentDownloadJobInput.md +161 -0
- package/docs/api/namespaces/media/interfaces/PlanMediaAttachmentOpenInput.md +25 -0
- package/docs/api/namespaces/media/interfaces/PlanMediaAttachmentProcessingInput.md +83 -0
- package/docs/api/namespaces/media/interfaces/PlanMediaAttachmentUploadJobInput.md +147 -0
- package/docs/api/namespaces/media/interfaces/PrepareMediaAttachmentUploadOptions.md +144 -0
- package/docs/api/namespaces/media/interfaces/ResolveMediaAttachmentOptions.md +55 -0
- package/docs/api/namespaces/media/interfaces/ResolvedMediaAttachment.md +109 -0
- package/docs/api/namespaces/media/interfaces/TusMediaAttachmentTransferOptions.md +85 -0
- package/docs/api/namespaces/media/type-aliases/CreateMediaAttachmentPointerInput.md +15 -0
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentCheckpointCallback.md +19 -0
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentCleanupReason.md +9 -0
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentErrorCode.md +9 -0
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentFlag.md +9 -0
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentJobExecutionStatus.md +9 -0
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentJobOperation.md +9 -0
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentJobPriority.md +9 -0
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentJobSkipReason.md +9 -0
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentJobSource.md +9 -0
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentKnownIds.md +9 -0
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentMessageType.md +9 -0
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentProgressCallback.md +19 -0
- package/docs/api/namespaces/media/variables/MEDIA_ATTACHMENT_POLICY_DEFAULTS.md +47 -0
- package/docs/api/namespaces/media/variables/MEDIA_ATTACHMENT_POLICY_PRESETS.md +95 -0
- package/docs/api/namespaces/media/variables/MediaAttachmentCleanupReason.md +27 -0
- package/docs/api/namespaces/media/variables/MediaAttachmentErrorCode.md +75 -0
- package/docs/api/namespaces/media/variables/MediaAttachmentFlag.md +23 -0
- package/docs/api/namespaces/media/variables/MediaAttachmentJobExecutionStatus.md +19 -0
- package/docs/api/namespaces/media/variables/MediaAttachmentJobOperation.md +31 -0
- package/docs/api/namespaces/media/variables/MediaAttachmentJobPriority.md +23 -0
- package/docs/api/namespaces/media/variables/MediaAttachmentJobSource.md +51 -0
- package/docs/api/namespaces/media/variables/MediaAttachmentMessageType.md +15 -0
- package/docs/api/namespaces/media/variables/downloadMediaAttachment.md +30 -0
- package/docs/api/namespaces/safety/README.md +61 -0
- package/docs/api/namespaces/safety/classes/DisplayableFingerprint.md +108 -0
- package/docs/api/namespaces/safety/classes/Fingerprint.md +104 -0
- package/docs/api/namespaces/safety/classes/ScannableFingerprint.md +209 -0
- package/docs/api/namespaces/safety/functions/base64ToBytes.md +21 -0
- package/docs/api/namespaces/safety/functions/clearFingerprintCache.md +15 -0
- package/docs/api/namespaces/safety/functions/compareSafetyNumbers.md +25 -0
- package/docs/api/namespaces/safety/functions/createFingerprintData.md +60 -0
- package/docs/api/namespaces/safety/functions/extractQrData.md +34 -0
- package/docs/api/namespaces/safety/functions/generateCompositeSafetyNumber.md +39 -0
- package/docs/api/namespaces/safety/functions/generateEmojiFingerprint.md +24 -0
- package/docs/api/namespaces/safety/functions/generateSingleKeyReferenceSafetyNumber.md +51 -0
- package/docs/api/namespaces/safety/functions/generateVerifySchemeUrl.md +32 -0
- package/docs/api/namespaces/safety/functions/generateVerifyUrl.md +49 -0
- package/docs/api/namespaces/safety/functions/isValidSafetyNumber.md +21 -0
- package/docs/api/namespaces/safety/functions/isVerifyUrl.md +45 -0
- package/docs/api/namespaces/safety/functions/parseVerifyUrl.md +31 -0
- package/docs/api/namespaces/safety/interfaces/FingerprintData.md +52 -0
- package/docs/api/namespaces/safety/interfaces/SafetyNumber.md +49 -0
- package/docs/api/namespaces/safety/interfaces/VerifyLinkConfig.md +28 -0
- package/docs/api/namespaces/safety/interfaces/VerifyUrlParams.md +49 -0
- package/docs/api/namespaces/safety/type-aliases/CompareResult.md +21 -0
- package/docs/api/namespaces/safety/variables/DEFAULT_VERIFY_LINK_CONFIG.md +12 -0
- package/docs/api/namespaces/safety/variables/FINGERPRINT_ITERATIONS.md +12 -0
- package/docs/api/namespaces/safety/variables/FINGERPRINT_VERSION.md +12 -0
- package/docs/api/namespaces/safety/variables/VERIFY_BASE_URL.md +11 -0
- package/docs/api/namespaces/safety/variables/VERIFY_SCHEME_URL.md +11 -0
- package/docs/api/type-aliases/Base64.md +20 -0
- package/docs/api/type-aliases/BraidPolicy.md +11 -0
- package/docs/api/type-aliases/Bytes.md +20 -0
- package/docs/api/type-aliases/Ciphertext.md +21 -0
- package/docs/api/type-aliases/DeviceType.md +11 -0
- package/docs/api/type-aliases/DownloadedAttachment.md +11 -0
- package/docs/api/type-aliases/GroupId.md +27 -0
- package/docs/api/type-aliases/Hex.md +20 -0
- package/docs/api/type-aliases/HookName.md +11 -0
- package/docs/api/type-aliases/PostQuantumPolicy.md +11 -0
- package/docs/api/type-aliases/PreparedAttachmentUpload.md +14 -0
- package/docs/api/type-aliases/PrivateKey.md +22 -0
- package/docs/api/type-aliases/ProgressCallback.md +45 -0
- package/docs/api/type-aliases/PublicKey.md +22 -0
- package/docs/api/type-aliases/RemoteObjectCompleteUploadRequest.md +19 -0
- package/docs/api/type-aliases/RemoteObjectDeleteRequest.md +19 -0
- package/docs/api/type-aliases/RemoteObjectDownloadRequest.md +19 -0
- package/docs/api/type-aliases/RemoteObjectUploadRequest.md +42 -0
- package/docs/api/type-aliases/SCKAMode.md +11 -0
- package/docs/api/type-aliases/SealedSenderAuth.md +15 -0
- package/docs/api/type-aliases/SignalProtocolClientMediaCleanupInput.md +9 -0
- package/docs/api/type-aliases/SignalProtocolClientMediaCleanupResult.md +9 -0
- package/docs/api/type-aliases/SignalProtocolClientMediaDownloadInput.md +9 -0
- package/docs/api/type-aliases/SignalProtocolClientMediaDownloadResult.md +9 -0
- package/docs/api/type-aliases/SignalProtocolClientMediaOperationResult.md +9 -0
- package/docs/api/type-aliases/SignalProtocolClientMediaUploadInput.md +9 -0
- package/docs/api/type-aliases/SignalProtocolClientMediaUploadResult.md +9 -0
- package/docs/api/type-aliases/Signature.md +21 -0
- package/docs/api/type-aliases/Unsubscribe.md +15 -0
- package/docs/api/variables/BraidPolicy.md +21 -0
- package/docs/api/variables/DEFAULT_DEVICE_ID.md +12 -0
- package/docs/api/variables/DOUBLE_RATCHET_SPEC.md +11 -0
- package/docs/api/variables/GROUP_V2_PREFIX.md +11 -0
- package/docs/api/variables/KEY_REFRESH_INTERVAL_MS_DEFAULT.md +11 -0
- package/docs/api/variables/MAX_MESSAGE_KEYS.md +14 -0
- package/docs/api/variables/MAX_PREKEY_AGE_MS_DEFAULT.md +11 -0
- package/docs/api/variables/MAX_RECEIVER_CHAINS.md +14 -0
- package/docs/api/variables/MAX_REGISTRATION_ID.md +16 -0
- package/docs/api/variables/MAX_SKIP.md +11 -0
- package/docs/api/variables/MESSAGE_FORMAT.md +11 -0
- package/docs/api/variables/MIN_REGISTRATION_ID.md +16 -0
- package/docs/api/variables/ML_KEM_BRAID_SPEC.md +11 -0
- package/docs/api/variables/ONE_TIME_PREKEY_BATCH_SIZE.md +21 -0
- package/docs/api/variables/PQXDH_SPEC.md +11 -0
- package/docs/api/variables/PostQuantumPolicy.md +21 -0
- package/docs/api/variables/SENDER_KEY_FORMAT.md +11 -0
- package/docs/api/variables/SENDER_KEY_SPEC.md +11 -0
- package/docs/api/variables/SESAME_SPEC.md +11 -0
- package/docs/api/variables/SESSION_FORMAT.md +11 -0
- package/docs/api/variables/SPQR_LIMITS_DEFAULTS.md +11 -0
- package/docs/api/variables/X3DH_SPEC.md +9 -0
- package/docs/api/variables/defaultSignalLogger.md +32 -0
- package/encoding/README.md +32 -0
- package/files/README.md +37 -0
- package/groups/README.md +42 -0
- package/hooks/README.md +40 -0
- package/keys/README.md +121 -0
- package/local/store/README.md +120 -0
- package/local/store/expo/README.md +73 -0
- package/local/store/mock/README.md +27 -0
- package/local/store/node/README.md +35 -0
- package/local/store/react-native/README.md +39 -0
- package/local/store/web/README.md +65 -0
- package/local/vault/README.md +32 -0
- package/media/README.md +73 -0
- package/package.json +436 -0
- package/profile/README.md +44 -0
- package/remote/README.md +219 -0
- package/remote/object-store/README.md +45 -0
- package/remote/object-store/convex-r2/README.md +85 -0
- package/remote/object-store/s3/README.md +35 -0
- package/remote/relay/README.md +38 -0
- package/remote/relay/convex/README.md +54 -0
- package/remote/relay/mock/README.md +32 -0
- package/safety/README.md +42 -0
- package/sealed-sender/README.md +32 -0
- package/types/README.md +36 -0
- package/username/README.md +37 -0
- package/utils/README.md +37 -0
- package/zk/README.md +36 -0
|
@@ -0,0 +1,2053 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypted-media message contracts.
|
|
3
|
+
*
|
|
4
|
+
* The package sends media as a two-layer encrypted attachment: encrypted bytes
|
|
5
|
+
* live in remote object storage, while the pointer, key, and integrity metadata
|
|
6
|
+
* travel inside an end-to-end encrypted application message.
|
|
7
|
+
*/
|
|
8
|
+
import { base64ToBytes, bytesToBase64, bytesToUrlSafeBase64, concatBytes, constantTimeEqual, generateRandomBytes, secureZeroBytes, sha256, streamingDecrypt, streamingEncrypt, } from '../internal/crypto/index.js';
|
|
9
|
+
import { toBase64 } from '../types/utils.js';
|
|
10
|
+
export const MediaAttachmentMessageType = {
|
|
11
|
+
Attachment: 'attachment',
|
|
12
|
+
};
|
|
13
|
+
export const MediaAttachmentFlag = {
|
|
14
|
+
VoiceMessage: 1,
|
|
15
|
+
Borderless: 2,
|
|
16
|
+
Gif: 8,
|
|
17
|
+
};
|
|
18
|
+
const MEDIA_ATTACHMENT_KEY_BYTES = 32;
|
|
19
|
+
const MEDIA_ATTACHMENT_DIGEST_BYTES = 32;
|
|
20
|
+
const KNOWN_MEDIA_ATTACHMENT_FLAG_VALUES = new Set([
|
|
21
|
+
0,
|
|
22
|
+
MediaAttachmentFlag.VoiceMessage,
|
|
23
|
+
MediaAttachmentFlag.Borderless,
|
|
24
|
+
MediaAttachmentFlag.Gif,
|
|
25
|
+
MediaAttachmentFlag.VoiceMessage + MediaAttachmentFlag.Borderless,
|
|
26
|
+
MediaAttachmentFlag.VoiceMessage + MediaAttachmentFlag.Gif,
|
|
27
|
+
MediaAttachmentFlag.Borderless + MediaAttachmentFlag.Gif,
|
|
28
|
+
MediaAttachmentFlag.VoiceMessage + MediaAttachmentFlag.Borderless + MediaAttachmentFlag.Gif,
|
|
29
|
+
]);
|
|
30
|
+
const UUID_PATTERN = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
31
|
+
export function isMediaAttachmentFlagSet(value) {
|
|
32
|
+
return (typeof value === 'number' &&
|
|
33
|
+
Number.isSafeInteger(value) &&
|
|
34
|
+
KNOWN_MEDIA_ATTACHMENT_FLAG_VALUES.has(value));
|
|
35
|
+
}
|
|
36
|
+
function hexByte(value) {
|
|
37
|
+
return value.toString(16).padStart(2, '0');
|
|
38
|
+
}
|
|
39
|
+
async function generateMediaAttachmentClientUuid() {
|
|
40
|
+
const bytes = await generateRandomBytes(16);
|
|
41
|
+
bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40;
|
|
42
|
+
bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;
|
|
43
|
+
const hex = Array.from(bytes, hexByte).join('');
|
|
44
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
45
|
+
}
|
|
46
|
+
/** @internal */
|
|
47
|
+
export async function generateMediaAttachmentUploadRequestId() {
|
|
48
|
+
const bytes = await generateRandomBytes(18);
|
|
49
|
+
return `media-upload/${bytesToUrlSafeBase64(bytes)}`;
|
|
50
|
+
}
|
|
51
|
+
export const MediaAttachmentErrorCode = {
|
|
52
|
+
RemoteObjectStoreNotConfigured: 'remote-object-store-not-configured',
|
|
53
|
+
UploadFailed: 'upload-failed',
|
|
54
|
+
UploadIdentityChanged: 'upload-identity-changed',
|
|
55
|
+
DownloadFailed: 'download-failed',
|
|
56
|
+
Cancelled: 'cancelled',
|
|
57
|
+
DeleteUnavailable: 'delete-unavailable',
|
|
58
|
+
DeleteFailed: 'delete-failed',
|
|
59
|
+
BlobNotFound: 'blob-not-found',
|
|
60
|
+
ResumeStateInvalid: 'resume-state-invalid',
|
|
61
|
+
JobHandlerMissing: 'job-handler-missing',
|
|
62
|
+
PolicyViolation: 'policy-violation',
|
|
63
|
+
InvalidPointer: 'invalid-pointer',
|
|
64
|
+
CiphertextSizeMismatch: 'ciphertext-size-mismatch',
|
|
65
|
+
DigestMismatch: 'digest-mismatch',
|
|
66
|
+
DecryptionFailed: 'decryption-failed',
|
|
67
|
+
PlaintextSizeMismatch: 'plaintext-size-mismatch',
|
|
68
|
+
};
|
|
69
|
+
export class MediaAttachmentError extends Error {
|
|
70
|
+
code;
|
|
71
|
+
status;
|
|
72
|
+
constructor(message, code, options) {
|
|
73
|
+
super(message);
|
|
74
|
+
this.name = 'MediaAttachmentError';
|
|
75
|
+
this.code = code;
|
|
76
|
+
this.status = options?.status;
|
|
77
|
+
if (options && 'cause' in options) {
|
|
78
|
+
this.cause = options.cause;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export const MEDIA_ATTACHMENT_POLICY_DEFAULTS = {
|
|
83
|
+
maxPlaintextSizeBytes: 50 * 1024 * 1024,
|
|
84
|
+
maxCiphertextSizeBytes: 64 * 1024 * 1024,
|
|
85
|
+
maxFileNameLength: 255,
|
|
86
|
+
maxCaptionLength: 4_096,
|
|
87
|
+
maxWidth: 65_535,
|
|
88
|
+
maxHeight: 65_535,
|
|
89
|
+
maxDurationMs: 24 * 60 * 60 * 1_000,
|
|
90
|
+
maxThumbnailBytes: 256 * 1024,
|
|
91
|
+
maxWaveformSamples: 4_096,
|
|
92
|
+
};
|
|
93
|
+
export const MEDIA_ATTACHMENT_POLICY_PRESETS = {
|
|
94
|
+
Image: {
|
|
95
|
+
allowedContentTypes: ['image/*'],
|
|
96
|
+
maxPlaintextSizeBytes: 25 * 1024 * 1024,
|
|
97
|
+
maxCiphertextSizeBytes: 32 * 1024 * 1024,
|
|
98
|
+
maxThumbnailBytes: 256 * 1024,
|
|
99
|
+
},
|
|
100
|
+
Video: {
|
|
101
|
+
allowedContentTypes: ['video/*'],
|
|
102
|
+
maxPlaintextSizeBytes: 100 * 1024 * 1024,
|
|
103
|
+
maxCiphertextSizeBytes: 128 * 1024 * 1024,
|
|
104
|
+
maxDurationMs: 4 * 60 * 60 * 1_000,
|
|
105
|
+
maxThumbnailBytes: 512 * 1024,
|
|
106
|
+
},
|
|
107
|
+
Audio: {
|
|
108
|
+
allowedContentTypes: ['audio/*'],
|
|
109
|
+
maxPlaintextSizeBytes: 100 * 1024 * 1024,
|
|
110
|
+
maxCiphertextSizeBytes: 128 * 1024 * 1024,
|
|
111
|
+
maxDurationMs: 4 * 60 * 60 * 1_000,
|
|
112
|
+
maxWaveformSamples: 4_096,
|
|
113
|
+
},
|
|
114
|
+
Document: {
|
|
115
|
+
allowedContentTypes: ['application/pdf', 'text/*'],
|
|
116
|
+
maxPlaintextSizeBytes: 50 * 1024 * 1024,
|
|
117
|
+
maxCiphertextSizeBytes: 64 * 1024 * 1024,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
export const MediaAttachmentCleanupReason = {
|
|
121
|
+
ViewOnceOpened: 'view-once-opened',
|
|
122
|
+
MessageDeleted: 'message-deleted',
|
|
123
|
+
MessageExpired: 'message-expired',
|
|
124
|
+
OrphanedUpload: 'orphaned-upload',
|
|
125
|
+
};
|
|
126
|
+
export const MediaAttachmentJobOperation = {
|
|
127
|
+
Upload: 'upload',
|
|
128
|
+
Download: 'download',
|
|
129
|
+
DeleteLocal: 'delete-local',
|
|
130
|
+
DeleteRemote: 'delete-remote',
|
|
131
|
+
SyncDelete: 'sync-delete',
|
|
132
|
+
};
|
|
133
|
+
export const MediaAttachmentJobSource = {
|
|
134
|
+
ComposePreUpload: 'compose-pre-upload',
|
|
135
|
+
IncomingMessage: 'incoming-message',
|
|
136
|
+
SentSync: 'sent-sync',
|
|
137
|
+
UserAction: 'user-action',
|
|
138
|
+
Retry: 'retry',
|
|
139
|
+
BackgroundRecovery: 'background-recovery',
|
|
140
|
+
MessageDeleted: 'message-deleted',
|
|
141
|
+
MessageExpired: 'message-expired',
|
|
142
|
+
OrphanCleanup: 'orphan-cleanup',
|
|
143
|
+
LinkedDeviceSync: 'linked-device-sync',
|
|
144
|
+
};
|
|
145
|
+
export const MediaAttachmentJobPriority = {
|
|
146
|
+
High: 'high',
|
|
147
|
+
Normal: 'normal',
|
|
148
|
+
Low: 'low',
|
|
149
|
+
};
|
|
150
|
+
export const MediaAttachmentJobExecutionStatus = {
|
|
151
|
+
Completed: 'completed',
|
|
152
|
+
Skipped: 'skipped',
|
|
153
|
+
};
|
|
154
|
+
function assertString(value, field) {
|
|
155
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
156
|
+
throw new TypeError(`Invalid media attachment pointer: ${field} must be a non-empty string`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function assertBase64ByteLength(value, field, expectedBytes) {
|
|
160
|
+
try {
|
|
161
|
+
const bytes = base64ToBytes(toBase64(value));
|
|
162
|
+
if (bytes.length !== expectedBytes) {
|
|
163
|
+
throw new Error(`expected ${expectedBytes} bytes, received ${bytes.length}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (cause) {
|
|
167
|
+
throw new TypeError(`Invalid media attachment pointer: ${field} must be a base64-encoded ${expectedBytes}-byte value`, { cause });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function assertBase64String(value, field) {
|
|
171
|
+
try {
|
|
172
|
+
base64ToBytes(toBase64(value));
|
|
173
|
+
}
|
|
174
|
+
catch (cause) {
|
|
175
|
+
throw new TypeError(`Invalid media attachment pointer: ${field} must be a base64-encoded value`, { cause });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function assertInteger(value, field, options) {
|
|
179
|
+
const min = options?.allowZero ? 0 : 1;
|
|
180
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < min) {
|
|
181
|
+
throw new TypeError(`Invalid media attachment pointer: ${field} must be an integer >= ${min}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function resolvePolicy(policy) {
|
|
185
|
+
return {
|
|
186
|
+
...MEDIA_ATTACHMENT_POLICY_DEFAULTS,
|
|
187
|
+
allowedContentTypes: policy?.allowedContentTypes ?? [],
|
|
188
|
+
...policy,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function assertPolicy(condition, message) {
|
|
192
|
+
if (!condition) {
|
|
193
|
+
throw new MediaAttachmentError(message, MediaAttachmentErrorCode.PolicyViolation);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function assertMetadataString(value, field) {
|
|
197
|
+
assertPolicy(typeof value === 'string' && value.length > 0, `Media attachment ${field} must be a non-empty string`);
|
|
198
|
+
}
|
|
199
|
+
function assertOptionalMetadataString(value, field) {
|
|
200
|
+
if (value === undefined)
|
|
201
|
+
return;
|
|
202
|
+
assertMetadataString(value, field);
|
|
203
|
+
}
|
|
204
|
+
function assertOptionalMetadataInteger(value, field, options) {
|
|
205
|
+
if (value === undefined)
|
|
206
|
+
return;
|
|
207
|
+
const min = options?.allowZero ? 0 : 1;
|
|
208
|
+
assertPolicy(typeof value === 'number' && Number.isSafeInteger(value) && value >= min, `Media attachment ${field} must be an integer >= ${min}`);
|
|
209
|
+
}
|
|
210
|
+
function assertOptionalMetadataBoolean(value, field) {
|
|
211
|
+
if (value === undefined)
|
|
212
|
+
return;
|
|
213
|
+
assertPolicy(typeof value === 'boolean', `Media attachment ${field} must be a boolean`);
|
|
214
|
+
}
|
|
215
|
+
function assertOptionalMetadataWaveform(value) {
|
|
216
|
+
if (value === undefined)
|
|
217
|
+
return;
|
|
218
|
+
assertPolicy(Array.isArray(value) &&
|
|
219
|
+
value.every((sample) => typeof sample === 'number' && Number.isSafeInteger(sample) && sample >= 0 && sample <= 255), 'Media attachment waveform must contain integer samples from 0 to 255');
|
|
220
|
+
}
|
|
221
|
+
function isContentTypeAllowed(contentType, allowedContentTypes) {
|
|
222
|
+
if (allowedContentTypes.length === 0)
|
|
223
|
+
return true;
|
|
224
|
+
return allowedContentTypes.some((allowed) => {
|
|
225
|
+
if (allowed.endsWith('/*')) {
|
|
226
|
+
return contentType.startsWith(`${allowed.slice(0, -2)}/`);
|
|
227
|
+
}
|
|
228
|
+
return contentType === allowed;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function validateMediaAttachmentMetadata(input, policy) {
|
|
232
|
+
const resolvedPolicy = resolvePolicy(policy);
|
|
233
|
+
assertMetadataString(input.contentType, 'contentType');
|
|
234
|
+
assertOptionalMetadataString(input.fileName, 'fileName');
|
|
235
|
+
assertOptionalMetadataString(input.caption, 'caption');
|
|
236
|
+
assertOptionalMetadataString(input.blurHash, 'blurHash');
|
|
237
|
+
assertOptionalMetadataString(input.thumbnail, 'thumbnail');
|
|
238
|
+
assertOptionalMetadataString(input.clientUuid, 'clientUuid');
|
|
239
|
+
assertOptionalMetadataInteger(input.size, 'size', { allowZero: true });
|
|
240
|
+
assertOptionalMetadataInteger(input.ciphertextSize, 'ciphertextSize');
|
|
241
|
+
assertOptionalMetadataInteger(input.width, 'width');
|
|
242
|
+
assertOptionalMetadataInteger(input.height, 'height');
|
|
243
|
+
assertOptionalMetadataInteger(input.durationMs, 'durationMs', {
|
|
244
|
+
allowZero: true,
|
|
245
|
+
});
|
|
246
|
+
assertOptionalMetadataInteger(input.flags, 'flags', { allowZero: true });
|
|
247
|
+
assertOptionalMetadataInteger(input.cdnNumber, 'cdnNumber');
|
|
248
|
+
assertOptionalMetadataBoolean(input.isViewOnce, 'isViewOnce');
|
|
249
|
+
assertOptionalMetadataWaveform(input.waveform);
|
|
250
|
+
assertPolicy(input.clientUuid === undefined || UUID_PATTERN.test(input.clientUuid), 'Media attachment clientUuid must be a UUID string');
|
|
251
|
+
assertPolicy(input.flags === undefined || isMediaAttachmentFlagSet(input.flags), 'Media attachment flags contains unknown media flag bits');
|
|
252
|
+
assertPolicy(input.size === undefined || input.size <= resolvedPolicy.maxPlaintextSizeBytes, `Media attachment plaintext size ${input.size} exceeds limit ${resolvedPolicy.maxPlaintextSizeBytes}`);
|
|
253
|
+
assertPolicy(input.ciphertextSize === undefined ||
|
|
254
|
+
input.ciphertextSize <= resolvedPolicy.maxCiphertextSizeBytes, `Media attachment ciphertext size ${input.ciphertextSize} exceeds limit ${resolvedPolicy.maxCiphertextSizeBytes}`);
|
|
255
|
+
assertPolicy(isContentTypeAllowed(input.contentType, resolvedPolicy.allowedContentTypes), `Media attachment content type ${input.contentType} is not allowed`);
|
|
256
|
+
assertPolicy(input.fileName === undefined || input.fileName.length <= resolvedPolicy.maxFileNameLength, `Media attachment file name exceeds limit ${resolvedPolicy.maxFileNameLength}`);
|
|
257
|
+
assertPolicy(input.caption === undefined || input.caption.length <= resolvedPolicy.maxCaptionLength, `Media attachment caption exceeds limit ${resolvedPolicy.maxCaptionLength}`);
|
|
258
|
+
assertPolicy(input.width === undefined || input.width <= resolvedPolicy.maxWidth, `Media attachment width ${input.width} exceeds limit ${resolvedPolicy.maxWidth}`);
|
|
259
|
+
assertPolicy(input.height === undefined || input.height <= resolvedPolicy.maxHeight, `Media attachment height ${input.height} exceeds limit ${resolvedPolicy.maxHeight}`);
|
|
260
|
+
assertPolicy(input.durationMs === undefined || input.durationMs <= resolvedPolicy.maxDurationMs, `Media attachment duration ${input.durationMs} exceeds limit ${resolvedPolicy.maxDurationMs}`);
|
|
261
|
+
assertPolicy(input.thumbnail === undefined ||
|
|
262
|
+
getBase64ByteLength(input.thumbnail, 'thumbnail') <= resolvedPolicy.maxThumbnailBytes, `Media attachment thumbnail exceeds limit ${resolvedPolicy.maxThumbnailBytes}`);
|
|
263
|
+
assertPolicy(input.waveform === undefined || input.waveform.length <= resolvedPolicy.maxWaveformSamples, `Media attachment waveform exceeds limit ${resolvedPolicy.maxWaveformSamples}`);
|
|
264
|
+
}
|
|
265
|
+
export function validateMediaAttachmentPolicy(attachment, policy) {
|
|
266
|
+
const pointer = createMediaAttachmentPointer(attachment);
|
|
267
|
+
validateMediaAttachmentMetadata(pointer, policy);
|
|
268
|
+
return pointer;
|
|
269
|
+
}
|
|
270
|
+
function copyOptionalString(target, source, field) {
|
|
271
|
+
const value = source[field];
|
|
272
|
+
if (value === undefined)
|
|
273
|
+
return;
|
|
274
|
+
assertString(value, field);
|
|
275
|
+
target[field] = value;
|
|
276
|
+
}
|
|
277
|
+
function copyOptionalClientUuid(target, source) {
|
|
278
|
+
const value = source.clientUuid;
|
|
279
|
+
if (value === undefined)
|
|
280
|
+
return;
|
|
281
|
+
assertString(value, 'clientUuid');
|
|
282
|
+
if (!UUID_PATTERN.test(value)) {
|
|
283
|
+
throw new TypeError('Invalid media attachment pointer: clientUuid must be a UUID string');
|
|
284
|
+
}
|
|
285
|
+
target.clientUuid = value;
|
|
286
|
+
}
|
|
287
|
+
function copyOptionalThumbnail(target, source) {
|
|
288
|
+
const value = source.thumbnail;
|
|
289
|
+
if (value === undefined)
|
|
290
|
+
return;
|
|
291
|
+
assertString(value, 'thumbnail');
|
|
292
|
+
assertBase64String(value, 'thumbnail');
|
|
293
|
+
target.thumbnail = value;
|
|
294
|
+
}
|
|
295
|
+
function getBase64ByteLength(value, field) {
|
|
296
|
+
try {
|
|
297
|
+
return base64ToBytes(toBase64(value)).length;
|
|
298
|
+
}
|
|
299
|
+
catch (cause) {
|
|
300
|
+
throw new MediaAttachmentError(`Media attachment ${field} must be base64 encoded`, MediaAttachmentErrorCode.PolicyViolation, { cause });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function copyOptionalInteger(target, source, field) {
|
|
304
|
+
const value = source[field];
|
|
305
|
+
if (value === undefined)
|
|
306
|
+
return;
|
|
307
|
+
assertInteger(value, field, { allowZero: field === 'durationMs' });
|
|
308
|
+
target[field] = value;
|
|
309
|
+
}
|
|
310
|
+
function copyOptionalFlags(target, source) {
|
|
311
|
+
const value = source.flags;
|
|
312
|
+
if (value === undefined)
|
|
313
|
+
return;
|
|
314
|
+
assertInteger(value, 'flags', { allowZero: true });
|
|
315
|
+
if (!isMediaAttachmentFlagSet(value)) {
|
|
316
|
+
throw new TypeError('Invalid media attachment pointer: flags contains unknown media flag bits');
|
|
317
|
+
}
|
|
318
|
+
target.flags = value;
|
|
319
|
+
}
|
|
320
|
+
function copyOptionalWaveform(target, source) {
|
|
321
|
+
if (source.waveform === undefined)
|
|
322
|
+
return;
|
|
323
|
+
if (!Array.isArray(source.waveform) ||
|
|
324
|
+
!source.waveform.every((sample) => typeof sample === 'number' && Number.isInteger(sample) && sample >= 0 && sample <= 255)) {
|
|
325
|
+
throw new TypeError('Invalid media attachment pointer: waveform must contain integer samples from 0 to 255');
|
|
326
|
+
}
|
|
327
|
+
target.waveform = [...source.waveform];
|
|
328
|
+
}
|
|
329
|
+
export function createMediaAttachmentPointer(input) {
|
|
330
|
+
assertString(input.storageId, 'storageId');
|
|
331
|
+
assertString(input.key, 'key');
|
|
332
|
+
assertString(input.digest, 'digest');
|
|
333
|
+
assertBase64ByteLength(input.key, 'key', MEDIA_ATTACHMENT_KEY_BYTES);
|
|
334
|
+
assertBase64ByteLength(input.digest, 'digest', MEDIA_ATTACHMENT_DIGEST_BYTES);
|
|
335
|
+
assertString(input.contentType, 'contentType');
|
|
336
|
+
assertInteger(input.segmentSize, 'segmentSize');
|
|
337
|
+
assertInteger(input.ciphertextSize, 'ciphertextSize');
|
|
338
|
+
assertInteger(input.size, 'size', { allowZero: true });
|
|
339
|
+
assertInteger(input.uploadTimestamp, 'uploadTimestamp');
|
|
340
|
+
const pointer = {
|
|
341
|
+
version: 1,
|
|
342
|
+
storageId: input.storageId,
|
|
343
|
+
key: input.key,
|
|
344
|
+
digest: input.digest,
|
|
345
|
+
segmentSize: input.segmentSize,
|
|
346
|
+
ciphertextSize: input.ciphertextSize,
|
|
347
|
+
contentType: input.contentType,
|
|
348
|
+
size: input.size,
|
|
349
|
+
uploadTimestamp: input.uploadTimestamp,
|
|
350
|
+
};
|
|
351
|
+
copyOptionalClientUuid(pointer, input);
|
|
352
|
+
copyOptionalString(pointer, input, 'blurHash');
|
|
353
|
+
copyOptionalThumbnail(pointer, input);
|
|
354
|
+
copyOptionalString(pointer, input, 'fileName');
|
|
355
|
+
copyOptionalString(pointer, input, 'caption');
|
|
356
|
+
copyOptionalInteger(pointer, input, 'cdnNumber');
|
|
357
|
+
copyOptionalInteger(pointer, input, 'width');
|
|
358
|
+
copyOptionalInteger(pointer, input, 'height');
|
|
359
|
+
copyOptionalInteger(pointer, input, 'durationMs');
|
|
360
|
+
copyOptionalFlags(pointer, input);
|
|
361
|
+
copyOptionalWaveform(pointer, input);
|
|
362
|
+
if (input.isViewOnce !== undefined) {
|
|
363
|
+
if (typeof input.isViewOnce !== 'boolean') {
|
|
364
|
+
throw new TypeError('Invalid media attachment pointer: isViewOnce must be a boolean');
|
|
365
|
+
}
|
|
366
|
+
pointer.isViewOnce = input.isViewOnce;
|
|
367
|
+
}
|
|
368
|
+
return pointer;
|
|
369
|
+
}
|
|
370
|
+
function encodeAttachmentIdentityPart(value) {
|
|
371
|
+
return bytesToUrlSafeBase64(new TextEncoder().encode(value));
|
|
372
|
+
}
|
|
373
|
+
export function createMediaAttachmentId(attachment) {
|
|
374
|
+
const pointer = createMediaAttachmentPointer(attachment);
|
|
375
|
+
return [
|
|
376
|
+
'media-v1',
|
|
377
|
+
encodeAttachmentIdentityPart(pointer.storageId),
|
|
378
|
+
pointer.ciphertextSize,
|
|
379
|
+
encodeAttachmentIdentityPart(pointer.digest),
|
|
380
|
+
].join('.');
|
|
381
|
+
}
|
|
382
|
+
export function createMediaAttachmentDeliveryId(input) {
|
|
383
|
+
assertString(input.senderUserId, 'senderUserId');
|
|
384
|
+
assertInteger(input.timestamp, 'timestamp');
|
|
385
|
+
return [
|
|
386
|
+
'media-delivery-v1',
|
|
387
|
+
encodeAttachmentIdentityPart(input.senderUserId),
|
|
388
|
+
input.timestamp,
|
|
389
|
+
createMediaAttachmentId(input.attachment),
|
|
390
|
+
].join('.');
|
|
391
|
+
}
|
|
392
|
+
function knownIdsIncludes(ids, id) {
|
|
393
|
+
if (!ids)
|
|
394
|
+
return false;
|
|
395
|
+
const candidate = ids;
|
|
396
|
+
if (typeof candidate.has === 'function') {
|
|
397
|
+
return candidate.has(id);
|
|
398
|
+
}
|
|
399
|
+
return ids.includes(id);
|
|
400
|
+
}
|
|
401
|
+
function assertMediaAttachmentCleanupReason(reason) {
|
|
402
|
+
if (!isMediaAttachmentCleanupReason(reason)) {
|
|
403
|
+
throw new TypeError('Invalid media attachment cleanup reason');
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function isMediaAttachmentCleanupReason(value) {
|
|
407
|
+
return (value === MediaAttachmentCleanupReason.ViewOnceOpened ||
|
|
408
|
+
value === MediaAttachmentCleanupReason.MessageDeleted ||
|
|
409
|
+
value === MediaAttachmentCleanupReason.MessageExpired ||
|
|
410
|
+
value === MediaAttachmentCleanupReason.OrphanedUpload);
|
|
411
|
+
}
|
|
412
|
+
function assertMediaAttachmentJobSource(source) {
|
|
413
|
+
if (!Object.values(MediaAttachmentJobSource).includes(source)) {
|
|
414
|
+
throw new TypeError('Invalid media attachment job source');
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function assertMediaAttachmentJobPriority(priority) {
|
|
418
|
+
if (!Object.values(MediaAttachmentJobPriority).includes(priority)) {
|
|
419
|
+
throw new TypeError('Invalid media attachment job priority');
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function createMediaAttachmentBackgroundJob(input) {
|
|
423
|
+
assertString(input.attachmentId, 'attachmentId');
|
|
424
|
+
assertMediaAttachmentJobSource(input.source);
|
|
425
|
+
const priority = input.priority ?? MediaAttachmentJobPriority.Normal;
|
|
426
|
+
assertMediaAttachmentJobPriority(priority);
|
|
427
|
+
const attempt = input.attempt ?? 0;
|
|
428
|
+
const createdAt = input.createdAt ?? Date.now();
|
|
429
|
+
const notBefore = input.notBefore ?? createdAt;
|
|
430
|
+
assertInteger(attempt, 'attempt', { allowZero: true });
|
|
431
|
+
assertInteger(createdAt, 'createdAt', { allowZero: true });
|
|
432
|
+
assertInteger(notBefore, 'notBefore', { allowZero: true });
|
|
433
|
+
const jobId = [
|
|
434
|
+
'media-job-v1',
|
|
435
|
+
input.operation,
|
|
436
|
+
encodeAttachmentIdentityPart(input.attachmentId),
|
|
437
|
+
input.deliveryId ? encodeAttachmentIdentityPart(input.deliveryId) : 'none',
|
|
438
|
+
input.reason ? encodeAttachmentIdentityPart(input.reason) : 'none',
|
|
439
|
+
].join('.');
|
|
440
|
+
return {
|
|
441
|
+
jobId,
|
|
442
|
+
operation: input.operation,
|
|
443
|
+
source: input.source,
|
|
444
|
+
priority,
|
|
445
|
+
requiresNetwork: input.requiresNetwork,
|
|
446
|
+
attachmentId: input.attachmentId,
|
|
447
|
+
storageId: input.storageId,
|
|
448
|
+
deliveryId: input.deliveryId,
|
|
449
|
+
reason: input.reason,
|
|
450
|
+
attempt,
|
|
451
|
+
createdAt,
|
|
452
|
+
notBefore,
|
|
453
|
+
resume: input.resume,
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
export function planMediaAttachmentUploadJob(input) {
|
|
457
|
+
assertString(input.localMediaId, 'localMediaId');
|
|
458
|
+
assertString(input.contentType, 'contentType');
|
|
459
|
+
assertInteger(input.size, 'size', { allowZero: true });
|
|
460
|
+
validateMediaAttachmentMetadata({
|
|
461
|
+
contentType: input.contentType,
|
|
462
|
+
size: input.size,
|
|
463
|
+
fileName: input.fileName,
|
|
464
|
+
caption: input.caption,
|
|
465
|
+
blurHash: input.blurHash,
|
|
466
|
+
width: input.width,
|
|
467
|
+
height: input.height,
|
|
468
|
+
durationMs: input.durationMs,
|
|
469
|
+
thumbnail: input.thumbnail,
|
|
470
|
+
waveform: input.waveform,
|
|
471
|
+
isViewOnce: input.isViewOnce,
|
|
472
|
+
flags: input.flags,
|
|
473
|
+
clientUuid: input.clientUuid,
|
|
474
|
+
cdnNumber: input.cdnNumber,
|
|
475
|
+
}, input.policy);
|
|
476
|
+
return createMediaAttachmentBackgroundJob({
|
|
477
|
+
operation: MediaAttachmentJobOperation.Upload,
|
|
478
|
+
source: input.source ?? MediaAttachmentJobSource.ComposePreUpload,
|
|
479
|
+
priority: input.priority ?? MediaAttachmentJobPriority.Normal,
|
|
480
|
+
requiresNetwork: true,
|
|
481
|
+
attachmentId: `upload-v1.${encodeAttachmentIdentityPart(input.localMediaId)}`,
|
|
482
|
+
reason: input.contentType,
|
|
483
|
+
attempt: input.attempt,
|
|
484
|
+
createdAt: input.createdAt,
|
|
485
|
+
notBefore: input.notBefore,
|
|
486
|
+
resume: input.resume,
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
export function planMediaAttachmentCleanup(attachment, reason) {
|
|
490
|
+
assertMediaAttachmentCleanupReason(reason);
|
|
491
|
+
const pointer = createMediaAttachmentPointer(attachment);
|
|
492
|
+
return {
|
|
493
|
+
storageId: pointer.storageId,
|
|
494
|
+
attachmentId: createMediaAttachmentId(pointer),
|
|
495
|
+
reason,
|
|
496
|
+
deleteLocalCache: true,
|
|
497
|
+
deleteRemoteBlob: reason === MediaAttachmentCleanupReason.MessageDeleted ||
|
|
498
|
+
reason === MediaAttachmentCleanupReason.MessageExpired ||
|
|
499
|
+
reason === MediaAttachmentCleanupReason.OrphanedUpload,
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
export function planMediaAttachmentCleanupJobs(input) {
|
|
503
|
+
const source = input.source ?? MediaAttachmentJobSource.BackgroundRecovery;
|
|
504
|
+
const includeLocal = input.includeLocal ?? input.cleanup.deleteLocalCache;
|
|
505
|
+
const includeRemote = input.includeRemote ?? input.cleanup.deleteRemoteBlob;
|
|
506
|
+
const includeSync = input.includeSync ?? false;
|
|
507
|
+
const jobs = [];
|
|
508
|
+
if (includeLocal) {
|
|
509
|
+
jobs.push(createMediaAttachmentBackgroundJob({
|
|
510
|
+
operation: MediaAttachmentJobOperation.DeleteLocal,
|
|
511
|
+
source,
|
|
512
|
+
priority: input.priority ?? MediaAttachmentJobPriority.Normal,
|
|
513
|
+
requiresNetwork: false,
|
|
514
|
+
attachmentId: input.cleanup.attachmentId,
|
|
515
|
+
storageId: input.cleanup.storageId,
|
|
516
|
+
reason: input.cleanup.reason,
|
|
517
|
+
attempt: input.attempt,
|
|
518
|
+
createdAt: input.createdAt,
|
|
519
|
+
notBefore: input.notBefore,
|
|
520
|
+
}));
|
|
521
|
+
}
|
|
522
|
+
if (includeRemote) {
|
|
523
|
+
jobs.push(createMediaAttachmentBackgroundJob({
|
|
524
|
+
operation: MediaAttachmentJobOperation.DeleteRemote,
|
|
525
|
+
source,
|
|
526
|
+
priority: input.priority ?? MediaAttachmentJobPriority.Normal,
|
|
527
|
+
requiresNetwork: true,
|
|
528
|
+
attachmentId: input.cleanup.attachmentId,
|
|
529
|
+
storageId: input.cleanup.storageId,
|
|
530
|
+
reason: input.cleanup.reason,
|
|
531
|
+
attempt: input.attempt,
|
|
532
|
+
createdAt: input.createdAt,
|
|
533
|
+
notBefore: input.notBefore,
|
|
534
|
+
}));
|
|
535
|
+
}
|
|
536
|
+
if (includeSync) {
|
|
537
|
+
jobs.push(createMediaAttachmentBackgroundJob({
|
|
538
|
+
operation: MediaAttachmentJobOperation.SyncDelete,
|
|
539
|
+
source: MediaAttachmentJobSource.LinkedDeviceSync,
|
|
540
|
+
priority: input.priority ?? MediaAttachmentJobPriority.Normal,
|
|
541
|
+
requiresNetwork: true,
|
|
542
|
+
attachmentId: input.cleanup.attachmentId,
|
|
543
|
+
storageId: input.cleanup.storageId,
|
|
544
|
+
reason: input.cleanup.reason,
|
|
545
|
+
attempt: input.attempt,
|
|
546
|
+
createdAt: input.createdAt,
|
|
547
|
+
notBefore: input.notBefore,
|
|
548
|
+
}));
|
|
549
|
+
}
|
|
550
|
+
return jobs;
|
|
551
|
+
}
|
|
552
|
+
export function planMediaAttachmentOpen(input) {
|
|
553
|
+
const attachment = createMediaAttachmentPointer(input.attachment);
|
|
554
|
+
assertString(input.senderUserId, 'senderUserId');
|
|
555
|
+
assertInteger(input.timestamp, 'timestamp');
|
|
556
|
+
if (!attachment.isViewOnce) {
|
|
557
|
+
return {
|
|
558
|
+
attachment,
|
|
559
|
+
isViewOnce: false,
|
|
560
|
+
cleanup: null,
|
|
561
|
+
viewOnceOpenSync: null,
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
attachment,
|
|
566
|
+
isViewOnce: true,
|
|
567
|
+
cleanup: planMediaAttachmentCleanup(attachment, MediaAttachmentCleanupReason.ViewOnceOpened),
|
|
568
|
+
viewOnceOpenSync: {
|
|
569
|
+
senderUserId: input.senderUserId,
|
|
570
|
+
timestamp: input.timestamp,
|
|
571
|
+
},
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
export function planMediaAttachmentProcessing(input) {
|
|
575
|
+
const attachment = createMediaAttachmentPointer(input.attachment);
|
|
576
|
+
assertString(input.senderUserId, 'senderUserId');
|
|
577
|
+
assertInteger(input.timestamp, 'timestamp');
|
|
578
|
+
const attachmentId = createMediaAttachmentId(attachment);
|
|
579
|
+
const deliveryId = createMediaAttachmentDeliveryId({
|
|
580
|
+
attachment,
|
|
581
|
+
senderUserId: input.senderUserId,
|
|
582
|
+
timestamp: input.timestamp,
|
|
583
|
+
});
|
|
584
|
+
const isDuplicateDelivery = knownIdsIncludes(input.processedDeliveryIds, deliveryId);
|
|
585
|
+
const hasLocalCopy = knownIdsIncludes(input.cachedAttachmentIds, attachmentId);
|
|
586
|
+
const isViewOnceOpened = attachment.isViewOnce === true && knownIdsIncludes(input.openedViewOnceDeliveryIds, deliveryId);
|
|
587
|
+
const shouldDownload = !hasLocalCopy && !isViewOnceOpened;
|
|
588
|
+
const downloadReason = shouldDownload
|
|
589
|
+
? isDuplicateDelivery
|
|
590
|
+
? 'duplicate-missing-local-copy'
|
|
591
|
+
: 'new-delivery'
|
|
592
|
+
: null;
|
|
593
|
+
return {
|
|
594
|
+
attachment,
|
|
595
|
+
attachmentId,
|
|
596
|
+
deliveryId,
|
|
597
|
+
isDuplicateDelivery,
|
|
598
|
+
hasLocalCopy,
|
|
599
|
+
isViewOnceOpened,
|
|
600
|
+
shouldPersistMessage: !isDuplicateDelivery,
|
|
601
|
+
shouldDownload,
|
|
602
|
+
downloadReason,
|
|
603
|
+
downloadJob: shouldDownload && downloadReason
|
|
604
|
+
? createMediaAttachmentBackgroundJob({
|
|
605
|
+
operation: MediaAttachmentJobOperation.Download,
|
|
606
|
+
source: input.jobSource ?? MediaAttachmentJobSource.IncomingMessage,
|
|
607
|
+
priority: input.jobPriority ?? MediaAttachmentJobPriority.Normal,
|
|
608
|
+
requiresNetwork: true,
|
|
609
|
+
attachmentId,
|
|
610
|
+
storageId: attachment.storageId,
|
|
611
|
+
deliveryId,
|
|
612
|
+
reason: downloadReason,
|
|
613
|
+
attempt: input.jobAttempt,
|
|
614
|
+
createdAt: input.jobCreatedAt ?? input.timestamp,
|
|
615
|
+
notBefore: input.jobNotBefore ?? input.jobCreatedAt ?? input.timestamp,
|
|
616
|
+
resume: input.resume,
|
|
617
|
+
})
|
|
618
|
+
: null,
|
|
619
|
+
cleanup: isViewOnceOpened
|
|
620
|
+
? planMediaAttachmentCleanup(attachment, MediaAttachmentCleanupReason.ViewOnceOpened)
|
|
621
|
+
: null,
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
export function planMediaAttachmentDownloadJob(input) {
|
|
625
|
+
return planMediaAttachmentProcessing({
|
|
626
|
+
...input,
|
|
627
|
+
jobSource: input.source ?? MediaAttachmentJobSource.IncomingMessage,
|
|
628
|
+
jobPriority: input.priority ?? MediaAttachmentJobPriority.Normal,
|
|
629
|
+
jobCreatedAt: input.createdAt,
|
|
630
|
+
jobNotBefore: input.notBefore,
|
|
631
|
+
jobAttempt: input.attempt,
|
|
632
|
+
resume: input.resume,
|
|
633
|
+
}).downloadJob;
|
|
634
|
+
}
|
|
635
|
+
export function planMediaAttachmentDeleteSync(input) {
|
|
636
|
+
assertInteger(input.deletedAt, 'deletedAt');
|
|
637
|
+
assertMediaAttachmentCleanupReason(input.reason);
|
|
638
|
+
const attachment = createMediaAttachmentPointer(input.attachment);
|
|
639
|
+
return {
|
|
640
|
+
storageId: attachment.storageId,
|
|
641
|
+
attachmentId: createMediaAttachmentId(attachment),
|
|
642
|
+
reason: input.reason,
|
|
643
|
+
deletedAt: input.deletedAt,
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
function requireMediaAttachmentJobHandler(handler, name, operation) {
|
|
647
|
+
if (handler !== undefined)
|
|
648
|
+
return handler;
|
|
649
|
+
throw new MediaAttachmentError(`Cannot execute media attachment ${operation} job: ${name} handler is required`, MediaAttachmentErrorCode.JobHandlerMissing);
|
|
650
|
+
}
|
|
651
|
+
function completedMediaAttachmentJob(job, result = {}) {
|
|
652
|
+
return {
|
|
653
|
+
job,
|
|
654
|
+
status: MediaAttachmentJobExecutionStatus.Completed,
|
|
655
|
+
...result,
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
function skippedMediaAttachmentJob(job, skipReason) {
|
|
659
|
+
return {
|
|
660
|
+
job,
|
|
661
|
+
status: MediaAttachmentJobExecutionStatus.Skipped,
|
|
662
|
+
skipReason,
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
async function loadRequiredAttachmentPointer(job, options) {
|
|
666
|
+
const loadAttachmentPointer = requireMediaAttachmentJobHandler(options.loadAttachmentPointer, 'loadAttachmentPointer', job.operation);
|
|
667
|
+
const attachment = await loadAttachmentPointer(job);
|
|
668
|
+
return attachment ? createMediaAttachmentPointer(attachment) : null;
|
|
669
|
+
}
|
|
670
|
+
export async function executeMediaAttachmentJob(job, options) {
|
|
671
|
+
switch (job.operation) {
|
|
672
|
+
case MediaAttachmentJobOperation.Upload: {
|
|
673
|
+
const loadUploadData = requireMediaAttachmentJobHandler(options.loadUploadData, 'loadUploadData', job.operation);
|
|
674
|
+
const uploadData = await loadUploadData(job);
|
|
675
|
+
if (!uploadData) {
|
|
676
|
+
return skippedMediaAttachmentJob(job, 'missing-upload-data');
|
|
677
|
+
}
|
|
678
|
+
const attachment = await prepareMediaAttachmentUpload(uploadData.data, {
|
|
679
|
+
...uploadData.options,
|
|
680
|
+
remoteObjectStore: options.remoteObjectStore,
|
|
681
|
+
transfer: uploadData.options?.transfer ?? options.transfer,
|
|
682
|
+
retry: uploadData.options?.retry ?? options.retry,
|
|
683
|
+
policy: uploadData.options?.policy ?? options.policy,
|
|
684
|
+
signal: uploadData.options?.signal ?? options.signal,
|
|
685
|
+
onProgress: uploadData.options?.onProgress ?? options.onProgress,
|
|
686
|
+
onCheckpoint: uploadData.options?.onCheckpoint ?? options.onCheckpoint,
|
|
687
|
+
resume: uploadData.options?.resume ?? job.resume,
|
|
688
|
+
});
|
|
689
|
+
await options.saveUploadedAttachment?.(job, attachment);
|
|
690
|
+
return completedMediaAttachmentJob(job, {
|
|
691
|
+
uploadedAttachment: attachment,
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
case MediaAttachmentJobOperation.Download: {
|
|
695
|
+
const attachment = await loadRequiredAttachmentPointer(job, options);
|
|
696
|
+
if (!attachment) {
|
|
697
|
+
return skippedMediaAttachmentJob(job, 'missing-attachment-pointer');
|
|
698
|
+
}
|
|
699
|
+
const downloadedAttachment = await resolveMediaAttachment(attachment, {
|
|
700
|
+
remoteObjectStore: options.remoteObjectStore,
|
|
701
|
+
transfer: options.transfer,
|
|
702
|
+
retry: options.retry,
|
|
703
|
+
policy: options.policy,
|
|
704
|
+
signal: options.signal,
|
|
705
|
+
onProgress: options.onProgress,
|
|
706
|
+
onCheckpoint: options.onCheckpoint,
|
|
707
|
+
resume: job.resume,
|
|
708
|
+
});
|
|
709
|
+
await options.saveDownloadedAttachment?.(job, downloadedAttachment);
|
|
710
|
+
return completedMediaAttachmentJob(job, { downloadedAttachment });
|
|
711
|
+
}
|
|
712
|
+
case MediaAttachmentJobOperation.DeleteLocal: {
|
|
713
|
+
const deleteLocalAttachment = requireMediaAttachmentJobHandler(options.deleteLocalAttachment, 'deleteLocalAttachment', job.operation);
|
|
714
|
+
await deleteLocalAttachment(job);
|
|
715
|
+
return completedMediaAttachmentJob(job, { deletedLocalCache: true });
|
|
716
|
+
}
|
|
717
|
+
case MediaAttachmentJobOperation.DeleteRemote: {
|
|
718
|
+
const attachment = await loadRequiredAttachmentPointer(job, options);
|
|
719
|
+
if (!attachment) {
|
|
720
|
+
return skippedMediaAttachmentJob(job, 'missing-attachment-pointer');
|
|
721
|
+
}
|
|
722
|
+
const result = await deleteMediaAttachment(attachment, {
|
|
723
|
+
remoteObjectStore: options.remoteObjectStore,
|
|
724
|
+
signal: options.signal,
|
|
725
|
+
onProgress: options.onProgress,
|
|
726
|
+
});
|
|
727
|
+
return completedMediaAttachmentJob(job, {
|
|
728
|
+
deletedRemoteObject: result.deletedRemoteObject,
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
case MediaAttachmentJobOperation.SyncDelete: {
|
|
732
|
+
if (!options.syncDelete) {
|
|
733
|
+
return skippedMediaAttachmentJob(job, 'sync-delete-not-configured');
|
|
734
|
+
}
|
|
735
|
+
const attachment = await loadRequiredAttachmentPointer(job, options);
|
|
736
|
+
if (!attachment) {
|
|
737
|
+
return skippedMediaAttachmentJob(job, 'missing-attachment-pointer');
|
|
738
|
+
}
|
|
739
|
+
const deleteSync = planMediaAttachmentDeleteSync({
|
|
740
|
+
attachment,
|
|
741
|
+
reason: isMediaAttachmentCleanupReason(job.reason)
|
|
742
|
+
? job.reason
|
|
743
|
+
: MediaAttachmentCleanupReason.MessageDeleted,
|
|
744
|
+
deletedAt: Date.now(),
|
|
745
|
+
});
|
|
746
|
+
await options.syncDelete(job, deleteSync);
|
|
747
|
+
return completedMediaAttachmentJob(job, { deleteSync });
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
export function createMediaAttachmentMessage(input) {
|
|
752
|
+
assertInteger(input.timestamp, 'timestamp');
|
|
753
|
+
return {
|
|
754
|
+
type: MediaAttachmentMessageType.Attachment,
|
|
755
|
+
version: 1,
|
|
756
|
+
timestamp: input.timestamp,
|
|
757
|
+
attachment: createMediaAttachmentPointer(input.attachment),
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
export function serializeMediaAttachmentMessage(input) {
|
|
761
|
+
return JSON.stringify(createMediaAttachmentMessage(input));
|
|
762
|
+
}
|
|
763
|
+
function isRecord(value) {
|
|
764
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
765
|
+
}
|
|
766
|
+
function assertNotAborted(signal) {
|
|
767
|
+
if (!signal?.aborted)
|
|
768
|
+
return;
|
|
769
|
+
throw new MediaAttachmentError('Media attachment operation cancelled', MediaAttachmentErrorCode.Cancelled, { cause: signal.reason });
|
|
770
|
+
}
|
|
771
|
+
function emitProgress(onProgress, progress) {
|
|
772
|
+
onProgress?.(progress);
|
|
773
|
+
}
|
|
774
|
+
function emitCheckpoint(onCheckpoint, checkpoint) {
|
|
775
|
+
onCheckpoint?.({
|
|
776
|
+
...checkpoint,
|
|
777
|
+
updatedAt: Date.now(),
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
function createResumeStateFromCheckpoint(checkpoint, previous) {
|
|
781
|
+
if (checkpoint.phase !== 'transfer') {
|
|
782
|
+
return previous;
|
|
783
|
+
}
|
|
784
|
+
const offsetBytes = Number.isInteger(checkpoint.bytesTransferred)
|
|
785
|
+
? Math.max(checkpoint.bytesTransferred ?? 0, 0)
|
|
786
|
+
: previous?.offsetBytes;
|
|
787
|
+
const resumeToken = checkpoint.resumeToken ?? previous?.resumeToken;
|
|
788
|
+
if (offsetBytes === undefined && resumeToken === undefined) {
|
|
789
|
+
return previous;
|
|
790
|
+
}
|
|
791
|
+
return {
|
|
792
|
+
operation: checkpoint.operation,
|
|
793
|
+
...(offsetBytes !== undefined ? { offsetBytes } : {}),
|
|
794
|
+
...(resumeToken !== undefined ? { resumeToken } : {}),
|
|
795
|
+
updatedAt: checkpoint.updatedAt,
|
|
796
|
+
...(previous?.expiresAt !== undefined ? { expiresAt: previous.expiresAt } : {}),
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
function trackResumeCheckpoints(operation, onCheckpoint, setResume, getResume) {
|
|
800
|
+
return (checkpoint) => {
|
|
801
|
+
if (checkpoint.operation === operation) {
|
|
802
|
+
const nextResume = createResumeStateFromCheckpoint(checkpoint, getResume());
|
|
803
|
+
if (nextResume !== getResume()) {
|
|
804
|
+
setResume(nextResume);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
onCheckpoint?.(checkpoint);
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
export function parseMediaAttachmentMessage(plaintext) {
|
|
811
|
+
let parsed;
|
|
812
|
+
try {
|
|
813
|
+
parsed = JSON.parse(plaintext);
|
|
814
|
+
}
|
|
815
|
+
catch {
|
|
816
|
+
return null;
|
|
817
|
+
}
|
|
818
|
+
if (!isRecord(parsed))
|
|
819
|
+
return null;
|
|
820
|
+
if (parsed.type !== MediaAttachmentMessageType.Attachment)
|
|
821
|
+
return null;
|
|
822
|
+
if (parsed.version !== 1)
|
|
823
|
+
return null;
|
|
824
|
+
if (typeof parsed.timestamp !== 'number')
|
|
825
|
+
return null;
|
|
826
|
+
if (!isRecord(parsed.attachment))
|
|
827
|
+
return null;
|
|
828
|
+
try {
|
|
829
|
+
return createMediaAttachmentMessage({
|
|
830
|
+
timestamp: parsed.timestamp,
|
|
831
|
+
attachment: parsed.attachment,
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
catch {
|
|
835
|
+
return null;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
async function defaultUpload(url, data, options = {}) {
|
|
839
|
+
assertNotAborted(options.signal);
|
|
840
|
+
if (typeof globalThis.fetch !== 'function') {
|
|
841
|
+
throw new MediaAttachmentError('Cannot upload media attachment: fetch is not available', MediaAttachmentErrorCode.UploadFailed);
|
|
842
|
+
}
|
|
843
|
+
emitProgress(options.onProgress, {
|
|
844
|
+
operation: 'upload',
|
|
845
|
+
phase: 'transfer',
|
|
846
|
+
attempt: options.attempt,
|
|
847
|
+
requestId: options.requestId,
|
|
848
|
+
storageId: options.storageId,
|
|
849
|
+
bytesTransferred: 0,
|
|
850
|
+
totalBytes: options.totalBytes ?? data.length,
|
|
851
|
+
});
|
|
852
|
+
emitCheckpoint(options.onCheckpoint, {
|
|
853
|
+
operation: 'upload',
|
|
854
|
+
phase: 'transfer',
|
|
855
|
+
attempt: options.attempt,
|
|
856
|
+
requestId: options.requestId,
|
|
857
|
+
storageId: options.storageId,
|
|
858
|
+
attachmentId: options.attachmentId,
|
|
859
|
+
bytesTransferred: 0,
|
|
860
|
+
totalBytes: options.totalBytes ?? data.length,
|
|
861
|
+
resumeToken: options.resume?.resumeToken,
|
|
862
|
+
});
|
|
863
|
+
const body = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
864
|
+
const response = await globalThis.fetch(url, {
|
|
865
|
+
method: 'PUT',
|
|
866
|
+
body,
|
|
867
|
+
signal: options.signal,
|
|
868
|
+
headers: {
|
|
869
|
+
'Content-Type': 'application/octet-stream',
|
|
870
|
+
...options.headers,
|
|
871
|
+
},
|
|
872
|
+
});
|
|
873
|
+
assertNotAborted(options.signal);
|
|
874
|
+
if (!response.ok) {
|
|
875
|
+
return {
|
|
876
|
+
ok: false,
|
|
877
|
+
status: response.status,
|
|
878
|
+
statusText: response.statusText,
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
emitProgress(options.onProgress, {
|
|
882
|
+
operation: 'upload',
|
|
883
|
+
phase: 'transfer',
|
|
884
|
+
attempt: options.attempt,
|
|
885
|
+
requestId: options.requestId,
|
|
886
|
+
storageId: options.storageId,
|
|
887
|
+
bytesTransferred: data.length,
|
|
888
|
+
totalBytes: options.totalBytes ?? data.length,
|
|
889
|
+
});
|
|
890
|
+
emitCheckpoint(options.onCheckpoint, {
|
|
891
|
+
operation: 'upload',
|
|
892
|
+
phase: 'complete',
|
|
893
|
+
attempt: options.attempt,
|
|
894
|
+
requestId: options.requestId,
|
|
895
|
+
storageId: options.storageId,
|
|
896
|
+
attachmentId: options.attachmentId,
|
|
897
|
+
bytesTransferred: data.length,
|
|
898
|
+
totalBytes: options.totalBytes ?? data.length,
|
|
899
|
+
resumeToken: options.resume?.resumeToken,
|
|
900
|
+
});
|
|
901
|
+
return {
|
|
902
|
+
ok: response.ok,
|
|
903
|
+
status: response.status,
|
|
904
|
+
statusText: response.statusText,
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
function getFetchImplementation(fetchOverride, operation = 'upload') {
|
|
908
|
+
const fetchImpl = fetchOverride ?? globalThis.fetch;
|
|
909
|
+
if (typeof fetchImpl !== 'function') {
|
|
910
|
+
throw new MediaAttachmentError(`Cannot ${operation} media attachment: fetch is not available`, operation === 'upload'
|
|
911
|
+
? MediaAttachmentErrorCode.UploadFailed
|
|
912
|
+
: MediaAttachmentErrorCode.DownloadFailed);
|
|
913
|
+
}
|
|
914
|
+
return fetchImpl;
|
|
915
|
+
}
|
|
916
|
+
function getHeader(response, header) {
|
|
917
|
+
return response.headers?.get?.(header) ?? response.headers?.get?.(header.toLowerCase()) ?? null;
|
|
918
|
+
}
|
|
919
|
+
function parseTusOffset(value, context) {
|
|
920
|
+
if (value === null) {
|
|
921
|
+
throwInvalidResumeState(`TUS media upload ${context} did not return Upload-Offset`);
|
|
922
|
+
}
|
|
923
|
+
const normalized = value.trim();
|
|
924
|
+
if (!/^\d+$/.test(normalized)) {
|
|
925
|
+
throwInvalidResumeState(`TUS media upload ${context} returned malformed Upload-Offset`);
|
|
926
|
+
}
|
|
927
|
+
const offset = Number(normalized);
|
|
928
|
+
if (!Number.isSafeInteger(offset)) {
|
|
929
|
+
throwInvalidResumeState(`TUS media upload ${context} returned unsafe Upload-Offset`);
|
|
930
|
+
}
|
|
931
|
+
return offset;
|
|
932
|
+
}
|
|
933
|
+
function parseTusCreationOffset(value, totalBytes) {
|
|
934
|
+
if (value === null)
|
|
935
|
+
return 0;
|
|
936
|
+
return assertTusOffsetWithinUpload(parseTusOffset(value, 'creation response'), totalBytes);
|
|
937
|
+
}
|
|
938
|
+
function assertTusOffsetWithinUpload(offset, totalBytes) {
|
|
939
|
+
if (offset > totalBytes) {
|
|
940
|
+
throwInvalidResumeState(`TUS media upload returned Upload-Offset ${offset} beyond ${totalBytes} byte upload`);
|
|
941
|
+
}
|
|
942
|
+
return offset;
|
|
943
|
+
}
|
|
944
|
+
function assertTusPatchAdvancedToExpectedOffset(offset, expectedOffset) {
|
|
945
|
+
if (offset !== expectedOffset) {
|
|
946
|
+
throwInvalidResumeState(`TUS media upload resume offset is invalid: expected ${expectedOffset}, received ${offset}`);
|
|
947
|
+
}
|
|
948
|
+
return offset;
|
|
949
|
+
}
|
|
950
|
+
function assertTusUploadResumeState(resume) {
|
|
951
|
+
if (!resume)
|
|
952
|
+
return;
|
|
953
|
+
if (resume.operation !== 'upload') {
|
|
954
|
+
throwInvalidResumeState('TUS media upload received non-upload resume state');
|
|
955
|
+
}
|
|
956
|
+
if (resume.offsetBytes !== undefined &&
|
|
957
|
+
(!Number.isSafeInteger(resume.offsetBytes) || resume.offsetBytes < 0)) {
|
|
958
|
+
throwInvalidResumeState('TUS media upload resume offset is invalid');
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
function resolveTusChunkSizeBytes(chunkSizeBytes, payloadBytes) {
|
|
962
|
+
const resolved = chunkSizeBytes ?? payloadBytes;
|
|
963
|
+
if (!Number.isSafeInteger(resolved) || resolved <= 0) {
|
|
964
|
+
throw new MediaAttachmentError('TUS media upload chunk size must be a positive safe integer', MediaAttachmentErrorCode.UploadFailed);
|
|
965
|
+
}
|
|
966
|
+
return resolved;
|
|
967
|
+
}
|
|
968
|
+
function resolveTusLocation(location, creationUrl) {
|
|
969
|
+
if (!location) {
|
|
970
|
+
throw new MediaAttachmentError('TUS media upload did not return a resume location', MediaAttachmentErrorCode.UploadFailed);
|
|
971
|
+
}
|
|
972
|
+
return new URL(location, creationUrl).toString();
|
|
973
|
+
}
|
|
974
|
+
function isInvalidTusResumeResponse(response) {
|
|
975
|
+
return (response.status === 400 ||
|
|
976
|
+
response.status === 404 ||
|
|
977
|
+
response.status === 409 ||
|
|
978
|
+
response.status === 410);
|
|
979
|
+
}
|
|
980
|
+
function throwInvalidResumeState(message, status) {
|
|
981
|
+
throw new MediaAttachmentError(message, MediaAttachmentErrorCode.ResumeStateInvalid, { status });
|
|
982
|
+
}
|
|
983
|
+
function sliceBytes(data, start, end) {
|
|
984
|
+
const view = data.subarray(start, end);
|
|
985
|
+
return view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength);
|
|
986
|
+
}
|
|
987
|
+
function emitUploadTransferProgress(options, bytesTransferred, totalBytes, resumeToken) {
|
|
988
|
+
emitProgress(options.onProgress, {
|
|
989
|
+
operation: 'upload',
|
|
990
|
+
phase: 'transfer',
|
|
991
|
+
attempt: options.attempt,
|
|
992
|
+
requestId: options.requestId,
|
|
993
|
+
storageId: options.storageId,
|
|
994
|
+
bytesTransferred,
|
|
995
|
+
totalBytes,
|
|
996
|
+
});
|
|
997
|
+
emitCheckpoint(options.onCheckpoint, {
|
|
998
|
+
operation: 'upload',
|
|
999
|
+
phase: bytesTransferred >= totalBytes ? 'complete' : 'transfer',
|
|
1000
|
+
attempt: options.attempt,
|
|
1001
|
+
requestId: options.requestId,
|
|
1002
|
+
storageId: options.storageId,
|
|
1003
|
+
attachmentId: options.attachmentId,
|
|
1004
|
+
bytesTransferred,
|
|
1005
|
+
totalBytes,
|
|
1006
|
+
resumeToken,
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
export function createTusMediaAttachmentTransfer(tusOptions = {}) {
|
|
1010
|
+
return {
|
|
1011
|
+
async upload(creationUrl, data, options = {}) {
|
|
1012
|
+
assertNotAborted(options.signal);
|
|
1013
|
+
const fetchImpl = getFetchImplementation(tusOptions.fetch);
|
|
1014
|
+
const tusVersion = tusOptions.tusVersion ?? '1.0.0';
|
|
1015
|
+
const totalBytes = options.totalBytes ?? data.length;
|
|
1016
|
+
if (totalBytes !== data.length) {
|
|
1017
|
+
throw new MediaAttachmentError(`TUS media upload length mismatch: totalBytes ${totalBytes} does not match payload length ${data.length}`, MediaAttachmentErrorCode.UploadFailed);
|
|
1018
|
+
}
|
|
1019
|
+
assertTusUploadResumeState(options.resume);
|
|
1020
|
+
const chunkSizeBytes = resolveTusChunkSizeBytes(tusOptions.chunkSizeBytes, data.length);
|
|
1021
|
+
let resumeUrl = options.resume?.resumeToken;
|
|
1022
|
+
let offset = options.resume?.offsetBytes ?? 0;
|
|
1023
|
+
if (resumeUrl) {
|
|
1024
|
+
const head = await fetchImpl(resumeUrl, {
|
|
1025
|
+
method: 'HEAD',
|
|
1026
|
+
signal: options.signal,
|
|
1027
|
+
headers: {
|
|
1028
|
+
...options.headers,
|
|
1029
|
+
'Tus-Resumable': tusVersion,
|
|
1030
|
+
},
|
|
1031
|
+
});
|
|
1032
|
+
assertNotAborted(options.signal);
|
|
1033
|
+
if (!head.ok) {
|
|
1034
|
+
if (isInvalidTusResumeResponse(head)) {
|
|
1035
|
+
throwInvalidResumeState('TUS media upload resume location is invalid', head.status);
|
|
1036
|
+
}
|
|
1037
|
+
return {
|
|
1038
|
+
ok: false,
|
|
1039
|
+
status: head.status,
|
|
1040
|
+
statusText: head.statusText,
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
offset = assertTusOffsetWithinUpload(parseTusOffset(getHeader(head, 'Upload-Offset'), 'resume response'), totalBytes);
|
|
1044
|
+
}
|
|
1045
|
+
else {
|
|
1046
|
+
const create = await fetchImpl(creationUrl, {
|
|
1047
|
+
method: 'POST',
|
|
1048
|
+
signal: options.signal,
|
|
1049
|
+
headers: {
|
|
1050
|
+
...options.headers,
|
|
1051
|
+
'Tus-Resumable': tusVersion,
|
|
1052
|
+
'Upload-Length': String(totalBytes),
|
|
1053
|
+
},
|
|
1054
|
+
});
|
|
1055
|
+
assertNotAborted(options.signal);
|
|
1056
|
+
if (create.status !== 201) {
|
|
1057
|
+
return {
|
|
1058
|
+
ok: false,
|
|
1059
|
+
status: create.status,
|
|
1060
|
+
statusText: create.statusText,
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
resumeUrl = resolveTusLocation(getHeader(create, 'Location'), creationUrl);
|
|
1064
|
+
offset = parseTusCreationOffset(getHeader(create, 'Upload-Offset'), totalBytes);
|
|
1065
|
+
}
|
|
1066
|
+
emitUploadTransferProgress(options, offset, totalBytes, resumeUrl);
|
|
1067
|
+
while (offset < data.length) {
|
|
1068
|
+
assertNotAborted(options.signal);
|
|
1069
|
+
const nextOffset = Math.min(offset + chunkSizeBytes, data.length);
|
|
1070
|
+
const patch = await fetchImpl(resumeUrl, {
|
|
1071
|
+
method: 'PATCH',
|
|
1072
|
+
body: sliceBytes(data, offset, nextOffset),
|
|
1073
|
+
signal: options.signal,
|
|
1074
|
+
headers: {
|
|
1075
|
+
...options.headers,
|
|
1076
|
+
'Tus-Resumable': tusVersion,
|
|
1077
|
+
'Upload-Offset': String(offset),
|
|
1078
|
+
'Content-Type': 'application/offset+octet-stream',
|
|
1079
|
+
},
|
|
1080
|
+
});
|
|
1081
|
+
assertNotAborted(options.signal);
|
|
1082
|
+
if (!patch.ok) {
|
|
1083
|
+
if (isInvalidTusResumeResponse(patch)) {
|
|
1084
|
+
throwInvalidResumeState('TUS media upload resume offset is invalid', patch.status);
|
|
1085
|
+
}
|
|
1086
|
+
return {
|
|
1087
|
+
ok: false,
|
|
1088
|
+
status: patch.status,
|
|
1089
|
+
statusText: patch.statusText,
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
offset = assertTusPatchAdvancedToExpectedOffset(assertTusOffsetWithinUpload(parseTusOffset(getHeader(patch, 'Upload-Offset'), 'PATCH response'), totalBytes), nextOffset);
|
|
1093
|
+
emitUploadTransferProgress(options, offset, totalBytes, resumeUrl);
|
|
1094
|
+
}
|
|
1095
|
+
return { ok: true, status: 204, statusText: 'No Content' };
|
|
1096
|
+
},
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
function parseContentLength(response) {
|
|
1100
|
+
const contentLength = getHeader(response, 'content-length');
|
|
1101
|
+
if (!contentLength || !/^\d+$/.test(contentLength))
|
|
1102
|
+
return undefined;
|
|
1103
|
+
return Number(contentLength);
|
|
1104
|
+
}
|
|
1105
|
+
function assertCiphertextSizeWithinExpected(expectedBytes, receivedBytes) {
|
|
1106
|
+
if (expectedBytes === undefined || receivedBytes <= expectedBytes) {
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
throw new MediaAttachmentError(`Media attachment ciphertext size mismatch: expected ${expectedBytes} bytes, received ${receivedBytes}`, MediaAttachmentErrorCode.CiphertextSizeMismatch);
|
|
1110
|
+
}
|
|
1111
|
+
function assertCiphertextSizeEqualsExpected(expectedBytes, receivedBytes) {
|
|
1112
|
+
if (expectedBytes === undefined ||
|
|
1113
|
+
receivedBytes === undefined ||
|
|
1114
|
+
receivedBytes === expectedBytes) {
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
throw new MediaAttachmentError(`Media attachment ciphertext size mismatch: expected ${expectedBytes} bytes, received ${receivedBytes}`, MediaAttachmentErrorCode.CiphertextSizeMismatch);
|
|
1118
|
+
}
|
|
1119
|
+
function parseContentRange(value) {
|
|
1120
|
+
if (!value)
|
|
1121
|
+
return null;
|
|
1122
|
+
const match = /^bytes\s+(\d+)-(\d+)\/(\d+|\*)$/i.exec(value.trim());
|
|
1123
|
+
if (!match)
|
|
1124
|
+
return null;
|
|
1125
|
+
const start = Number(match[1]);
|
|
1126
|
+
const end = Number(match[2]);
|
|
1127
|
+
const totalBytes = match[3] === '*' ? undefined : Number(match[3]);
|
|
1128
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end < start) {
|
|
1129
|
+
return null;
|
|
1130
|
+
}
|
|
1131
|
+
if (totalBytes !== undefined && (!Number.isSafeInteger(totalBytes) || totalBytes <= end)) {
|
|
1132
|
+
return null;
|
|
1133
|
+
}
|
|
1134
|
+
return { start, end, totalBytes };
|
|
1135
|
+
}
|
|
1136
|
+
function contentRangeLength(range) {
|
|
1137
|
+
return range.end - range.start + 1;
|
|
1138
|
+
}
|
|
1139
|
+
function assertContentRangeTotalMatchesExpected(range, expectedBytes) {
|
|
1140
|
+
assertCiphertextSizeEqualsExpected(expectedBytes, range.totalBytes);
|
|
1141
|
+
}
|
|
1142
|
+
function assertContentRangeBodyLength(range, bytes) {
|
|
1143
|
+
const expectedLength = contentRangeLength(range);
|
|
1144
|
+
if (bytes.length === expectedLength) {
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
throw new MediaAttachmentError(`Media attachment range body length mismatch: expected ${expectedLength} bytes, received ${bytes.length}`, MediaAttachmentErrorCode.DownloadFailed, { status: 206 });
|
|
1148
|
+
}
|
|
1149
|
+
async function readResponseBodyBytes(response, signal) {
|
|
1150
|
+
if (response.body?.getReader) {
|
|
1151
|
+
const reader = response.body.getReader();
|
|
1152
|
+
const chunks = [];
|
|
1153
|
+
while (true) {
|
|
1154
|
+
assertNotAborted(signal);
|
|
1155
|
+
const { done, value } = await reader.read();
|
|
1156
|
+
if (done)
|
|
1157
|
+
break;
|
|
1158
|
+
chunks.push(value);
|
|
1159
|
+
}
|
|
1160
|
+
return concatBytes(...chunks);
|
|
1161
|
+
}
|
|
1162
|
+
const data = new Uint8Array(await response.arrayBuffer());
|
|
1163
|
+
assertNotAborted(signal);
|
|
1164
|
+
return data;
|
|
1165
|
+
}
|
|
1166
|
+
function resolveByteRangeResumeToken(url, options, rangeOptions) {
|
|
1167
|
+
if (options.resume?.resumeToken)
|
|
1168
|
+
return options.resume.resumeToken;
|
|
1169
|
+
if (typeof rangeOptions.resumeToken === 'function') {
|
|
1170
|
+
return rangeOptions.resumeToken(url, options);
|
|
1171
|
+
}
|
|
1172
|
+
if (typeof rangeOptions.resumeToken === 'string')
|
|
1173
|
+
return rangeOptions.resumeToken;
|
|
1174
|
+
return options.attachmentId ?? options.storageId ?? url;
|
|
1175
|
+
}
|
|
1176
|
+
function createDownloadResumeState(options, offsetBytes, resumeToken) {
|
|
1177
|
+
return {
|
|
1178
|
+
operation: 'download',
|
|
1179
|
+
offsetBytes,
|
|
1180
|
+
resumeToken,
|
|
1181
|
+
updatedAt: Date.now(),
|
|
1182
|
+
expiresAt: options.resume?.expiresAt,
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
function emitDownloadTransferProgress(options, bytesTransferred, totalBytes, resumeToken, complete = false) {
|
|
1186
|
+
emitProgress(options.onProgress, {
|
|
1187
|
+
operation: 'download',
|
|
1188
|
+
phase: 'transfer',
|
|
1189
|
+
attempt: options.attempt,
|
|
1190
|
+
storageId: options.storageId,
|
|
1191
|
+
bytesTransferred,
|
|
1192
|
+
totalBytes,
|
|
1193
|
+
});
|
|
1194
|
+
emitCheckpoint(options.onCheckpoint, {
|
|
1195
|
+
operation: 'download',
|
|
1196
|
+
phase: complete ? 'complete' : 'transfer',
|
|
1197
|
+
attempt: options.attempt,
|
|
1198
|
+
storageId: options.storageId,
|
|
1199
|
+
attachmentId: options.attachmentId,
|
|
1200
|
+
bytesTransferred,
|
|
1201
|
+
totalBytes,
|
|
1202
|
+
resumeToken,
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
function handleDownloadHttpFailure(response) {
|
|
1206
|
+
if (response.status === 404) {
|
|
1207
|
+
throw new MediaAttachmentError('Media attachment blob not found', MediaAttachmentErrorCode.BlobNotFound, { status: response.status });
|
|
1208
|
+
}
|
|
1209
|
+
if (response.status === 416) {
|
|
1210
|
+
throwInvalidResumeState('Byte-range media download resume offset is invalid', response.status);
|
|
1211
|
+
}
|
|
1212
|
+
throw new MediaAttachmentError(`Media attachment download failed: ${response.status} ${response.statusText}`, MediaAttachmentErrorCode.DownloadFailed, { status: response.status });
|
|
1213
|
+
}
|
|
1214
|
+
async function loadByteRangePrefix(resume, partialStore) {
|
|
1215
|
+
if (!resume || (resume.offsetBytes ?? 0) === 0) {
|
|
1216
|
+
return new Uint8Array();
|
|
1217
|
+
}
|
|
1218
|
+
if (resume.operation !== 'download') {
|
|
1219
|
+
throwInvalidResumeState('Byte-range media download received non-download resume state');
|
|
1220
|
+
}
|
|
1221
|
+
if (!partialStore) {
|
|
1222
|
+
throwInvalidResumeState('Byte-range media download resume requires a partial-byte store');
|
|
1223
|
+
}
|
|
1224
|
+
const prefix = await partialStore.load(resume);
|
|
1225
|
+
if (!prefix || prefix.length !== resume.offsetBytes) {
|
|
1226
|
+
await clearByteRangePrefixes(partialStore, [resume]);
|
|
1227
|
+
throwInvalidResumeState('Byte-range media download partial state is missing or truncated');
|
|
1228
|
+
}
|
|
1229
|
+
return prefix;
|
|
1230
|
+
}
|
|
1231
|
+
async function persistByteRangePrefix(partialStore, options, bytes, resumeToken) {
|
|
1232
|
+
if (!partialStore)
|
|
1233
|
+
return undefined;
|
|
1234
|
+
const resume = createDownloadResumeState(options, bytes.length, resumeToken);
|
|
1235
|
+
await partialStore.save(resume, bytes);
|
|
1236
|
+
return resume;
|
|
1237
|
+
}
|
|
1238
|
+
function dedupeByteRangeResumeStates(resumes) {
|
|
1239
|
+
const seen = new Set();
|
|
1240
|
+
const deduped = [];
|
|
1241
|
+
for (const resume of resumes) {
|
|
1242
|
+
if (!resume)
|
|
1243
|
+
continue;
|
|
1244
|
+
const key = `${resume.operation}:${resume.resumeToken ?? ''}:${resume.offsetBytes ?? ''}`;
|
|
1245
|
+
if (seen.has(key))
|
|
1246
|
+
continue;
|
|
1247
|
+
seen.add(key);
|
|
1248
|
+
deduped.push(resume);
|
|
1249
|
+
}
|
|
1250
|
+
return deduped;
|
|
1251
|
+
}
|
|
1252
|
+
async function clearByteRangePrefixes(partialStore, resumes) {
|
|
1253
|
+
if (!partialStore?.clear)
|
|
1254
|
+
return;
|
|
1255
|
+
for (const resume of dedupeByteRangeResumeStates(resumes)) {
|
|
1256
|
+
try {
|
|
1257
|
+
await partialStore.clear(resume);
|
|
1258
|
+
}
|
|
1259
|
+
catch {
|
|
1260
|
+
// Cleanup failures must not mask transfer integrity decisions. App-level
|
|
1261
|
+
// orphan cleanup can remove stale encrypted partials on a later pass.
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
async function clearCurrentByteRangePrefix(partialStore, options, offsetBytes, resumeToken) {
|
|
1266
|
+
if (offsetBytes === 0 && !options.resume?.resumeToken) {
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
await clearByteRangePrefixes(partialStore, [
|
|
1270
|
+
createDownloadResumeState(options, offsetBytes, resumeToken),
|
|
1271
|
+
]);
|
|
1272
|
+
}
|
|
1273
|
+
export function createByteRangeMediaAttachmentTransfer(rangeOptions = {}) {
|
|
1274
|
+
return {
|
|
1275
|
+
async download(url, options = {}) {
|
|
1276
|
+
assertNotAborted(options.signal);
|
|
1277
|
+
const fetchImpl = getFetchImplementation(rangeOptions.fetch, 'download');
|
|
1278
|
+
const resumeToken = resolveByteRangeResumeToken(url, options, rangeOptions);
|
|
1279
|
+
let bytes = await loadByteRangePrefix(options.resume, rangeOptions.partialStore);
|
|
1280
|
+
let offset = bytes.length;
|
|
1281
|
+
let totalBytes = options.totalBytes;
|
|
1282
|
+
const persistedPrefixes = [];
|
|
1283
|
+
emitDownloadTransferProgress(options, offset, totalBytes, resumeToken);
|
|
1284
|
+
if (totalBytes !== undefined && offset >= totalBytes) {
|
|
1285
|
+
emitDownloadTransferProgress(options, offset, totalBytes, resumeToken, true);
|
|
1286
|
+
await clearByteRangePrefixes(rangeOptions.partialStore, [options.resume]);
|
|
1287
|
+
return bytes;
|
|
1288
|
+
}
|
|
1289
|
+
while (totalBytes === undefined || offset < totalBytes) {
|
|
1290
|
+
assertNotAborted(options.signal);
|
|
1291
|
+
const requestedRangeEnd = rangeOptions.chunkSizeBytes !== undefined
|
|
1292
|
+
? offset + Math.max(1, rangeOptions.chunkSizeBytes) - 1
|
|
1293
|
+
: undefined;
|
|
1294
|
+
const rangeEnd = totalBytes !== undefined
|
|
1295
|
+
? Math.min(requestedRangeEnd ?? totalBytes - 1, totalBytes - 1)
|
|
1296
|
+
: requestedRangeEnd;
|
|
1297
|
+
const shouldRequestRange = offset > 0 || rangeOptions.chunkSizeBytes !== undefined;
|
|
1298
|
+
const response = await fetchImpl(url, {
|
|
1299
|
+
method: 'GET',
|
|
1300
|
+
signal: options.signal,
|
|
1301
|
+
headers: {
|
|
1302
|
+
...options.headers,
|
|
1303
|
+
...(shouldRequestRange
|
|
1304
|
+
? {
|
|
1305
|
+
Range: `bytes=${offset}-${rangeEnd !== undefined ? rangeEnd : ''}`,
|
|
1306
|
+
}
|
|
1307
|
+
: {}),
|
|
1308
|
+
},
|
|
1309
|
+
});
|
|
1310
|
+
assertNotAborted(options.signal);
|
|
1311
|
+
if (!response.ok) {
|
|
1312
|
+
if (response.status === 416) {
|
|
1313
|
+
await clearCurrentByteRangePrefix(rangeOptions.partialStore, options, offset, resumeToken);
|
|
1314
|
+
}
|
|
1315
|
+
handleDownloadHttpFailure(response);
|
|
1316
|
+
}
|
|
1317
|
+
let rangedResponse = false;
|
|
1318
|
+
let responseContentRange = null;
|
|
1319
|
+
if (shouldRequestRange) {
|
|
1320
|
+
if (response.status === 206) {
|
|
1321
|
+
rangedResponse = true;
|
|
1322
|
+
responseContentRange = parseContentRange(getHeader(response, 'content-range'));
|
|
1323
|
+
if (!responseContentRange ||
|
|
1324
|
+
responseContentRange.start !== offset ||
|
|
1325
|
+
(rangeEnd !== undefined && responseContentRange.end > rangeEnd)) {
|
|
1326
|
+
await clearCurrentByteRangePrefix(rangeOptions.partialStore, options, offset, resumeToken);
|
|
1327
|
+
throwInvalidResumeState('Byte-range media download returned an unexpected range');
|
|
1328
|
+
}
|
|
1329
|
+
try {
|
|
1330
|
+
assertContentRangeTotalMatchesExpected(responseContentRange, totalBytes);
|
|
1331
|
+
}
|
|
1332
|
+
catch (error) {
|
|
1333
|
+
await clearCurrentByteRangePrefix(rangeOptions.partialStore, options, offset, resumeToken);
|
|
1334
|
+
throw error;
|
|
1335
|
+
}
|
|
1336
|
+
totalBytes = totalBytes ?? responseContentRange.totalBytes;
|
|
1337
|
+
}
|
|
1338
|
+
else if (response.status === 200 && offset > 0) {
|
|
1339
|
+
await clearCurrentByteRangePrefix(rangeOptions.partialStore, options, offset, resumeToken);
|
|
1340
|
+
throwInvalidResumeState('Byte-range media download server ignored resume offset');
|
|
1341
|
+
}
|
|
1342
|
+
else if (response.status !== 200) {
|
|
1343
|
+
handleDownloadHttpFailure(response);
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
totalBytes = totalBytes ?? parseContentLength(response);
|
|
1347
|
+
const chunk = await readResponseBodyBytes(response, options.signal);
|
|
1348
|
+
if (responseContentRange) {
|
|
1349
|
+
try {
|
|
1350
|
+
assertContentRangeBodyLength(responseContentRange, chunk);
|
|
1351
|
+
}
|
|
1352
|
+
catch (error) {
|
|
1353
|
+
await clearCurrentByteRangePrefix(rangeOptions.partialStore, options, offset, resumeToken);
|
|
1354
|
+
throw error;
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
assertCiphertextSizeWithinExpected(totalBytes, offset + chunk.length);
|
|
1358
|
+
if (chunk.length === 0 && (totalBytes === undefined || offset < totalBytes)) {
|
|
1359
|
+
throw new MediaAttachmentError('Media attachment download returned an empty partial response', MediaAttachmentErrorCode.DownloadFailed, { status: response.status });
|
|
1360
|
+
}
|
|
1361
|
+
bytes = offset === 0 && !rangedResponse ? chunk : concatBytes(bytes, chunk);
|
|
1362
|
+
offset = bytes.length;
|
|
1363
|
+
const persistedPrefix = await persistByteRangePrefix(rangeOptions.partialStore, options, bytes, resumeToken);
|
|
1364
|
+
if (persistedPrefix) {
|
|
1365
|
+
persistedPrefixes.push(persistedPrefix);
|
|
1366
|
+
}
|
|
1367
|
+
emitDownloadTransferProgress(options, offset, totalBytes, resumeToken, totalBytes !== undefined && offset >= totalBytes);
|
|
1368
|
+
if (!rangedResponse || rangeOptions.chunkSizeBytes === undefined) {
|
|
1369
|
+
break;
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
if (totalBytes !== undefined && bytes.length !== totalBytes) {
|
|
1373
|
+
await clearByteRangePrefixes(rangeOptions.partialStore, [
|
|
1374
|
+
options.resume,
|
|
1375
|
+
...persistedPrefixes,
|
|
1376
|
+
]);
|
|
1377
|
+
throw new MediaAttachmentError(`Media attachment download size mismatch: expected ${totalBytes} bytes, received ${bytes.length}`, MediaAttachmentErrorCode.DownloadFailed);
|
|
1378
|
+
}
|
|
1379
|
+
await clearByteRangePrefixes(rangeOptions.partialStore, [
|
|
1380
|
+
options.resume,
|
|
1381
|
+
...persistedPrefixes,
|
|
1382
|
+
]);
|
|
1383
|
+
return bytes;
|
|
1384
|
+
},
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1387
|
+
async function readResponseBytes(response, options) {
|
|
1388
|
+
const totalBytesHeader = getHeader(response, 'content-length');
|
|
1389
|
+
const headerBytes = totalBytesHeader && /^\d+$/.test(totalBytesHeader) ? Number(totalBytesHeader) : undefined;
|
|
1390
|
+
assertCiphertextSizeEqualsExpected(options.totalBytes, headerBytes);
|
|
1391
|
+
const totalBytes = options.totalBytes ?? (headerBytes !== undefined ? Number(headerBytes) : undefined);
|
|
1392
|
+
emitProgress(options.onProgress, {
|
|
1393
|
+
operation: 'download',
|
|
1394
|
+
phase: 'transfer',
|
|
1395
|
+
attempt: options.attempt,
|
|
1396
|
+
storageId: options.storageId,
|
|
1397
|
+
bytesTransferred: 0,
|
|
1398
|
+
totalBytes,
|
|
1399
|
+
});
|
|
1400
|
+
emitCheckpoint(options.onCheckpoint, {
|
|
1401
|
+
operation: 'download',
|
|
1402
|
+
phase: 'transfer',
|
|
1403
|
+
attempt: options.attempt,
|
|
1404
|
+
storageId: options.storageId,
|
|
1405
|
+
attachmentId: options.attachmentId,
|
|
1406
|
+
bytesTransferred: 0,
|
|
1407
|
+
totalBytes,
|
|
1408
|
+
resumeToken: options.resume?.resumeToken,
|
|
1409
|
+
});
|
|
1410
|
+
if (response.body?.getReader) {
|
|
1411
|
+
const reader = response.body.getReader();
|
|
1412
|
+
const chunks = [];
|
|
1413
|
+
let bytesTransferred = 0;
|
|
1414
|
+
while (true) {
|
|
1415
|
+
assertNotAborted(options.signal);
|
|
1416
|
+
const { done, value } = await reader.read();
|
|
1417
|
+
if (done)
|
|
1418
|
+
break;
|
|
1419
|
+
const nextBytesTransferred = bytesTransferred + value.length;
|
|
1420
|
+
assertCiphertextSizeWithinExpected(options.totalBytes, nextBytesTransferred);
|
|
1421
|
+
chunks.push(value);
|
|
1422
|
+
bytesTransferred = nextBytesTransferred;
|
|
1423
|
+
emitProgress(options.onProgress, {
|
|
1424
|
+
operation: 'download',
|
|
1425
|
+
phase: 'transfer',
|
|
1426
|
+
attempt: options.attempt,
|
|
1427
|
+
storageId: options.storageId,
|
|
1428
|
+
bytesTransferred,
|
|
1429
|
+
totalBytes,
|
|
1430
|
+
});
|
|
1431
|
+
emitCheckpoint(options.onCheckpoint, {
|
|
1432
|
+
operation: 'download',
|
|
1433
|
+
phase: 'transfer',
|
|
1434
|
+
attempt: options.attempt,
|
|
1435
|
+
storageId: options.storageId,
|
|
1436
|
+
attachmentId: options.attachmentId,
|
|
1437
|
+
bytesTransferred,
|
|
1438
|
+
totalBytes,
|
|
1439
|
+
resumeToken: options.resume?.resumeToken,
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
const data = concatBytes(...chunks);
|
|
1443
|
+
emitCheckpoint(options.onCheckpoint, {
|
|
1444
|
+
operation: 'download',
|
|
1445
|
+
phase: 'complete',
|
|
1446
|
+
attempt: options.attempt,
|
|
1447
|
+
storageId: options.storageId,
|
|
1448
|
+
attachmentId: options.attachmentId,
|
|
1449
|
+
bytesTransferred: data.length,
|
|
1450
|
+
totalBytes: totalBytes ?? data.length,
|
|
1451
|
+
resumeToken: options.resume?.resumeToken,
|
|
1452
|
+
});
|
|
1453
|
+
return data;
|
|
1454
|
+
}
|
|
1455
|
+
const data = new Uint8Array(await response.arrayBuffer());
|
|
1456
|
+
assertNotAborted(options.signal);
|
|
1457
|
+
assertCiphertextSizeEqualsExpected(options.totalBytes, data.length);
|
|
1458
|
+
emitProgress(options.onProgress, {
|
|
1459
|
+
operation: 'download',
|
|
1460
|
+
phase: 'transfer',
|
|
1461
|
+
attempt: options.attempt,
|
|
1462
|
+
storageId: options.storageId,
|
|
1463
|
+
bytesTransferred: data.length,
|
|
1464
|
+
totalBytes: totalBytes ?? data.length,
|
|
1465
|
+
});
|
|
1466
|
+
emitCheckpoint(options.onCheckpoint, {
|
|
1467
|
+
operation: 'download',
|
|
1468
|
+
phase: 'complete',
|
|
1469
|
+
attempt: options.attempt,
|
|
1470
|
+
storageId: options.storageId,
|
|
1471
|
+
attachmentId: options.attachmentId,
|
|
1472
|
+
bytesTransferred: data.length,
|
|
1473
|
+
totalBytes: totalBytes ?? data.length,
|
|
1474
|
+
resumeToken: options.resume?.resumeToken,
|
|
1475
|
+
});
|
|
1476
|
+
return data;
|
|
1477
|
+
}
|
|
1478
|
+
async function defaultDownload(url, options = {}) {
|
|
1479
|
+
assertNotAborted(options.signal);
|
|
1480
|
+
if (typeof globalThis.fetch !== 'function') {
|
|
1481
|
+
throw new MediaAttachmentError('Cannot download media attachment: fetch is not available', MediaAttachmentErrorCode.DownloadFailed);
|
|
1482
|
+
}
|
|
1483
|
+
const response = await globalThis.fetch(url, {
|
|
1484
|
+
signal: options.signal,
|
|
1485
|
+
headers: options.headers,
|
|
1486
|
+
});
|
|
1487
|
+
assertNotAborted(options.signal);
|
|
1488
|
+
if (!response.ok) {
|
|
1489
|
+
if (response.status === 404) {
|
|
1490
|
+
throw new MediaAttachmentError('Media attachment blob not found', MediaAttachmentErrorCode.BlobNotFound, { status: response.status });
|
|
1491
|
+
}
|
|
1492
|
+
throw new MediaAttachmentError(`Media attachment download failed: ${response.status} ${response.statusText}`, MediaAttachmentErrorCode.DownloadFailed, { status: response.status });
|
|
1493
|
+
}
|
|
1494
|
+
return readResponseBytes(response, options);
|
|
1495
|
+
}
|
|
1496
|
+
const DEFAULT_MEDIA_RETRY_OPTIONS = {
|
|
1497
|
+
maxRetries: 2,
|
|
1498
|
+
baseDelayMs: 250,
|
|
1499
|
+
maxDelayMs: 2_000,
|
|
1500
|
+
enableJitter: true,
|
|
1501
|
+
};
|
|
1502
|
+
function sleep(ms) {
|
|
1503
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1504
|
+
}
|
|
1505
|
+
function resolveUploadRetryOptions(input) {
|
|
1506
|
+
return {
|
|
1507
|
+
...DEFAULT_MEDIA_RETRY_OPTIONS,
|
|
1508
|
+
...input,
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
function calculateUploadRetryDelay(attempt, options) {
|
|
1512
|
+
let delay = Math.min(options.baseDelayMs * Math.pow(2, attempt), options.maxDelayMs);
|
|
1513
|
+
if (options.enableJitter && delay > 0) {
|
|
1514
|
+
delay -= Math.random() * delay * 0.25;
|
|
1515
|
+
}
|
|
1516
|
+
return Math.floor(delay);
|
|
1517
|
+
}
|
|
1518
|
+
function isRetryableUploadStatus(status) {
|
|
1519
|
+
if (status === undefined)
|
|
1520
|
+
return true;
|
|
1521
|
+
if (status === 403)
|
|
1522
|
+
return true;
|
|
1523
|
+
if (status === 408 || status === 409 || status === 425 || status === 429)
|
|
1524
|
+
return true;
|
|
1525
|
+
return status >= 500;
|
|
1526
|
+
}
|
|
1527
|
+
function isRetryableUploadError(error) {
|
|
1528
|
+
if (error instanceof MediaAttachmentError) {
|
|
1529
|
+
if (error.code === MediaAttachmentErrorCode.ResumeStateInvalid) {
|
|
1530
|
+
return true;
|
|
1531
|
+
}
|
|
1532
|
+
return (error.code === MediaAttachmentErrorCode.UploadFailed && isRetryableUploadStatus(error.status));
|
|
1533
|
+
}
|
|
1534
|
+
return true;
|
|
1535
|
+
}
|
|
1536
|
+
function isRetryableDownloadStatus(status) {
|
|
1537
|
+
if (status === undefined)
|
|
1538
|
+
return true;
|
|
1539
|
+
if (status === 403)
|
|
1540
|
+
return true;
|
|
1541
|
+
if (status === 408 || status === 409 || status === 425 || status === 429)
|
|
1542
|
+
return true;
|
|
1543
|
+
return status >= 500;
|
|
1544
|
+
}
|
|
1545
|
+
function isRetryableDownloadError(error) {
|
|
1546
|
+
if (error instanceof MediaAttachmentError) {
|
|
1547
|
+
if (error.code === MediaAttachmentErrorCode.BlobNotFound) {
|
|
1548
|
+
return false;
|
|
1549
|
+
}
|
|
1550
|
+
if (error.code === MediaAttachmentErrorCode.ResumeStateInvalid) {
|
|
1551
|
+
return true;
|
|
1552
|
+
}
|
|
1553
|
+
return (error.code === MediaAttachmentErrorCode.DownloadFailed &&
|
|
1554
|
+
isRetryableDownloadStatus(error.status));
|
|
1555
|
+
}
|
|
1556
|
+
return true;
|
|
1557
|
+
}
|
|
1558
|
+
function normalizeDownloadError(error) {
|
|
1559
|
+
if (error instanceof MediaAttachmentError) {
|
|
1560
|
+
if (error.status === 404 && error.code === MediaAttachmentErrorCode.DownloadFailed) {
|
|
1561
|
+
return new MediaAttachmentError('Media attachment blob not found', MediaAttachmentErrorCode.BlobNotFound, { cause: error, status: 404 });
|
|
1562
|
+
}
|
|
1563
|
+
return error;
|
|
1564
|
+
}
|
|
1565
|
+
const message = error instanceof Error ? error.message.toLowerCase() : '';
|
|
1566
|
+
if (message.includes('blob not found') ||
|
|
1567
|
+
message.includes('attachment blob not found') ||
|
|
1568
|
+
message.includes('media attachment not found')) {
|
|
1569
|
+
return new MediaAttachmentError('Media attachment blob not found', MediaAttachmentErrorCode.BlobNotFound, { cause: error });
|
|
1570
|
+
}
|
|
1571
|
+
return error;
|
|
1572
|
+
}
|
|
1573
|
+
function getRetryStatus(error) {
|
|
1574
|
+
return error instanceof MediaAttachmentError ? error.status : undefined;
|
|
1575
|
+
}
|
|
1576
|
+
function getRetryReason(error) {
|
|
1577
|
+
if (error instanceof MediaAttachmentError &&
|
|
1578
|
+
error.code === MediaAttachmentErrorCode.ResumeStateInvalid) {
|
|
1579
|
+
return 'invalid-resume';
|
|
1580
|
+
}
|
|
1581
|
+
const status = getRetryStatus(error);
|
|
1582
|
+
if (status === 403)
|
|
1583
|
+
return 'expired-url';
|
|
1584
|
+
if (status !== undefined)
|
|
1585
|
+
return 'retryable-status';
|
|
1586
|
+
return 'transient-failure';
|
|
1587
|
+
}
|
|
1588
|
+
async function uploadCiphertextWithRetry(input) {
|
|
1589
|
+
const retry = resolveUploadRetryOptions(input.retry);
|
|
1590
|
+
let lastError;
|
|
1591
|
+
let resume = input.resume;
|
|
1592
|
+
let canonicalObjectId;
|
|
1593
|
+
const onCheckpoint = trackResumeCheckpoints('upload', input.onCheckpoint, (nextResume) => {
|
|
1594
|
+
resume = nextResume;
|
|
1595
|
+
}, () => resume);
|
|
1596
|
+
for (let attempt = 0; attempt <= retry.maxRetries; attempt++) {
|
|
1597
|
+
try {
|
|
1598
|
+
assertNotAborted(input.signal);
|
|
1599
|
+
emitProgress(input.onProgress, {
|
|
1600
|
+
operation: 'upload',
|
|
1601
|
+
phase: 'request-url',
|
|
1602
|
+
attempt,
|
|
1603
|
+
requestId: input.requestId,
|
|
1604
|
+
});
|
|
1605
|
+
emitCheckpoint(onCheckpoint, {
|
|
1606
|
+
operation: 'upload',
|
|
1607
|
+
phase: 'request-url',
|
|
1608
|
+
attempt,
|
|
1609
|
+
requestId: input.requestId,
|
|
1610
|
+
storageId: canonicalObjectId,
|
|
1611
|
+
bytesTransferred: resume?.offsetBytes ?? 0,
|
|
1612
|
+
totalBytes: input.ciphertext.length,
|
|
1613
|
+
resumeToken: resume?.resumeToken,
|
|
1614
|
+
});
|
|
1615
|
+
const { uploadUrl, objectId, headers, protocol } = await input.remoteObjectStore.createUpload({
|
|
1616
|
+
requestId: input.requestId,
|
|
1617
|
+
contentType: 'application/octet-stream',
|
|
1618
|
+
contentLength: input.ciphertext.length,
|
|
1619
|
+
});
|
|
1620
|
+
if (canonicalObjectId !== undefined && canonicalObjectId !== objectId) {
|
|
1621
|
+
throw new MediaAttachmentError('Remote object storage returned a different object ID for an upload retry', MediaAttachmentErrorCode.UploadIdentityChanged);
|
|
1622
|
+
}
|
|
1623
|
+
canonicalObjectId = objectId;
|
|
1624
|
+
assertNotAborted(input.signal);
|
|
1625
|
+
const transfer = input.transfer ?? (protocol === 'tus' ? createTusMediaAttachmentTransfer() : undefined);
|
|
1626
|
+
const uploadHeaders = { ...headers };
|
|
1627
|
+
if (!Object.keys(uploadHeaders).some((name) => name.toLowerCase() === 'content-type')) {
|
|
1628
|
+
uploadHeaders['Content-Type'] = 'application/octet-stream';
|
|
1629
|
+
}
|
|
1630
|
+
const response = transfer?.upload
|
|
1631
|
+
? await transfer.upload(uploadUrl, input.ciphertext, {
|
|
1632
|
+
headers: uploadHeaders,
|
|
1633
|
+
signal: input.signal,
|
|
1634
|
+
onProgress: input.onProgress,
|
|
1635
|
+
onCheckpoint,
|
|
1636
|
+
resume,
|
|
1637
|
+
attempt,
|
|
1638
|
+
totalBytes: input.ciphertext.length,
|
|
1639
|
+
requestId: input.requestId,
|
|
1640
|
+
storageId: objectId,
|
|
1641
|
+
})
|
|
1642
|
+
: await defaultUpload(uploadUrl, input.ciphertext, {
|
|
1643
|
+
headers: uploadHeaders,
|
|
1644
|
+
signal: input.signal,
|
|
1645
|
+
onProgress: input.onProgress,
|
|
1646
|
+
onCheckpoint,
|
|
1647
|
+
resume,
|
|
1648
|
+
attempt,
|
|
1649
|
+
totalBytes: input.ciphertext.length,
|
|
1650
|
+
requestId: input.requestId,
|
|
1651
|
+
storageId: objectId,
|
|
1652
|
+
});
|
|
1653
|
+
if (!response.ok) {
|
|
1654
|
+
throw new MediaAttachmentError(`Media attachment upload failed: ${response.status} ${response.statusText}`, MediaAttachmentErrorCode.UploadFailed, { status: response.status });
|
|
1655
|
+
}
|
|
1656
|
+
await input.remoteObjectStore.completeUpload?.({ objectId });
|
|
1657
|
+
return objectId;
|
|
1658
|
+
}
|
|
1659
|
+
catch (error) {
|
|
1660
|
+
if (input.signal?.aborted) {
|
|
1661
|
+
throw new MediaAttachmentError('Media attachment operation cancelled', MediaAttachmentErrorCode.Cancelled, { cause: input.signal.reason });
|
|
1662
|
+
}
|
|
1663
|
+
lastError = error;
|
|
1664
|
+
const shouldClearResume = error instanceof MediaAttachmentError &&
|
|
1665
|
+
error.code === MediaAttachmentErrorCode.ResumeStateInvalid;
|
|
1666
|
+
if (shouldClearResume) {
|
|
1667
|
+
resume = undefined;
|
|
1668
|
+
}
|
|
1669
|
+
if (attempt >= retry.maxRetries || !isRetryableUploadError(error)) {
|
|
1670
|
+
break;
|
|
1671
|
+
}
|
|
1672
|
+
const delay = calculateUploadRetryDelay(attempt, retry);
|
|
1673
|
+
emitProgress(input.onProgress, {
|
|
1674
|
+
operation: 'upload',
|
|
1675
|
+
phase: 'retry',
|
|
1676
|
+
attempt,
|
|
1677
|
+
requestId: input.requestId,
|
|
1678
|
+
storageId: canonicalObjectId,
|
|
1679
|
+
status: getRetryStatus(error),
|
|
1680
|
+
retryInMs: delay,
|
|
1681
|
+
reason: getRetryReason(error),
|
|
1682
|
+
});
|
|
1683
|
+
emitCheckpoint(onCheckpoint, {
|
|
1684
|
+
operation: 'upload',
|
|
1685
|
+
phase: 'retry',
|
|
1686
|
+
attempt,
|
|
1687
|
+
requestId: input.requestId,
|
|
1688
|
+
storageId: canonicalObjectId,
|
|
1689
|
+
bytesTransferred: resume?.offsetBytes ?? 0,
|
|
1690
|
+
totalBytes: input.ciphertext.length,
|
|
1691
|
+
resumeToken: resume?.resumeToken,
|
|
1692
|
+
});
|
|
1693
|
+
if (delay > 0) {
|
|
1694
|
+
await sleep(delay);
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
if (lastError instanceof MediaAttachmentError) {
|
|
1699
|
+
throw lastError;
|
|
1700
|
+
}
|
|
1701
|
+
throw new MediaAttachmentError('Media attachment upload failed', MediaAttachmentErrorCode.UploadFailed, { cause: lastError });
|
|
1702
|
+
}
|
|
1703
|
+
async function downloadCiphertextWithRetry(input) {
|
|
1704
|
+
const retry = resolveUploadRetryOptions(input.retry);
|
|
1705
|
+
let lastError;
|
|
1706
|
+
let resume = input.resume;
|
|
1707
|
+
const onCheckpoint = trackResumeCheckpoints('download', input.onCheckpoint, (nextResume) => {
|
|
1708
|
+
resume = nextResume;
|
|
1709
|
+
}, () => resume);
|
|
1710
|
+
for (let attempt = 0; attempt <= retry.maxRetries; attempt++) {
|
|
1711
|
+
try {
|
|
1712
|
+
assertNotAborted(input.signal);
|
|
1713
|
+
emitProgress(input.onProgress, {
|
|
1714
|
+
operation: 'download',
|
|
1715
|
+
phase: 'request-url',
|
|
1716
|
+
attempt,
|
|
1717
|
+
storageId: input.storageId,
|
|
1718
|
+
});
|
|
1719
|
+
emitCheckpoint(onCheckpoint, {
|
|
1720
|
+
operation: 'download',
|
|
1721
|
+
phase: 'request-url',
|
|
1722
|
+
attempt,
|
|
1723
|
+
storageId: input.storageId,
|
|
1724
|
+
attachmentId: input.attachmentId,
|
|
1725
|
+
bytesTransferred: resume?.offsetBytes ?? 0,
|
|
1726
|
+
totalBytes: input.expectedCiphertextSize,
|
|
1727
|
+
resumeToken: resume?.resumeToken,
|
|
1728
|
+
});
|
|
1729
|
+
const { downloadUrl, headers } = await input.remoteObjectStore.createDownload({
|
|
1730
|
+
objectId: input.storageId,
|
|
1731
|
+
});
|
|
1732
|
+
assertNotAborted(input.signal);
|
|
1733
|
+
return input.transfer?.download
|
|
1734
|
+
? await input.transfer.download(downloadUrl, {
|
|
1735
|
+
headers,
|
|
1736
|
+
signal: input.signal,
|
|
1737
|
+
onProgress: input.onProgress,
|
|
1738
|
+
onCheckpoint,
|
|
1739
|
+
resume,
|
|
1740
|
+
attempt,
|
|
1741
|
+
totalBytes: input.expectedCiphertextSize,
|
|
1742
|
+
storageId: input.storageId,
|
|
1743
|
+
attachmentId: input.attachmentId,
|
|
1744
|
+
})
|
|
1745
|
+
: await defaultDownload(downloadUrl, {
|
|
1746
|
+
headers,
|
|
1747
|
+
signal: input.signal,
|
|
1748
|
+
onProgress: input.onProgress,
|
|
1749
|
+
onCheckpoint,
|
|
1750
|
+
resume,
|
|
1751
|
+
attempt,
|
|
1752
|
+
totalBytes: input.expectedCiphertextSize,
|
|
1753
|
+
storageId: input.storageId,
|
|
1754
|
+
attachmentId: input.attachmentId,
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
catch (error) {
|
|
1758
|
+
if (input.signal?.aborted) {
|
|
1759
|
+
throw new MediaAttachmentError('Media attachment operation cancelled', MediaAttachmentErrorCode.Cancelled, { cause: input.signal.reason });
|
|
1760
|
+
}
|
|
1761
|
+
const normalizedError = normalizeDownloadError(error);
|
|
1762
|
+
lastError = normalizedError;
|
|
1763
|
+
const shouldClearResume = normalizedError instanceof MediaAttachmentError &&
|
|
1764
|
+
normalizedError.code === MediaAttachmentErrorCode.ResumeStateInvalid;
|
|
1765
|
+
if (shouldClearResume) {
|
|
1766
|
+
resume = undefined;
|
|
1767
|
+
}
|
|
1768
|
+
if (attempt >= retry.maxRetries || !isRetryableDownloadError(normalizedError)) {
|
|
1769
|
+
break;
|
|
1770
|
+
}
|
|
1771
|
+
const delay = calculateUploadRetryDelay(attempt, retry);
|
|
1772
|
+
emitProgress(input.onProgress, {
|
|
1773
|
+
operation: 'download',
|
|
1774
|
+
phase: 'retry',
|
|
1775
|
+
attempt,
|
|
1776
|
+
storageId: input.storageId,
|
|
1777
|
+
status: getRetryStatus(normalizedError),
|
|
1778
|
+
retryInMs: delay,
|
|
1779
|
+
reason: getRetryReason(normalizedError),
|
|
1780
|
+
});
|
|
1781
|
+
emitCheckpoint(onCheckpoint, {
|
|
1782
|
+
operation: 'download',
|
|
1783
|
+
phase: 'retry',
|
|
1784
|
+
attempt,
|
|
1785
|
+
storageId: input.storageId,
|
|
1786
|
+
attachmentId: input.attachmentId,
|
|
1787
|
+
bytesTransferred: resume?.offsetBytes ?? 0,
|
|
1788
|
+
totalBytes: input.expectedCiphertextSize,
|
|
1789
|
+
resumeToken: resume?.resumeToken,
|
|
1790
|
+
});
|
|
1791
|
+
if (delay > 0) {
|
|
1792
|
+
await sleep(delay);
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
if (lastError instanceof MediaAttachmentError) {
|
|
1797
|
+
throw lastError;
|
|
1798
|
+
}
|
|
1799
|
+
throw new MediaAttachmentError('Media attachment download failed', MediaAttachmentErrorCode.DownloadFailed, { cause: lastError });
|
|
1800
|
+
}
|
|
1801
|
+
function decodeAttachmentKey(key) {
|
|
1802
|
+
try {
|
|
1803
|
+
const keyBytes = base64ToBytes(toBase64(key));
|
|
1804
|
+
if (keyBytes.length !== 32) {
|
|
1805
|
+
throw new Error(`expected 32 bytes, received ${keyBytes.length}`);
|
|
1806
|
+
}
|
|
1807
|
+
return keyBytes;
|
|
1808
|
+
}
|
|
1809
|
+
catch (cause) {
|
|
1810
|
+
throw new MediaAttachmentError('Invalid media attachment pointer: key must be a base64-encoded 32-byte key', MediaAttachmentErrorCode.InvalidPointer, { cause });
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
async function assertDigestMatches(ciphertext, expectedDigest) {
|
|
1814
|
+
let expectedDigestBytes;
|
|
1815
|
+
try {
|
|
1816
|
+
expectedDigestBytes = base64ToBytes(toBase64(expectedDigest));
|
|
1817
|
+
}
|
|
1818
|
+
catch (cause) {
|
|
1819
|
+
throw new MediaAttachmentError('Invalid media attachment pointer: digest must be base64-encoded SHA-256', MediaAttachmentErrorCode.InvalidPointer, { cause });
|
|
1820
|
+
}
|
|
1821
|
+
const actualDigestBytes = await sha256(ciphertext);
|
|
1822
|
+
if (expectedDigestBytes.length !== actualDigestBytes.length ||
|
|
1823
|
+
!constantTimeEqual(expectedDigestBytes, actualDigestBytes)) {
|
|
1824
|
+
throw new MediaAttachmentError('Media attachment digest mismatch', MediaAttachmentErrorCode.DigestMismatch);
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Encrypt and upload media bytes, returning a SDK attachment pointer.
|
|
1829
|
+
*
|
|
1830
|
+
* The encrypted object digest and object ID are computed once. Upload
|
|
1831
|
+
* retries request fresh presigned URLs for that same key, which handles expired
|
|
1832
|
+
* upload URLs without changing the pointer metadata that will be encrypted into
|
|
1833
|
+
* the Signal message.
|
|
1834
|
+
*/
|
|
1835
|
+
export async function prepareMediaAttachmentUpload(data, options) {
|
|
1836
|
+
assertNotAborted(options.signal);
|
|
1837
|
+
const contentType = options.contentType ?? 'application/octet-stream';
|
|
1838
|
+
const clientUuid = options.clientUuid ?? (await generateMediaAttachmentClientUuid());
|
|
1839
|
+
const requestId = options.requestId ?? (await generateMediaAttachmentUploadRequestId());
|
|
1840
|
+
assertString(requestId, 'requestId');
|
|
1841
|
+
assertNotAborted(options.signal);
|
|
1842
|
+
validateMediaAttachmentMetadata({
|
|
1843
|
+
contentType,
|
|
1844
|
+
size: data.length,
|
|
1845
|
+
fileName: options.fileName,
|
|
1846
|
+
caption: options.caption,
|
|
1847
|
+
blurHash: options.blurHash,
|
|
1848
|
+
width: options.width,
|
|
1849
|
+
height: options.height,
|
|
1850
|
+
durationMs: options.durationMs,
|
|
1851
|
+
thumbnail: options.thumbnail,
|
|
1852
|
+
waveform: options.waveform,
|
|
1853
|
+
isViewOnce: options.isViewOnce,
|
|
1854
|
+
flags: options.flags,
|
|
1855
|
+
clientUuid,
|
|
1856
|
+
cdnNumber: options.cdnNumber,
|
|
1857
|
+
}, options.policy);
|
|
1858
|
+
emitProgress(options.onProgress, {
|
|
1859
|
+
operation: 'upload',
|
|
1860
|
+
phase: 'encrypt',
|
|
1861
|
+
bytesTransferred: 0,
|
|
1862
|
+
totalBytes: data.length,
|
|
1863
|
+
});
|
|
1864
|
+
const masterKey = await generateRandomBytes(32);
|
|
1865
|
+
const masterKeyBase64 = bytesToBase64(masterKey);
|
|
1866
|
+
try {
|
|
1867
|
+
assertNotAborted(options.signal);
|
|
1868
|
+
const { ciphertext, segmentSize } = await streamingEncrypt(masterKey, data);
|
|
1869
|
+
assertNotAborted(options.signal);
|
|
1870
|
+
emitProgress(options.onProgress, {
|
|
1871
|
+
operation: 'upload',
|
|
1872
|
+
phase: 'encrypt',
|
|
1873
|
+
bytesTransferred: data.length,
|
|
1874
|
+
totalBytes: data.length,
|
|
1875
|
+
});
|
|
1876
|
+
const digest = bytesToBase64(await sha256(ciphertext));
|
|
1877
|
+
const storageId = await uploadCiphertextWithRetry({
|
|
1878
|
+
remoteObjectStore: options.remoteObjectStore,
|
|
1879
|
+
transfer: options.transfer,
|
|
1880
|
+
retry: options.retry,
|
|
1881
|
+
signal: options.signal,
|
|
1882
|
+
onProgress: options.onProgress,
|
|
1883
|
+
onCheckpoint: options.onCheckpoint,
|
|
1884
|
+
resume: options.resume,
|
|
1885
|
+
ciphertext,
|
|
1886
|
+
requestId,
|
|
1887
|
+
});
|
|
1888
|
+
const pointer = createMediaAttachmentPointer({
|
|
1889
|
+
storageId,
|
|
1890
|
+
key: masterKeyBase64,
|
|
1891
|
+
digest,
|
|
1892
|
+
segmentSize,
|
|
1893
|
+
ciphertextSize: ciphertext.length,
|
|
1894
|
+
contentType,
|
|
1895
|
+
size: data.length,
|
|
1896
|
+
uploadTimestamp: Date.now(),
|
|
1897
|
+
blurHash: options.blurHash,
|
|
1898
|
+
thumbnail: options.thumbnail,
|
|
1899
|
+
width: options.width,
|
|
1900
|
+
height: options.height,
|
|
1901
|
+
durationMs: options.durationMs,
|
|
1902
|
+
waveform: options.waveform,
|
|
1903
|
+
fileName: options.fileName,
|
|
1904
|
+
caption: options.caption,
|
|
1905
|
+
isViewOnce: options.isViewOnce,
|
|
1906
|
+
flags: options.flags,
|
|
1907
|
+
clientUuid,
|
|
1908
|
+
cdnNumber: options.cdnNumber,
|
|
1909
|
+
});
|
|
1910
|
+
validateMediaAttachmentMetadata(pointer, options.policy);
|
|
1911
|
+
emitProgress(options.onProgress, {
|
|
1912
|
+
operation: 'upload',
|
|
1913
|
+
phase: 'complete',
|
|
1914
|
+
storageId: pointer.storageId,
|
|
1915
|
+
bytesTransferred: ciphertext.length,
|
|
1916
|
+
totalBytes: ciphertext.length,
|
|
1917
|
+
});
|
|
1918
|
+
return pointer;
|
|
1919
|
+
}
|
|
1920
|
+
finally {
|
|
1921
|
+
secureZeroBytes(masterKey);
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Download, verify, and decrypt a Signal media attachment pointer.
|
|
1926
|
+
*
|
|
1927
|
+
* This is the safe receive-side counterpart to attachment upload. It validates
|
|
1928
|
+
* pointer metadata, downloads opaque ciphertext from the object store, verifies
|
|
1929
|
+
* length and SHA-256 digest before decryption, then decrypts with the package's
|
|
1930
|
+
* streaming AEAD format.
|
|
1931
|
+
*/
|
|
1932
|
+
export async function resolveMediaAttachment(attachment, options) {
|
|
1933
|
+
const pointer = validateMediaAttachmentPolicy(attachment, options.policy);
|
|
1934
|
+
const ciphertext = await downloadCiphertextWithRetry({
|
|
1935
|
+
remoteObjectStore: options.remoteObjectStore,
|
|
1936
|
+
transfer: options.transfer,
|
|
1937
|
+
retry: options.retry,
|
|
1938
|
+
signal: options.signal,
|
|
1939
|
+
onProgress: options.onProgress,
|
|
1940
|
+
onCheckpoint: options.onCheckpoint,
|
|
1941
|
+
resume: options.resume,
|
|
1942
|
+
storageId: pointer.storageId,
|
|
1943
|
+
attachmentId: createMediaAttachmentId(pointer),
|
|
1944
|
+
expectedCiphertextSize: pointer.ciphertextSize,
|
|
1945
|
+
});
|
|
1946
|
+
assertNotAborted(options.signal);
|
|
1947
|
+
if (ciphertext.length !== pointer.ciphertextSize) {
|
|
1948
|
+
throw new MediaAttachmentError(`Media attachment ciphertext size mismatch: expected ${pointer.ciphertextSize}, received ${ciphertext.length}`, MediaAttachmentErrorCode.CiphertextSizeMismatch);
|
|
1949
|
+
}
|
|
1950
|
+
emitProgress(options.onProgress, {
|
|
1951
|
+
operation: 'download',
|
|
1952
|
+
phase: 'verify',
|
|
1953
|
+
storageId: pointer.storageId,
|
|
1954
|
+
bytesTransferred: ciphertext.length,
|
|
1955
|
+
totalBytes: pointer.ciphertextSize,
|
|
1956
|
+
});
|
|
1957
|
+
await assertDigestMatches(ciphertext, pointer.digest);
|
|
1958
|
+
assertNotAborted(options.signal);
|
|
1959
|
+
const keyBytes = decodeAttachmentKey(pointer.key);
|
|
1960
|
+
try {
|
|
1961
|
+
emitProgress(options.onProgress, {
|
|
1962
|
+
operation: 'download',
|
|
1963
|
+
phase: 'decrypt',
|
|
1964
|
+
storageId: pointer.storageId,
|
|
1965
|
+
bytesTransferred: 0,
|
|
1966
|
+
totalBytes: pointer.size,
|
|
1967
|
+
});
|
|
1968
|
+
const data = await streamingDecrypt(keyBytes, ciphertext, new Uint8Array(0), {
|
|
1969
|
+
segmentSize: pointer.segmentSize,
|
|
1970
|
+
});
|
|
1971
|
+
assertNotAborted(options.signal);
|
|
1972
|
+
if (data.length !== pointer.size) {
|
|
1973
|
+
throw new MediaAttachmentError(`Media attachment plaintext size mismatch: expected ${pointer.size}, received ${data.length}`, MediaAttachmentErrorCode.PlaintextSizeMismatch);
|
|
1974
|
+
}
|
|
1975
|
+
emitProgress(options.onProgress, {
|
|
1976
|
+
operation: 'download',
|
|
1977
|
+
phase: 'decrypt',
|
|
1978
|
+
storageId: pointer.storageId,
|
|
1979
|
+
bytesTransferred: data.length,
|
|
1980
|
+
totalBytes: pointer.size,
|
|
1981
|
+
});
|
|
1982
|
+
emitProgress(options.onProgress, {
|
|
1983
|
+
operation: 'download',
|
|
1984
|
+
phase: 'complete',
|
|
1985
|
+
storageId: pointer.storageId,
|
|
1986
|
+
bytesTransferred: data.length,
|
|
1987
|
+
totalBytes: pointer.size,
|
|
1988
|
+
});
|
|
1989
|
+
return {
|
|
1990
|
+
data,
|
|
1991
|
+
attachment: pointer,
|
|
1992
|
+
contentType: pointer.contentType,
|
|
1993
|
+
size: pointer.size,
|
|
1994
|
+
fileName: pointer.fileName,
|
|
1995
|
+
caption: pointer.caption,
|
|
1996
|
+
width: pointer.width,
|
|
1997
|
+
height: pointer.height,
|
|
1998
|
+
blurHash: pointer.blurHash,
|
|
1999
|
+
thumbnail: pointer.thumbnail,
|
|
2000
|
+
durationMs: pointer.durationMs,
|
|
2001
|
+
waveform: pointer.waveform,
|
|
2002
|
+
isViewOnce: pointer.isViewOnce,
|
|
2003
|
+
flags: pointer.flags,
|
|
2004
|
+
storageId: pointer.storageId,
|
|
2005
|
+
digest: pointer.digest,
|
|
2006
|
+
ciphertextSize: pointer.ciphertextSize,
|
|
2007
|
+
};
|
|
2008
|
+
}
|
|
2009
|
+
catch (error) {
|
|
2010
|
+
if (error instanceof MediaAttachmentError) {
|
|
2011
|
+
throw error;
|
|
2012
|
+
}
|
|
2013
|
+
throw new MediaAttachmentError('Media attachment decryption failed', MediaAttachmentErrorCode.DecryptionFailed, { cause: error });
|
|
2014
|
+
}
|
|
2015
|
+
finally {
|
|
2016
|
+
secureZeroBytes(keyBytes);
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
export async function deleteMediaAttachment(attachment, options) {
|
|
2020
|
+
const pointer = createMediaAttachmentPointer(attachment);
|
|
2021
|
+
assertNotAborted(options.signal);
|
|
2022
|
+
if (!options.remoteObjectStore.deleteObject) {
|
|
2023
|
+
throw new MediaAttachmentError('Media attachment remote delete is unavailable for the configured object store', MediaAttachmentErrorCode.DeleteUnavailable);
|
|
2024
|
+
}
|
|
2025
|
+
try {
|
|
2026
|
+
emitProgress(options.onProgress, {
|
|
2027
|
+
operation: 'delete',
|
|
2028
|
+
phase: 'delete',
|
|
2029
|
+
storageId: pointer.storageId,
|
|
2030
|
+
});
|
|
2031
|
+
await options.remoteObjectStore.deleteObject({
|
|
2032
|
+
objectId: pointer.storageId,
|
|
2033
|
+
});
|
|
2034
|
+
assertNotAborted(options.signal);
|
|
2035
|
+
emitProgress(options.onProgress, {
|
|
2036
|
+
operation: 'delete',
|
|
2037
|
+
phase: 'complete',
|
|
2038
|
+
storageId: pointer.storageId,
|
|
2039
|
+
});
|
|
2040
|
+
return {
|
|
2041
|
+
storageId: pointer.storageId,
|
|
2042
|
+
deletedRemoteObject: true,
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
catch (cause) {
|
|
2046
|
+
if (options.signal?.aborted) {
|
|
2047
|
+
throw new MediaAttachmentError('Media attachment operation cancelled', MediaAttachmentErrorCode.Cancelled, { cause: options.signal.reason });
|
|
2048
|
+
}
|
|
2049
|
+
throw new MediaAttachmentError('Media attachment remote delete failed', MediaAttachmentErrorCode.DeleteFailed, { cause });
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
export const downloadMediaAttachment = resolveMediaAttachment;
|
|
2053
|
+
//# sourceMappingURL=index.js.map
|