-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: implement rsa signer / verifier #102
Merged
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
4a7bbe9
feat: unifiy principals & signers
Gozala 8639961
fix: tests on core
Gozala 5a0b238
fix: transport package
Gozala a5b30e6
chore: update client to 0.9
Gozala ff9c434
feat(validator): update to ucan 0.9
Gozala 15abcb5
feat(server): upgrade to 0.9
Gozala 28f67dd
fix(principal): invalid test
Gozala 2edba5e
chore: update dag-ucan dep
Gozala b7a42d8
feat: rename caveats to nb
Gozala 55c5427
fix(server): type checks
Gozala fc1d659
fix(validator): increase coverage
Gozala 3f58a66
fix(docs): rename caveats to nb
Gozala 2f3a606
chore: merge 'origin/main' into feat/v0.9
Gozala 714cc80
feat: improve decoders
Gozala a878e04
stash: need to work on diff branch
Gozala 0ffc431
stash: need to work on ucant 0.9
Gozala b30eb4a
feat: implement rsa keys
Gozala a1f8971
Merge remote-tracking branch 'origin/main' into feat/rsa
Gozala c933756
chore: remove obsolete code
Gozala e08ea47
fix: messy merge artifact
Gozala 5aca463
feat: add composition operators
Gozala 1cdec2e
chore: disable node14
Gozala 7717f91
fix: address review comments
Gozala 13ed09a
chore: remove format & encode functions
Gozala 695a671
chore: add tests to ensure keys with / work
Gozala 8b54bb4
fix: typo
Gozala 265cb33
Apply suggestions from code review
Gozala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,6 @@ jobs: | |
strategy: | ||
matrix: | ||
node-version: | ||
- 14 | ||
- 16 | ||
os: | ||
- ubuntu-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,8 +14,8 @@ import { | |||||||||
Resource, | ||||||||||
Signature, | ||||||||||
Principal, | ||||||||||
Verifier, | ||||||||||
Signer, | ||||||||||
Verifier as UCANVerifier, | ||||||||||
Signer as UCANSigner, | ||||||||||
} from '@ipld/dag-ucan' | ||||||||||
import * as UCAN from '@ipld/dag-ucan' | ||||||||||
import { | ||||||||||
|
@@ -39,8 +39,6 @@ export * from './transport.js' | |||||||||
export type { | ||||||||||
Transport, | ||||||||||
Principal, | ||||||||||
Verifier, | ||||||||||
Signer, | ||||||||||
Phantom, | ||||||||||
Tuple, | ||||||||||
DID, | ||||||||||
|
@@ -388,7 +386,23 @@ export type URI<P extends Protocol = Protocol> = `${P}${string}` & | |||||||||
}> | ||||||||||
|
||||||||||
export interface PrincipalParser { | ||||||||||
parse(did: UCAN.DID): UCAN.Verifier | ||||||||||
parse(did: UCAN.DID): Verifier | ||||||||||
} | ||||||||||
|
||||||||||
export interface IntoSigner { | ||||||||||
decode: (bytes: Uint8Array) => Signer | ||||||||||
} | ||||||||||
|
||||||||||
export interface Signer<M extends string = string, A extends number = number> | ||||||||||
extends UCANSigner<M, A> { | ||||||||||
export?: () => Await<ByteView<Signer<M, A>>> | ||||||||||
toCryptoKey?: () => Await<CryptoKey> | ||||||||||
} | ||||||||||
|
||||||||||
export interface Verifier<M extends string = string, A extends number = number> | ||||||||||
extends UCANVerifier<M, A> { | ||||||||||
export?: () => Await<ByteView<Verifier<M, A>>> | ||||||||||
toCryptoKey?: () => Await<CryptoKey> | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
} | ||||||||||
|
||||||||||
export type InferInvokedCapability< | ||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||||
import { Signer, Verifier, ByteView, UCAN, Await } from '@ucanto/interface' | ||||||||
import * as Signature from '@ipld/dag-ucan/signature' | ||||||||
|
||||||||
export * from '@ucanto/interface' | ||||||||
|
||||||||
type CODE = typeof Signature.EdDSA | ||||||||
type ALG = 'EdDSA' | ||||||||
|
||||||||
export interface EdSigner<M extends string = 'key'> | ||||||||
extends Signer<M, CODE>, | ||||||||
UCAN.Verifier<M, CODE> { | ||||||||
readonly signer: EdSigner<M> | ||||||||
readonly verifier: EdVerifier<M> | ||||||||
|
||||||||
readonly code: 0x1300 | ||||||||
encode(): ByteView<EdSigner<M>> | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} | ||||||||
|
||||||||
export interface EdVerifier<M extends string = 'key'> | ||||||||
extends Verifier<M, CODE> { | ||||||||
readonly code: 0xed | ||||||||
readonly signatureCode: CODE | ||||||||
readonly signatureAlgorithm: ALG | ||||||||
|
||||||||
encode: () => ByteView<EdVerifier<M>> | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
export * as ed25519 from './ed25519.js' | ||
import * as ed25519 from './ed25519.js' | ||
import * as RSA from './rsa.js' | ||
import { create as createVerifier } from './verifier.js' | ||
import { create as createSigner } from './signer.js' | ||
|
||
export const Verifier = createVerifier([ed25519.Verifier, RSA.Verifier]) | ||
export const Signer = createSigner([ed25519, RSA]) | ||
|
||
export { ed25519, RSA } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { varint } from 'multiformats' | ||
|
||
/** | ||
* | ||
* @param {number} code | ||
* @param {Uint8Array} bytes | ||
*/ | ||
export const tagWith = (code, bytes) => { | ||
const offset = varint.encodingLength(code) | ||
const multiformat = new Uint8Array(bytes.byteLength + offset) | ||
varint.encodeTo(code, multiformat, 0) | ||
multiformat.set(bytes, offset) | ||
|
||
return multiformat | ||
} | ||
|
||
/** | ||
* @param {number} code | ||
* @param {Uint8Array} source | ||
* @param {number} byteOffset | ||
* @returns | ||
*/ | ||
export const untagWith = (code, source, byteOffset = 0) => { | ||
const bytes = byteOffset !== 0 ? source.subarray(byteOffset) : source | ||
const [tag, size] = varint.decode(bytes) | ||
if (tag !== code) { | ||
throw new Error( | ||
`Expected multiformat with 0x${code.toString( | ||
16 | ||
)} tag instead got 0x${tag.toString(16)}` | ||
) | ||
} else { | ||
return new Uint8Array(bytes.buffer, bytes.byteOffset + size) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.