-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/decoders-dsl
- Loading branch information
Showing
24 changed files
with
1,812 additions
and
156 deletions.
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
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,24 @@ | ||
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 | ||
toArchive(): ByteView<EdSigner<M>> | ||
} | ||
|
||
export interface EdVerifier<M extends string = 'key'> | ||
extends Verifier<M, CODE> { | ||
readonly code: 0xed | ||
readonly signatureCode: CODE | ||
readonly signatureAlgorithm: ALG | ||
} |
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.