Skip to content

Instantly share code, notes, and snippets.

@bshambaugh
Created December 4, 2023 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bshambaugh/234b1e335b2772a6eec0d4019f14d34d to your computer and use it in GitHub Desktop.
Save bshambaugh/234b1e335b2772a6eec0d4019f14d34d to your computer and use it in GitHub Desktop.
tests of encrypter and decrypter Auth
brent@brent-P65-67HSHP:~/Downloads/did-jwt$ npm run test
> did-jwt@7.4.1 test
> cross-env NODE_OPTIONS="--experimental-vm-modules" jest
(node:37871) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
PASS src/__tests__/NaclSigner.test.ts (8.837 s)
(node:37868) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
PASS src/__tests__/SignerAlgorithm.test.ts (10.298 s)
(node:37849) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
PASS src/__tests__/JWE.test.ts (11.023 s)
(node:37853) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
PASS src/__tests__/xc20pEncryption.test.ts (11.194 s)
PASS src/__tests__/ES256Signer.test.ts
PASS src/__tests__/ES256KSigner.test.ts
PASS src/__tests__/SimpleSigner.test.ts
PASS src/__tests__/EdDSASigner.test.ts
(node:37866) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
PASS src/__tests__/VerifierAlgorithm.test.ts (12.184 s)
PASS src/__tests__/EllipticSigner.test.ts
PASS src/__tests__/Digest.test.ts
PASS src/__tests__/didkey.test.ts
PASS src/__tests__/util.test.ts
FAIL src/__tests__/a256gcmEncryption.test.ts (8.423 s)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › One recipient › Creates with only ciphertext
first arg must be private key
13 | let sharedSecret
14 | if (receiverSecret instanceof Uint8Array) {
> 15 | sharedSecret = p256.getSharedSecret(receiverSecret, publicKey)
| ^
16 | } else {
17 | sharedSecret = await receiverSecret(publicKey)
18 | }
at Object.getSharedSecret (node_modules/@noble/curves/src/abstract/weierstrass.ts:907:36)
at computeP256EcdhEsKek (src/encryption/P256-ECDH-ES.ts:15:25)
at Object.decrypt (src/encryption/a256gcmEncryption.ts:172:23)
at decryptJWE (src/encryption/JWE.ts:88:37)
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:771:20)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › One recipient › Creates with only ciphertext
expect.assertions(3)
Expected three assertions to be called but received two assertion calls.
765 | it('Creates with only ciphertext', async () => {
766 | const encrypter = a256gcmAuthEncrypterEcdhESp256WithA256KW(recipientKey.publicKey,sharedSecret)
> 767 | expect.assertions(3)
| ^
768 | const jwe = await createJWE(cleartext, [encrypter])
769 | expect(jwe.aad).toBeUndefined()
770 | expect(JSON.parse(decodeBase64url(jwe.protected))).toEqual({ enc: 'A256GCM' })
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:767:14)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › One recipient › Creates with kid, no apu and no apv
first arg must be private key
13 | let sharedSecret
14 | if (receiverSecret instanceof Uint8Array) {
> 15 | sharedSecret = p256.getSharedSecret(receiverSecret, publicKey)
| ^
16 | } else {
17 | sharedSecret = await receiverSecret(publicKey)
18 | }
at Object.getSharedSecret (node_modules/@noble/curves/src/abstract/weierstrass.ts:907:36)
at computeP256EcdhEsKek (src/encryption/P256-ECDH-ES.ts:15:25)
at Object.decrypt (src/encryption/a256gcmEncryption.ts:172:23)
at decryptJWE (src/encryption/JWE.ts:88:37)
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:784:20)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › One recipient › Creates with kid, no apu and no apv
expect.assertions(6)
Expected six assertions to be called but received five assertion calls.
775 | const kid = 'did:example:receiver#key-1'
776 | const encrypter = a256gcmAuthEncrypterEcdhESp256WithA256KW(recipientKey.publicKey, sharedSecret,{kid: kid})
> 777 | expect.assertions(6)
| ^
778 | const jwe = await createJWE(cleartext, [encrypter])
779 | expect(jwe.aad).toBeUndefined()
780 | expect(JSON.parse(decodeBase64url(jwe.protected))).toEqual({ enc: 'A256GCM' })
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:777:14)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › One recipient › Creates with no kid, with apv
first arg must be private key
13 | let sharedSecret
14 | if (receiverSecret instanceof Uint8Array) {
> 15 | sharedSecret = p256.getSharedSecret(receiverSecret, publicKey)
| ^
16 | } else {
17 | sharedSecret = await receiverSecret(publicKey)
18 | }
at Object.getSharedSecret (node_modules/@noble/curves/src/abstract/weierstrass.ts:907:36)
at computeP256EcdhEsKek (src/encryption/P256-ECDH-ES.ts:15:25)
at Object.decrypt (src/encryption/a256gcmEncryption.ts:172:23)
at decryptJWE (src/encryption/JWE.ts:88:37)
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:796:20)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › One recipient › Creates with no kid, with apv
expect.assertions(5)
Expected five assertions to be called but received four assertion calls.
788 | const apv = encodeBase64url('Bob')
789 | const encrypter = a256gcmAuthEncrypterEcdhESp256WithA256KW(recipientKey.publicKey,sharedSecret,{kid: undefined, apv: apv})
> 790 | expect.assertions(5)
| ^
791 | const jwe = await createJWE(cleartext, [encrypter])
792 | expect(jwe.aad).toBeUndefined()
793 | expect(JSON.parse(decodeBase64url(jwe.protected))).toEqual({ enc: 'A256GCM' })
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:790:14)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › One recipient › Creates with kid and apv
first arg must be private key
13 | let sharedSecret
14 | if (receiverSecret instanceof Uint8Array) {
> 15 | sharedSecret = p256.getSharedSecret(receiverSecret, publicKey)
| ^
16 | } else {
17 | sharedSecret = await receiverSecret(publicKey)
18 | }
at Object.getSharedSecret (node_modules/@noble/curves/src/abstract/weierstrass.ts:907:36)
at computeP256EcdhEsKek (src/encryption/P256-ECDH-ES.ts:15:25)
at Object.decrypt (src/encryption/a256gcmEncryption.ts:172:23)
at decryptJWE (src/encryption/JWE.ts:88:37)
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:809:20)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › One recipient › Creates with kid and apv
expect.assertions(5)
Expected five assertions to be called but received four assertion calls.
801 | const apv = encodeBase64url('Bob')
802 | const encrypter = a256gcmAuthEncrypterEcdhESp256WithA256KW(recipientKey.publicKey,sharedSecret,{kid: kid, apv: apv})
> 803 | expect.assertions(5)
| ^
804 | const jwe = await createJWE(cleartext, [encrypter])
805 | expect(jwe.aad).toBeUndefined()
806 | expect(JSON.parse(decodeBase64url(jwe.protected))).toEqual({ enc: 'A256GCM' })
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:803:14)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › One recipient › Creates with data in protected header
first arg must be private key
13 | let sharedSecret
14 | if (receiverSecret instanceof Uint8Array) {
> 15 | sharedSecret = p256.getSharedSecret(receiverSecret, publicKey)
| ^
16 | } else {
17 | sharedSecret = await receiverSecret(publicKey)
18 | }
at Object.getSharedSecret (node_modules/@noble/curves/src/abstract/weierstrass.ts:907:36)
at computeP256EcdhEsKek (src/encryption/P256-ECDH-ES.ts:15:25)
at Object.decrypt (src/encryption/a256gcmEncryption.ts:172:23)
at decryptJWE (src/encryption/JWE.ts:88:37)
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:819:20)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › One recipient › Creates with data in protected header
expect.assertions(3)
Expected three assertions to be called but received two assertion calls.
813 | const encrypter = a256gcmAuthEncrypterEcdhESp256WithA256KW(recipientKey.publicKey,sharedSecret)
814 | const skid = 'did:example:sender#key-1'
> 815 | expect.assertions(3)
| ^
816 | const jwe = await createJWE(cleartext, [encrypter], { skid, more: 'protected' })
817 | expect(jwe.aad).toBeUndefined()
818 | expect(JSON.parse(decodeBase64url(jwe.protected))).toEqual({ enc: 'A256GCM', skid, more: 'protected' })
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:815:14)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › One recipient › Creates with aad
first arg must be private key
13 | let sharedSecret
14 | if (receiverSecret instanceof Uint8Array) {
> 15 | sharedSecret = p256.getSharedSecret(receiverSecret, publicKey)
| ^
16 | } else {
17 | sharedSecret = await receiverSecret(publicKey)
18 | }
at Object.getSharedSecret (node_modules/@noble/curves/src/abstract/weierstrass.ts:907:36)
at computeP256EcdhEsKek (src/encryption/P256-ECDH-ES.ts:15:25)
at Object.decrypt (src/encryption/a256gcmEncryption.ts:172:23)
at decryptJWE (src/encryption/JWE.ts:88:37)
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:829:20)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › One recipient › Creates with aad
expect.assertions(4)
Expected four assertions to be called but received two assertion calls.
822 | it('Creates with aad', async () => {
823 | const encrypter = a256gcmAuthEncrypterEcdhESp256WithA256KW(recipientKey.publicKey,sharedSecret)
> 824 | expect.assertions(4)
| ^
825 | const aad = fromString('this data is authenticated')
826 | const jwe = await createJWE(cleartext, [encrypter], { more: 'protected' }, aad)
827 | expect(fromString(jwe.aad!!, 'base64url')).toEqual(aad)
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:824:14)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › One recipient › using remote ECDH › creates JWE with remote ECDH
first arg must be private key
13 | let sharedSecret
14 | if (receiverSecret instanceof Uint8Array) {
> 15 | sharedSecret = p256.getSharedSecret(receiverSecret, publicKey)
| ^
16 | } else {
17 | sharedSecret = await receiverSecret(publicKey)
18 | }
at Object.getSharedSecret (node_modules/@noble/curves/src/abstract/weierstrass.ts:907:36)
at computeP256EcdhEsKek (src/encryption/P256-ECDH-ES.ts:15:25)
at Object.decrypt (src/encryption/a256gcmEncryption.ts:172:23)
at decryptJWE (src/encryption/JWE.ts:88:37)
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:843:38)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › Multiple recipients › Creates with only ciphertext
private key must be 32 bytes, hex or bigint, not undefined
867 | recipients[0].kid,
868 | ),
> 869 | decrypter: a256gcmAuthDecrypterEcdhP256WithA256KW(p256.getSharedSecret(senderkey.secretKeyKey, recipients[0].recipientkey.publicKey),recipients[0].recipientkey.publicKey),
| ^
870 | },
871 | }
872 |
at normPrivateKeyToScalar (node_modules/@noble/curves/src/abstract/weierstrass.ts:252:13)
at Object.getSharedSecret (node_modules/@noble/curves/src/abstract/weierstrass.ts:910:23)
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:869:66)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › Multiple recipients › Creates with data in protected header
private key must be 32 bytes, hex or bigint, not undefined
867 | recipients[0].kid,
868 | ),
> 869 | decrypter: a256gcmAuthDecrypterEcdhP256WithA256KW(p256.getSharedSecret(senderkey.secretKeyKey, recipients[0].recipientkey.publicKey),recipients[0].recipientkey.publicKey),
| ^
870 | },
871 | }
872 |
at normPrivateKeyToScalar (node_modules/@noble/curves/src/abstract/weierstrass.ts:252:13)
at Object.getSharedSecret (node_modules/@noble/curves/src/abstract/weierstrass.ts:910:23)
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:869:66)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › Multiple recipients › Creates with aad
private key must be 32 bytes, hex or bigint, not undefined
867 | recipients[0].kid,
868 | ),
> 869 | decrypter: a256gcmAuthDecrypterEcdhP256WithA256KW(p256.getSharedSecret(senderkey.secretKeyKey, recipients[0].recipientkey.publicKey),recipients[0].recipientkey.publicKey),
| ^
870 | },
871 | }
872 |
at normPrivateKeyToScalar (node_modules/@noble/curves/src/abstract/weierstrass.ts:252:13)
at Object.getSharedSecret (node_modules/@noble/curves/src/abstract/weierstrass.ts:910:23)
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:869:66)
● ECDH-ES+A256KW (P-256) Auth, Key Wrapping Mode with A256GCM content encryption › Multiple recipients › Incompatible encrypters throw
private key must be 32 bytes, hex or bigint, not undefined
867 | recipients[0].kid,
868 | ),
> 869 | decrypter: a256gcmAuthDecrypterEcdhP256WithA256KW(p256.getSharedSecret(senderkey.secretKeyKey, recipients[0].recipientkey.publicKey),recipients[0].recipientkey.publicKey),
| ^
870 | },
871 | }
872 |
at normPrivateKeyToScalar (node_modules/@noble/curves/src/abstract/weierstrass.ts:252:13)
at Object.getSharedSecret (node_modules/@noble/curves/src/abstract/weierstrass.ts:910:23)
at Object.<anonymous> (src/__tests__/a256gcmEncryption.test.ts:869:66)
(node:37848) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
PASS src/__tests__/ConditionalAlgorithm.test.ts (19.998 s)
(node:37847) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
PASS src/__tests__/JWT.test.ts (20.181 s)
Test Suites: 1 failed, 15 passed, 16 total
Tests: 11 failed, 349 passed, 360 total
Snapshots: 20 passed, 20 total
Time: 20.995 s
Ran all test suites.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment