Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing JWE for P256 #295

Closed
wants to merge 113 commits into from
Closed
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
aaedaf5
add ES256Signer Module
bshambaugh Jan 10, 2022
ae80a5a
update base58 test, it appears to have a problem
bshambaugh Jan 10, 2022
52646fd
update with failing test for base58
bshambaugh Jan 10, 2022
ac8e814
modify base58matcher to match both base58 in es256 and es256k
bshambaugh Jan 16, 2022
27fd5ea
change 68 to 86 in base58 matcher
bshambaugh Jan 16, 2022
3835342
remove uneccessary = sign in the base64 regex
bshambaugh Jan 16, 2022
7c26c1a
add ES256Signer to index so it is acessible
bshambaugh Jan 17, 2022
333fa55
refactor SignerAlgorithm.ts and SignerAlgorithm.test.ts by breaking u…
bshambaugh Jan 18, 2022
f9ed034
move tests for signers into folder called signers
bshambaugh Jan 18, 2022
85a5cbc
remove carriage returns (should be result of enter) and unused variab…
bshambaugh Jan 18, 2022
ac795f0
break up verifierAlgorithm into separate files bases on Curve
bshambaugh Jan 18, 2022
9d108ad
add preliminary tests for JWT
bshambaugh Jan 19, 2022
635eb7e
refactor VerifierAlgorithm test
bshambaugh Jan 20, 2022
622a7d1
update JWT tests
bshambaugh Jan 22, 2022
62e6f7d
update ES256Signer with constants
bshambaugh Jan 22, 2022
dcdeeb5
change the name of constants to common in JWT test folder
bshambaugh Jan 23, 2022
e498f41
add tests for JWT common
bshambaugh Jan 24, 2022
d8dccf9
add ES256 to Signer Verifier and JWT ...tests needed
bshambaugh Jan 24, 2022
61e9928
add note about supported key types in JWT, Signer, and Verifier Algor…
bshambaugh Jan 25, 2022
20c1ebe
in common_Signer_test_test.ts the create JWK functions need to be tes…
bshambaugh Feb 7, 2022
8b18d4e
added test to for comosmos adress from public key to keep consistent …
bshambaugh Mar 10, 2022
0c1c1fd
commit stub for decrypt / encrypt JWE Decrypter impl. for P-256
bshambaugh Mar 10, 2022
f312794
reverse base64matcher to original version that will match '=' sign, o…
bshambaugh Mar 22, 2022
8a38d4c
add a second matcher for base58 to util.test.ts to illustrate variabl…
bshambaugh Mar 27, 2022
027f701
remove encrypters and clean up to remote forks state
bshambaugh Apr 1, 2022
f39c88e
update util.ts with latest matcher
bshambaugh Apr 1, 2022
92e2bff
util.ts to fork
bshambaugh Apr 1, 2022
6dcb134
util.ts to fork try 2
bshambaugh Apr 1, 2022
9c0b48b
reset util.test.ts to fork
bshambaugh Apr 1, 2022
a0cd2a2
remove cosmos test because it is not upstream
bshambaugh Apr 1, 2022
c8fdae8
keep SignerAlgorithm the same as with upstream
bshambaugh Apr 1, 2022
71d970e
keep verifierAlgorithm.test.ts in line with upstream
bshambaugh Apr 1, 2022
358872d
set ES256KSigner.test.ts to upstream
bshambaugh Apr 1, 2022
f5a108a
change JWT.test.test to be in line with upstream
bshambaugh Apr 1, 2022
27f7f76
get VerifierAlgorithm in line with upstream
bshambaugh Apr 1, 2022
bc260fd
get SignerAlgorithm in line with upstream
bshambaugh Apr 1, 2022
e0f0e4f
update JWT.ts to be in line with upstream
bshambaugh Apr 1, 2022
28f04a7
update package.json to match upstream
bshambaugh Apr 1, 2022
17cba29
update package.json to match upstream try 2
bshambaugh Apr 1, 2022
c0b2791
add JWT.test.ts.snap
bshambaugh Apr 1, 2022
ca8a2e8
add yarn.lock to match upstream
bshambaugh Apr 1, 2022
129f566
remove parseKey from Signers as well as base64, 58, and hex matchers
bshambaugh Apr 1, 2022
b4fc0e2
remove commented out code with ES256KSigner.test.ts
bshambaugh Apr 1, 2022
9e4e33e
update README and export functions that convert hex, base64, and base…
bshambaugh Apr 2, 2022
dbf34ef
fix documentation for ES256KSigner
bshambaugh Apr 2, 2022
a2c7e6a
Merge remote-tracking branch 'upstream/master'
bshambaugh Aug 3, 2022
fa61104
remove extra line at the end of the files
bshambaugh Aug 5, 2022
a97d6a9
add newline to each of the files
bshambaugh Aug 5, 2022
a3b8fb4
create a ES256Signer
bshambaugh Aug 5, 2022
4e0a669
Add ES256Signer Tests
bshambaugh Aug 5, 2022
5b0cecf
update fixes suggested by linter
bshambaugh Aug 6, 2022
169e7bd
removed recoverable parameter from ES256Signer since only recoverable…
bshambaugh Sep 2, 2022
7b02c56
add code specific to ES256 and P-256 to SignerAlgorithm.ts
bshambaugh Sep 2, 2022
636de24
created files for verifieralgorithm.ts, tests do not pass..merge with…
bshambaugh Sep 2, 2022
b06fca3
Merge branch 'addES256VerifierAlg' into addES256SignerandVeriferAlg
bshambaugh Sep 2, 2022
3a4e4bc
move signer declaration to match interface
bshambaugh Sep 2, 2022
c789049
fix merge conflict with ES256Signer and test
bshambaugh Sep 2, 2022
e8b46a2
Merge branch 'master' into addES256SignerandVeriferAlg
bshambaugh Sep 2, 2022
d73bd52
update verifieralgorithm and tests with ES256
bshambaugh Sep 2, 2022
c7ab289
Merge branch 'master' of github.com:bshambaugh/did-jwt
bshambaugh Sep 2, 2022
de5fc43
add tests to JWT for ES256
bshambaugh Sep 24, 2022
c74f938
temporarily comment out failing tests
bshambaugh Oct 1, 2022
8938a0d
create backup __tests__/JWT.test.ts
bshambaugh Oct 3, 2022
a7d99f9
add comments to ES256K code
bshambaugh Oct 3, 2022
b68692d
start redo of tests to JWT.test.ts
bshambaugh Oct 3, 2022
29e587d
updated JWT.test.ts to update with ES256
bshambaugh Oct 3, 2022
8291c73
update JWT.test.ts have ES256
bshambaugh Oct 3, 2022
f22a7b1
update with typescript types and move to dev for jwkToPem and jsonwe…
bshambaugh Oct 7, 2022
c54b109
Pull in remote did-jwt to keep VerifierAlgorithm
bshambaugh Oct 7, 2022
446e03d
removed EcdsaSecp256r1VerificationKey2022 in preference of JsonWebKey…
bshambaugh Oct 10, 2022
ca7c479
remove package-lock.json, prefer and keep yarn.lock
bshambaugh Oct 14, 2022
d6611ae
update main branch to upstream
bshambaugh Apr 6, 2023
e3bbe5a
Merge branch 'master' of https://github.com/decentralized-identity/di…
bshambaugh Sep 14, 2023
3385ea0
added preliminary updates to ECDH.ts for P256 to iniate discussion on…
bshambaugh Sep 22, 2023
24efe3c
add removed yarn.lock file
bshambaugh Sep 30, 2023
7574907
add modified yarn lock to match remote
bshambaugh Sep 30, 2023
4036833
Merge remote-tracking branch 'upstream/master'
bshambaugh Sep 30, 2023
cf8e7f3
ECDHkw improvements
bshambaugh Nov 20, 2023
1064144
update a256kw with veramo distribution
bshambaugh Nov 21, 2023
3727066
create backup of in process X25519 branch
bshambaugh Nov 23, 2023
d444217
commit package-lock.json
bshambaugh Nov 23, 2023
ebb6d6d
get a basic skeleton in place, resolveX25519Encrypters needs fix
bshambaugh Nov 25, 2023
c63f171
add resolve p256Encrypter
bshambaugh Nov 26, 2023
9f789df
add p256Decrypter to xc20pEncryption.js and add P256 tests in xc20pEn…
bshambaugh Nov 26, 2023
83d06c6
update conditional on createEncrypter (ephemeralKeyPair?.publicKeyJWK…
bshambaugh Nov 26, 2023
75874be
say Encrypters.ts needs fix for ephemeralKeyPair
bshambaugh Nov 26, 2023
0a7b1fb
added index Signature to prefixToDriverMap plus added updated functio…
bshambaugh Nov 27, 2023
0caf664
replace imported functions for X25519 with those for P-256
bshambaugh Nov 27, 2023
fa7c08e
update exports in src/index.ts to reflect updates in xc20p
bshambaugh Nov 27, 2023
9583494
merge X25519-ECDH-1PU-ES branch into as256kwExperiments
bshambaugh Nov 28, 2023
ecf6673
remove unused imports in encrpytion/P256-ECDH*.ts
bshambaugh Nov 28, 2023
a197877
remove unused prefixToDriverMap prototypes
bshambaugh Nov 28, 2023
e43eb4c
Merge branch 'X25519-ECDH-1PU-ES' into as256kwExperiments
bshambaugh Nov 28, 2023
b6c2c62
remove creatP256Encrypter from createEncrypter.ts since it is unused
bshambaugh Nov 28, 2023
01bba7f
change createP256FullEncrypter to createFullEncrypter
bshambaugh Nov 28, 2023
43443fa
added comment about a256kw.tw from did/veramo
bshambaugh Nov 29, 2023
91080a4
remove package-lock.json
bshambaugh Nov 29, 2023
595d658
backup modified files
bshambaugh Dec 1, 2023
1813099
remove unecessary a256kwEncrpytion test
bshambaugh Dec 1, 2023
3eb9a16
update P236KeyAgreementKey from 2019 to 2023
bshambaugh Dec 1, 2023
724442f
add key unwrapping to dir anon decrypter to pass test. add unwrapping…
bshambaugh Dec 1, 2023
e0da697
add comments to a256gcmEncryption.ts for further exploration
bshambaugh Dec 1, 2023
9717af9
fix typo in tests so all tests pass
bshambaugh Dec 2, 2023
6b09dd0
update genEphemeral keypair function in utils to use P256 and update …
bshambaugh Dec 2, 2023
19e274c
merge branch a256kwExperiments
bshambaugh Dec 2, 2023
c0dbf49
remove todo comments for Auth and Anon Encrypters and Decrypters
bshambaugh Dec 2, 2023
8aa4340
remove unused library @noble/ciphers, use @stablelib/aes @stablelib/g…
bshambaugh Dec 2, 2023
125694f
change KeyAgreement[2019/2020] to KeyAgreement2023
bshambaugh Dec 3, 2023
fcf3ded
change encryption/decryption alg in a256gcm to use EcdhEs not Echdh1PU
bshambaugh Dec 3, 2023
53a005a
remove P256-ECDH-1PU.js include in a256gcmEncryption.ts
bshambaugh Dec 4, 2023
04e273e
commit preliminary Auth tests
bshambaugh Dec 4, 2023
909bdff
add failing tests for Auth Dir Encrypter and Decrypter
bshambaugh Dec 4, 2023
705db84
remove a256gcmAuth Encrypters and Decrypters
bshambaugh Jan 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/encryption/ECDH.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { x25519 } from '@noble/curves/ed25519'
import { p256 } from '@noble/curves/p256'
import type { ECDH } from './types.js'

/**
Expand All @@ -19,3 +20,22 @@ export function createX25519ECDH(mySecretKey: Uint8Array): ECDH {
return x25519.getSharedSecret(mySecretKey, theirPublicKey)
}
}

/**
* Wraps an P256 secret key into an ECDH method that can be used to compute a shared secret with a public key.
* @param mySecretKey A `Uint8Array` of length 32 representing the bytes of my secret key
* @returns an `ECDH` method with the signature `(theirPublicKey: Uint8Array) => Promise<Uint8Array>`
*
* @throws 'invalid_argument:...' if the secret key size is wrong
*/
export function createP256ECDH(mySecretKey: Uint8Array): ECDH {
if (mySecretKey.length !== 32) {
throw new Error('invalid_argument: incorrect secret key length for P256')
}
return async (theirPublicKey: Uint8Array): Promise<Uint8Array> => {
if (theirPublicKey.length !== 33) {
throw new Error('invalid_argument: incorrect publicKey key length for P256')
}
return p256.getSharedSecret(mySecretKey, theirPublicKey)
}
}
Loading