Skip to content

SubtleCrypto

Defined in: packages/core/src/auth-subtlecrypto.ts:31

SubtleCrypto implements AuthProvider using WebCrypto’s Subtle API.

Supports AES-GCM (default, AEAD), AES-CTR, and AES-CBC. For non-AEAD modes (CTR, CBC) an encrypt-then-MAC (HMAC-SHA256) construction is used automatically to provide ciphertext authentication.

The base keytype is CryptoKey.

new SubtleCrypto(signingAlgorithm?, _encryptionAlgorithmName?): SubtleCrypto

Defined in: packages/core/src/auth-subtlecrypto.ts:44

Nonce size follows the configured encryption algorithm: 12 bytes for GCM and 16 bytes for CTR/CBC, exposed by the nonceBytes getter.

AlgorithmIdentifier | AesCbcParams | RsaPssParams | EcdsaParams

The type of algorithm used for signature and verification keys.

Remarks

https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/sign

AesAlgorithmName = 'AES-GCM'

The encryption algorithm to use for encrypt/decrypt.

AES-GCM provides built-in AEAD. AES-CTR and AES-CBC use an encrypt-then-MAC (HMAC-SHA256) construction for authentication.

SubtleCrypto

readonly _encryptionAlgorithmName: AesAlgorithmName = 'AES-GCM'

Defined in: packages/core/src/auth-subtlecrypto.ts:65

The encryption algorithm to use for encrypt/decrypt.

AES-GCM provides built-in AEAD. AES-CTR and AES-CBC use an encrypt-then-MAC (HMAC-SHA256) construction for authentication.


readonly initialInvitationCapacityProfile: "peerborne-automerge-json-subtle-p384-v1" = INITIAL_INVITATION_CAPACITY_PROFILE

Defined in: packages/core/src/auth-subtlecrypto.ts:34


readonly signingAlgorithm: AlgorithmIdentifier | AesCbcParams | RsaPssParams | EcdsaParams

Defined in: packages/core/src/auth-subtlecrypto.ts:50

The type of algorithm used for signature and verification keys.

https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/sign

get nonceBytes(): number

Defined in: packages/core/src/auth-subtlecrypto.ts:114

Returns the nonce/IV size in bytes for the configured encryption algorithm.

  • AES-GCM: 12 bytes (96-bit IV, standard)
  • AES-CTR: 16 bytes (128-bit counter block)
  • AES-CBC: 16 bytes (128-bit IV)

number

Returns the nonce/IV size in bytes for the configured encryption algorithm.

AuthProvider.nonceBytes

_encryptionAlgorithmParams(nonce?): AesCtrParams | AesCbcParams | AesGcmParams

Defined in: packages/core/src/auth-subtlecrypto.ts:159

Generate algorithm parameters for the configured encryption algorithm.

Uint8Array<ArrayBufferLike>

If provided, used as the IV/counter. Otherwise a random one is generated.

AesCtrParams | AesCbcParams | AesGcmParams


decrypt(data, documentKey, nonce?): Promise<Uint8Array<ArrayBufferLike>>

Defined in: packages/core/src/auth-subtlecrypto.ts:352

Decrypt data using the configured encryption algorithm.

For AES-GCM, authentication is built-in (AEAD). For AES-CTR and AES-CBC, the HMAC-SHA256 tag appended by encrypt() is verified before decryption to prevent padding oracle attacks (CBC) and ciphertext tampering (CTR).

Uint8Array

CryptoKey

Uint8Array<ArrayBufferLike>

Promise<Uint8Array<ArrayBufferLike>>

AuthProvider.decrypt


deserializePublicKey(serialized): Promise<CryptoKey>

Defined in: packages/core/src/auth-subtlecrypto.ts:326

Import a canonical P-384 ECDSA identity encoded by serializePublicKey. Invitation authentication deliberately pins this exact algorithm and curve; custom identity schemes must provide their own AuthProvider.deserializePublicKey implementation.

string

Promise<CryptoKey>

AuthProvider.deserializePublicKey


encrypt(data, documentKey): Promise<SubtleCryptoEncryptionResult>

Defined in: packages/core/src/auth-subtlecrypto.ts:410

Encrypt data using the configured encryption algorithm.

For AES-CTR and AES-CBC, an HMAC-SHA256 tag over (nonce || ciphertext) is appended to the returned data for authentication. The document layer treats this as opaque ciphertext — the wire format is unchanged.

Uint8Array

CryptoKey

Promise<SubtleCryptoEncryptionResult>

AuthProvider.encrypt


serializePublicKey(publicKey): Promise<string>

Defined in: packages/core/src/auth-subtlecrypto.ts:307

Serialize a public CryptoKey to a stable base64-encoded string.

The encoding matches the one used by ACLs and keychain entries in the yjs and automerge providers (exportKey('raw', ...) + Base64), so a welcomeRecipient value attached by one peer is directly comparable to another peer’s serialized public key.

The key must be extractable; this is satisfied for all keys imported or generated by the SubtleCrypto provider in this codebase.

CryptoKey

Promise<string>

AuthProvider.serializePublicKey


sign(data, privateKey): Promise<Uint8Array<ArrayBufferLike>>

Defined in: packages/core/src/auth-subtlecrypto.ts:261

Given data and a private key, returns a signature.

Uint8Array

bytes to be signed

CryptoKey

part of key pair used to sign and verify

Promise<Uint8Array<ArrayBufferLike>>

signature over the data

AuthProvider.sign


supportsInitialInvitationCapacity(privateKey, publicKey): boolean

Defined in: packages/core/src/auth-subtlecrypto.ts:69

Internal

Confirm the exact bounded identity/crypto invitation profile.

CryptoKey

CryptoKey

boolean


verify(data, publicKey, signature): Promise<boolean>

Defined in: packages/core/src/auth-subtlecrypto.ts:282

Given a signature and the signed data, a Promise that fulfills with true if the signature is valid, false otherwise

Uint8Array

data that was signed

CryptoKey

part of key pair used to sign and verify

Uint8Array

signature to verify

Promise<boolean>

a Promise that fulfills with true if the signature is valid, false otherwise

AuthProvider.verify