@ucanto/principal
Advanced tools
Comparing version 3.0.1 to 4.0.0
export const code: 4864; | ||
export const name: "Ed25519"; | ||
export const signatureAlgorithm: "EdDSA"; | ||
/** @type {'EdDSA'} */ | ||
export const signatureAlgorithm: 'EdDSA'; | ||
export const signatureCode: 53485; | ||
@@ -8,9 +9,8 @@ export const PUB_KEY_OFFSET: number; | ||
export function derive(secret: Uint8Array): Promise<API.EdSigner>; | ||
export function from(archive: API.SignerArchive<API.Signer<"key", typeof signatureCode>>): API.EdSigner; | ||
export function from({ id, keys }: API.SignerArchive<API.DID<'key'>, typeof signatureCode>): API.EdSigner; | ||
export function decode(bytes: Uint8Array): API.EdSigner; | ||
export function encode(signer: API.EdSigner): API.ByteView<API.EdSigner>; | ||
export function encode(signer: API.EdSigner): API.ByteView<API.EdSigner & CryptoKeyPair>; | ||
export function format<Prefix extends string>(signer: API.EdSigner, encoder?: API.MultibaseEncoder<Prefix> | undefined): string; | ||
export function parse<Prefix extends string>(principal: string, decoder?: API.MultibaseDecoder<Prefix> | undefined): API.EdSigner; | ||
export type EdSigner = API.EdSigner; | ||
import * as API from "./type.js"; | ||
//# sourceMappingURL=signer.d.ts.map |
@@ -1,17 +0,51 @@ | ||
import { Signer, Verifier, ByteView, UCAN } from '@ucanto/interface'; | ||
import { SignerKey, VerifierKey, ByteView, DIDKey } from '@ucanto/interface'; | ||
import * as Signature from '@ipld/dag-ucan/signature'; | ||
export * from '@ucanto/interface'; | ||
declare type CODE = typeof Signature.EdDSA; | ||
declare 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>; | ||
/** | ||
* Integer corresponding to EdDSA byteprefix of the VarSig. | ||
*/ | ||
export declare type SigAlg = typeof Signature.EdDSA; | ||
/** | ||
* Name corresponding to EdDSA algorithm. | ||
*/ | ||
export declare type Name = 'EdDSA'; | ||
/** | ||
* This interface parametrizes {@link SignerKey} and extends it with Ed specific | ||
* details. | ||
*/ | ||
export interface EdSigner extends SignerKey<SigAlg> { | ||
readonly signatureAlgorithm: Name; | ||
/** | ||
* Multicodec code that corresponds to Ed private key. | ||
*/ | ||
readonly code: 0x1300; | ||
toArchive(): ByteView<EdSigner<M>>; | ||
readonly signer: EdSigner; | ||
readonly verifier: EdVerifier; | ||
/** | ||
* Encodes keypair into bytes. | ||
*/ | ||
encode(): ByteView<EdSigner & CryptoKeyPair>; | ||
/** | ||
* Overrides method to make it more concrete allowing one to use `keys` | ||
* without checking if it's a `CryptoKey` or bytes. | ||
*/ | ||
toArchive(): { | ||
id: DIDKey; | ||
keys: { | ||
[Key: DIDKey]: ByteView<SignerKey<SigAlg> & CryptoKey>; | ||
}; | ||
}; | ||
} | ||
export interface EdVerifier<M extends string = 'key'> extends Verifier<M, CODE> { | ||
/** | ||
* This interface parametrizes {@link VerifierKey} and extends it with Ed | ||
* specific details. | ||
*/ | ||
export interface EdVerifier extends VerifierKey<SigAlg> { | ||
/** | ||
* Multicodec code that corresponds to Ed public key. | ||
*/ | ||
readonly code: 0xed; | ||
readonly signatureCode: CODE; | ||
readonly signatureAlgorithm: ALG; | ||
readonly signatureCode: SigAlg; | ||
readonly signatureAlgorithm: Name; | ||
} | ||
//# sourceMappingURL=type.d.ts.map |
@@ -5,6 +5,6 @@ export const code: 237; | ||
export const signatureAlgorithm: "EdDSA"; | ||
export function parse(did: API.DID<"key"> | string): API.EdVerifier<"key">; | ||
export function parse(did: API.DID | string): API.EdVerifier; | ||
export function decode(bytes: Uint8Array): API.EdVerifier; | ||
export function format(principal: API.Principal<"key">): `did:key:${string}`; | ||
export function encode(principal: API.Principal<"key">): API.UCAN.PrincipalView<"key">; | ||
export function format(principal: API.Principal<API.DID<"key">>): `did:key:${string}`; | ||
export function encode(principal: API.Principal<API.DID<"key">>): API.UCAN.PrincipalView<"key">; | ||
export type EdVerifier = API.EdVerifier; | ||
@@ -11,0 +11,0 @@ import * as API from "./type.js"; |
@@ -1,15 +0,9 @@ | ||
export const Verifier: { | ||
create: (options: RSA.PrincipalParser[]) => any; | ||
parse: (did: `did:${string}:${string}`) => RSA.UCAN.Verifier<string, number>; | ||
}; | ||
export const Signer: { | ||
create: <Importers extends [RSA.SignerImporter<RSA.Signer<string, number>>, ...RSA.SignerImporter<RSA.Signer<string, number>>[]]>(importers: Importers) => { | ||
create: any; | ||
from: RSA.Intersection<Importers[number]["from"]>; | ||
}; | ||
from: ((archive: RSA.SignerArchive<RSA.Signer<"key", 53485>>) => import("./ed25519/type.js").EdSigner<"key">) & ((archive: RSA.SignerArchive<RSA.Signer<"key", 13636101>>) => RSA.RSASigner<"key">); | ||
}; | ||
export const Verifier: typeof DID; | ||
export const Signer: typeof DID; | ||
import * as DID from "./did.js"; | ||
import * as ed25519 from "./ed25519.js"; | ||
import * as RSA from "./rsa.js"; | ||
import * as ed25519 from "./ed25519.js"; | ||
export { ed25519, RSA }; | ||
import * as Key from "./key.js"; | ||
export { ed25519, RSA, Key, DID }; | ||
export { from, parse } from "./did.js"; | ||
//# sourceMappingURL=lib.d.ts.map |
export function tagWith(code: number, bytes: Uint8Array): Uint8Array; | ||
export function untagWith(code: number, source: Uint8Array, byteOffset?: number): Uint8Array; | ||
export const encodingLength: typeof varint.encodingLength; | ||
export const encodeTo: typeof varint.encodeTo; | ||
export const decode: typeof varint.decode; | ||
import { varint } from "multiformats/dist/types/src"; | ||
//# sourceMappingURL=multiformat.d.ts.map |
@@ -10,10 +10,10 @@ export * from "./rsa/type.js"; | ||
}): Promise<API.RSASigner>; | ||
export function from(archive: API.SignerArchive<API.Signer<'key', typeof signatureCode>>): API.RSASigner; | ||
export function from({ id, keys }: API.SignerArchive<API.DID<'key'>, typeof signatureCode>): API.RSASigner; | ||
export function decode(bytes: EncodedSigner): API.RSASigner; | ||
/** @type {API.PrincipalParser} */ | ||
export const Verifier: API.PrincipalParser; | ||
export type EncodedSigner = API.ByteView<API.Signer<'key', typeof signatureCode>>; | ||
export type EncodedSigner = API.ByteView<API.Signer<API.DID<'key'>, typeof signatureCode> & CryptoKey>; | ||
import * as API from "./rsa/type.js"; | ||
/** | ||
* @typedef {API.ByteView<API.Signer<'key', typeof signatureCode>>} EncodedSigner | ||
* @typedef {API.ByteView<API.Signer<API.DID<'key'>, typeof signatureCode> & CryptoKey>} EncodedSigner | ||
*/ | ||
@@ -31,6 +31,6 @@ declare class RSASigner { | ||
/** @readonly */ | ||
readonly verifier: API.RSAVerifier<"key">; | ||
readonly verifier: API.RSAVerifier; | ||
/** @protected */ | ||
protected privateKey: API.Await<CryptoKey>; | ||
get signer(): API.RSASigner<"key">; | ||
get signer(): RSASigner; | ||
/** | ||
@@ -54,3 +54,3 @@ * @type {typeof code} | ||
*/ | ||
verify<T>(payload: API.ByteView<T>, signature: API.Signature<T, 13636101>): API.UCAN.Await<boolean>; | ||
verify<T>(payload: API.ByteView<T>, signature: API.Signature<T, 13636101>): API.Await<boolean>; | ||
/** | ||
@@ -63,2 +63,3 @@ * @template T | ||
} | ||
import * as DID from "@ipld/dag-ucan/did"; | ||
/** | ||
@@ -74,6 +75,6 @@ * @implements {API.RSAVerifier} | ||
/** | ||
* @param {API.DID} did | ||
* @param {API.DID<"key">} did | ||
* @returns {API.RSAVerifier} | ||
*/ | ||
static parse(did: API.DID): API.RSAVerifier; | ||
static parse(did: API.DID<"key">): API.RSAVerifier; | ||
/** | ||
@@ -92,2 +93,8 @@ * @param {object} options | ||
private bytes; | ||
/** | ||
* @template {API.DID} ID | ||
* @param {ID} id | ||
* @returns {API.Verifier<ID, typeof signatureCode>} | ||
*/ | ||
withDID<ID extends `did:${string}:${string}`>(id: ID): API.Verifier<ID, 13636101>; | ||
/** @type {typeof verifierCode} */ | ||
@@ -116,3 +123,2 @@ get code(): 4613; | ||
} | ||
import * as DID from "@ipld/dag-ucan/did"; | ||
//# sourceMappingURL=rsa.d.ts.map |
@@ -1,15 +0,35 @@ | ||
import { Signer, Verifier, UCAN } from '@ucanto/interface'; | ||
import { VerifierKey, SignerKey } from '@ucanto/interface'; | ||
export * from '@ucanto/interface'; | ||
declare type CODE = 0xd01205; | ||
declare type ALG = 'RS256'; | ||
export interface RSASigner<M extends string = 'key'> extends Signer<M, CODE>, UCAN.Verifier<M, CODE> { | ||
readonly signer: RSASigner<M>; | ||
readonly verifier: RSAVerifier<M>; | ||
/** | ||
* Integer corresponding to RS256 byteprefix of the VarSig. | ||
*/ | ||
export declare type SigAlg = 0xd01205; | ||
/** | ||
* Name corresponding to RS256 algorithm. | ||
*/ | ||
export declare type Name = 'RS256'; | ||
/** | ||
* This interface parametrizes {@link SignerKey} and extends it with RSA specific | ||
* details. | ||
*/ | ||
export interface RSASigner extends SignerKey<SigAlg> { | ||
readonly signer: RSASigner; | ||
readonly verifier: RSAVerifier; | ||
/** | ||
* Multicodec code that corresponds to Ed private key. | ||
*/ | ||
readonly code: 0x1305; | ||
} | ||
export interface RSAVerifier<M extends string = 'key'> extends Verifier<M, CODE> { | ||
/** | ||
* This interface parametrizes {@link VerifierKey} and extends it with Ed | ||
* specific details. | ||
*/ | ||
export interface RSAVerifier extends VerifierKey<SigAlg> { | ||
/** | ||
* Multicodec code that corresponds to RSA public key. | ||
*/ | ||
readonly code: 0x1205; | ||
readonly signatureCode: CODE; | ||
readonly signatureAlgorithm: ALG; | ||
readonly signatureCode: SigAlg; | ||
readonly signatureAlgorithm: Name; | ||
} | ||
//# sourceMappingURL=type.d.ts.map |
@@ -1,6 +0,52 @@ | ||
export function create<Importers extends [API.SignerImporter<API.Signer<string, number>>, ...API.SignerImporter<API.Signer<string, number>>[]]>(importers: Importers): { | ||
create: <Importers extends [API.SignerImporter<API.Signer<string, number>>, ...API.SignerImporter<API.Signer<string, number>>[]]>(importers: Importers) => any; | ||
export function create<Importers extends [API.SignerImporter<`did:${string}:${string}`, number>, ...API.SignerImporter<`did:${string}:${string}`, number>[]]>(importers: Importers): { | ||
create: <Importers extends [API.SignerImporter<`did:${string}:${string}`, number>, ...API.SignerImporter<`did:${string}:${string}`, number>[]]>(importers: Importers) => any; | ||
from: API.Intersection<Importers[number]["from"]>; | ||
}; | ||
export function withDID<Code extends number, ID extends `did:${string}:${string}`>({ signer, verifier }: API.Signer<`did:key:${string}`, Code>, id: ID): API.Signer<ID, Code>; | ||
import * as API from "@ucanto/interface"; | ||
/** | ||
* @template {API.DID} ID | ||
* @template {number} Code | ||
* @implements {API.Signer<ID, Code>} | ||
*/ | ||
declare class Signer<ID extends `did:${string}:${string}`, Code extends number> implements API.Signer<ID, Code> { | ||
/** | ||
* @param {API.Signer<API.DID<'key'>, Code>} key | ||
* @param {API.Verifier<ID, Code>} verifier | ||
*/ | ||
constructor(key: API.Signer<API.DID<'key'>, Code>, verifier: API.Verifier<ID, Code>); | ||
key: API.Signer<`did:key:${string}`, Code>; | ||
verifier: API.Verifier<ID, Code>; | ||
/** @type {API.Signer<ID, Code>} */ | ||
get signer(): API.Signer<ID, Code>; | ||
get signatureAlgorithm(): string; | ||
get signatureCode(): Code; | ||
/** | ||
* @returns {ID} | ||
*/ | ||
did(): ID; | ||
/** | ||
* @template {API.DID} ID | ||
* @param {ID} id | ||
*/ | ||
withDID<ID_1 extends `did:${string}:${string}`>(id: ID_1): API.Signer<ID_1, Code>; | ||
/** | ||
* @template T | ||
* @param {API.ByteView<T>} payload | ||
*/ | ||
sign<T>(payload: API.ByteView<T>): API.Await<API.Signature<T, Code>>; | ||
/** | ||
* @template T | ||
* @param {API.ByteView<T>} payload | ||
* @param {API.Signature<T, Code>} signature | ||
*/ | ||
verify<T_1>(payload: API.ByteView<T_1>, signature: API.Signature<T_1, Code>): API.Await<boolean>; | ||
toArchive(): { | ||
id: ID; | ||
keys: { | ||
[Key: `did:key:${string}`]: API.KeyArchive<Code>; | ||
}; | ||
}; | ||
} | ||
export {}; | ||
//# sourceMappingURL=signer.d.ts.map |
@@ -9,3 +9,32 @@ export function create(options: API.PrincipalParser[]): { | ||
}; | ||
export function withDID<ID extends `did:${string}:${string}`, Code extends number>(key: API.Verifier<`did:key:${string}`, Code>, id: ID): API.Verifier<ID, Code>; | ||
import * as API from "@ucanto/interface"; | ||
/** | ||
* @template {API.DID} ID | ||
* @template {number} Code | ||
* @implements {API.Verifier<ID, Code>} | ||
*/ | ||
declare class Verifier<ID extends `did:${string}:${string}`, Code extends number> implements API.Verifier<ID, Code> { | ||
/** | ||
* @param {ID} id | ||
* @param {API.Verifier<API.DID<"key">, Code>} key | ||
*/ | ||
constructor(id: ID, key: API.Verifier<API.DID<"key">, Code>); | ||
id: ID; | ||
key: API.Verifier<`did:key:${string}`, Code>; | ||
did(): ID; | ||
/** | ||
* @template T | ||
* @param {API.ByteView<T>} payload | ||
* @param {API.Signature<T, Code>} signature | ||
* @returns {API.Await<boolean>} | ||
*/ | ||
verify<T>(payload: API.ByteView<T>, signature: API.Signature<T, Code>): API.Await<boolean>; | ||
/** | ||
* @template {API.DID} ID | ||
* @param {ID} id | ||
*/ | ||
withDID<ID_1 extends `did:${string}:${string}`>(id: ID_1): API.Verifier<ID_1, Code>; | ||
} | ||
export {}; | ||
//# sourceMappingURL=verifier.d.ts.map |
{ | ||
"name": "@ucanto/principal", | ||
"description": "ed25519 principal", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"keywords": [ | ||
@@ -24,3 +24,3 @@ "UCAN", | ||
"@noble/ed25519": "^1.7.1", | ||
"@ucanto/interface": "^3.0.1", | ||
"@ucanto/interface": "^4.0.0", | ||
"multiformats": "^10.0.2", | ||
@@ -27,0 +27,0 @@ "one-webcrypto": "^1.0.3" |
@@ -7,5 +7,8 @@ import * as ED25519 from '@noble/ed25519' | ||
import * as Signature from '@ipld/dag-ucan/signature' | ||
import { withDID } from '../signer.js' | ||
export const code = 0x1300 | ||
export const name = Verifier.name | ||
/** @type {'EdDSA'} */ | ||
export const signatureAlgorithm = Verifier.signatureAlgorithm | ||
@@ -22,6 +25,2 @@ export const signatureCode = Verifier.signatureCode | ||
/** | ||
* @typedef {API.EdSigner } EdSigner | ||
*/ | ||
/** | ||
* Generates new issuer by generating underlying ED25519 keypair. | ||
@@ -57,8 +56,9 @@ * @returns {Promise<API.EdSigner>} | ||
/** | ||
* @param {API.SignerArchive<API.Signer<"key", typeof signatureCode>>} archive | ||
* @param {API.SignerArchive<API.DID<'key'>, typeof signatureCode>} archive | ||
* @returns {API.EdSigner} | ||
*/ | ||
export const from = archive => { | ||
if (archive instanceof Uint8Array) { | ||
return decode(archive) | ||
export const from = ({ id, keys }) => { | ||
const key = keys[id] | ||
if (key instanceof Uint8Array) { | ||
return decode(key) | ||
} else { | ||
@@ -101,5 +101,5 @@ throw new Error(`Unsupported archive format`) | ||
* @param {API.EdSigner} signer | ||
* @return {API.ByteView<API.EdSigner>} | ||
* @return {API.ByteView<API.EdSigner & CryptoKeyPair>} | ||
*/ | ||
export const encode = signer => signer.toArchive() | ||
export const encode = signer => signer.encode() | ||
@@ -170,2 +170,11 @@ /** | ||
/** | ||
* @template {API.DID} ID | ||
* @param {ID} id | ||
* @returns {API.Signer<ID, typeof Signature.EdDSA>} | ||
*/ | ||
withDID(id) { | ||
return withDID(this, id) | ||
} | ||
/** | ||
* @template T | ||
@@ -191,3 +200,3 @@ * @param {API.ByteView<T>} payload | ||
get signatureAlgorithm() { | ||
return 'EdDSA' | ||
return signatureAlgorithm | ||
} | ||
@@ -198,5 +207,13 @@ get signatureCode() { | ||
toArchive() { | ||
encode() { | ||
return this | ||
} | ||
toArchive() { | ||
const id = this.did() | ||
return { | ||
id, | ||
keys: { [id]: this.encode() }, | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Signer, Verifier, ByteView, UCAN, Await } from '@ucanto/interface' | ||
import { SignerKey, VerifierKey, ByteView, DIDKey } from '@ucanto/interface' | ||
import * as Signature from '@ipld/dag-ucan/signature' | ||
@@ -6,20 +6,52 @@ | ||
type CODE = typeof Signature.EdDSA | ||
type ALG = 'EdDSA' | ||
/** | ||
* Integer corresponding to EdDSA byteprefix of the VarSig. | ||
*/ | ||
export type SigAlg = typeof Signature.EdDSA | ||
export interface EdSigner<M extends string = 'key'> | ||
extends Signer<M, CODE>, | ||
UCAN.Verifier<M, CODE> { | ||
readonly signer: EdSigner<M> | ||
readonly verifier: EdVerifier<M> | ||
/** | ||
* Name corresponding to EdDSA algorithm. | ||
*/ | ||
export type Name = 'EdDSA' | ||
/** | ||
* This interface parametrizes {@link SignerKey} and extends it with Ed specific | ||
* details. | ||
*/ | ||
export interface EdSigner extends SignerKey<SigAlg> { | ||
readonly signatureAlgorithm: Name | ||
/** | ||
* Multicodec code that corresponds to Ed private key. | ||
*/ | ||
readonly code: 0x1300 | ||
toArchive(): ByteView<EdSigner<M>> | ||
readonly signer: EdSigner | ||
readonly verifier: EdVerifier | ||
/** | ||
* Encodes keypair into bytes. | ||
*/ | ||
encode(): ByteView<EdSigner & CryptoKeyPair> | ||
/** | ||
* Overrides method to make it more concrete allowing one to use `keys` | ||
* without checking if it's a `CryptoKey` or bytes. | ||
*/ | ||
toArchive(): { | ||
id: DIDKey | ||
keys: { [Key: DIDKey]: ByteView<SignerKey<SigAlg> & CryptoKey> } | ||
} | ||
} | ||
export interface EdVerifier<M extends string = 'key'> | ||
extends Verifier<M, CODE> { | ||
/** | ||
* This interface parametrizes {@link VerifierKey} and extends it with Ed | ||
* specific details. | ||
*/ | ||
export interface EdVerifier extends VerifierKey<SigAlg> { | ||
/** | ||
* Multicodec code that corresponds to Ed public key. | ||
*/ | ||
readonly code: 0xed | ||
readonly signatureCode: CODE | ||
readonly signatureAlgorithm: ALG | ||
readonly signatureCode: SigAlg | ||
readonly signatureAlgorithm: Name | ||
} |
@@ -7,2 +7,4 @@ import * as DID from '@ipld/dag-ucan/did' | ||
import { base58btc } from 'multiformats/bases/base58' | ||
import { withDID } from '../verifier.js' | ||
export const code = 0xed | ||
@@ -23,3 +25,3 @@ export const name = 'Ed25519' | ||
* | ||
* @param {API.DID<"key">|string} did | ||
* @param {API.DID|string} did | ||
*/ | ||
@@ -53,3 +55,3 @@ export const parse = did => decode(DID.parse(did)) | ||
* | ||
* @param {API.Principal<"key">} principal | ||
* @param {API.Principal<API.DID<"key">>} principal | ||
*/ | ||
@@ -62,3 +64,3 @@ export const format = principal => DID.format(principal) | ||
* | ||
* @param {API.Principal<"key">} principal | ||
* @param {API.Principal<API.DID<"key">>} principal | ||
*/ | ||
@@ -116,2 +118,11 @@ export const encode = principal => DID.encode(principal) | ||
} | ||
/** | ||
* @template {API.DID} ID | ||
* @param {ID} id | ||
* @returns {API.Verifier<ID, typeof signatureCode>} | ||
*/ | ||
withDID(id) { | ||
return withDID(this, id) | ||
} | ||
} |
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' | ||
import * as DID from './did.js' | ||
import * as Key from './key.js' | ||
export { from, parse } from './did.js' | ||
export const Verifier = createVerifier([ed25519.Verifier, RSA.Verifier]) | ||
export const Signer = createSigner([ed25519, RSA]) | ||
export const Verifier = DID | ||
export const Signer = DID | ||
export { ed25519, RSA } | ||
export { ed25519, RSA, Key, DID } |
@@ -36,1 +36,5 @@ import { varint } from 'multiformats' | ||
} | ||
export const encodingLength = varint.encodingLength | ||
export const encodeTo = varint.encodeTo | ||
export const decode = varint.decode |
@@ -11,2 +11,4 @@ import { webcrypto } from 'one-webcrypto' | ||
import * as PublicKey from './rsa/public-key.js' | ||
import { withDID as setVerifierDID } from './verifier.js' | ||
import { withDID } from './signer.js' | ||
export * from './rsa/type.js' | ||
@@ -91,12 +93,13 @@ | ||
/** | ||
* @param {API.SignerArchive<API.Signer<'key', typeof signatureCode>>} archive | ||
* @param {API.SignerArchive<API.DID<'key'>, typeof signatureCode>} archive | ||
* @returns {API.RSASigner} | ||
*/ | ||
export const from = archive => { | ||
if (archive instanceof Uint8Array) { | ||
return decode(archive) | ||
export const from = ({ id, keys }) => { | ||
const key = keys[id] | ||
if (key instanceof Uint8Array) { | ||
return decode(key) | ||
} else { | ||
return new UnextractableRSASigner({ | ||
privateKey: archive.key, | ||
verifier: RSAVerifier.parse(archive.did), | ||
privateKey: key, | ||
verifier: RSAVerifier.parse(id), | ||
}) | ||
@@ -147,2 +150,11 @@ } | ||
/** | ||
* @template {API.DID} ID | ||
* @param {ID} id | ||
* @returns {API.Verifier<ID, typeof signatureCode>} | ||
*/ | ||
withDID(id) { | ||
return setVerifierDID(this, id) | ||
} | ||
/** | ||
* @param {API.ByteView<API.RSAVerifier>} bytes | ||
@@ -164,3 +176,3 @@ * @returns {API.RSAVerifier} | ||
/** | ||
* @param {API.DID} did | ||
* @param {API.DID<"key">} did | ||
* @returns {API.RSAVerifier} | ||
@@ -222,3 +234,3 @@ */ | ||
/** | ||
* @typedef {API.ByteView<API.Signer<'key', typeof signatureCode>>} EncodedSigner | ||
* @typedef {API.ByteView<API.Signer<API.DID<'key'>, typeof signatureCode> & CryptoKey>} EncodedSigner | ||
*/ | ||
@@ -239,5 +251,5 @@ | ||
get signer() { | ||
// @ts-expect-error - we define export methods on subclasses | ||
return /** @type {API.RSASigner} */ (this) | ||
return this | ||
} | ||
/** | ||
@@ -303,4 +315,18 @@ * @type {typeof code} | ||
} | ||
/** | ||
* @template {API.DID} ID | ||
* @param {ID} id | ||
* @returns {API.Signer<ID, typeof signatureCode>} | ||
*/ | ||
withDID(id) { | ||
return withDID(this, id) | ||
} | ||
toArchive() { | ||
return this.bytes | ||
const id = this.did() | ||
return { | ||
id, | ||
keys: { [id]: this.bytes }, | ||
} | ||
} | ||
@@ -322,8 +348,19 @@ } | ||
} | ||
/** | ||
* @template {API.DID} ID | ||
* @param {ID} id | ||
* @returns {API.Signer<ID, typeof signatureCode>} | ||
*/ | ||
withDID(id) { | ||
return withDID(this, id) | ||
} | ||
toArchive() { | ||
const id = this.did() | ||
return { | ||
did: this.did(), | ||
key: this.privateKey, | ||
id, | ||
keys: { [id]: this.privateKey }, | ||
} | ||
} | ||
} |
@@ -1,22 +0,40 @@ | ||
import { Signer, Verifier, ByteView, UCAN, Await } from '@ucanto/interface' | ||
import { VerifierKey, SignerKey } from '@ucanto/interface' | ||
export * from '@ucanto/interface' | ||
type CODE = 0xd01205 | ||
type ALG = 'RS256' | ||
/** | ||
* Integer corresponding to RS256 byteprefix of the VarSig. | ||
*/ | ||
export type SigAlg = 0xd01205 | ||
export interface RSASigner<M extends string = 'key'> | ||
extends Signer<M, CODE>, | ||
UCAN.Verifier<M, CODE> { | ||
readonly signer: RSASigner<M> | ||
readonly verifier: RSAVerifier<M> | ||
/** | ||
* Name corresponding to RS256 algorithm. | ||
*/ | ||
export type Name = 'RS256' | ||
/** | ||
* This interface parametrizes {@link SignerKey} and extends it with RSA specific | ||
* details. | ||
*/ | ||
export interface RSASigner extends SignerKey<SigAlg> { | ||
readonly signer: RSASigner | ||
readonly verifier: RSAVerifier | ||
/** | ||
* Multicodec code that corresponds to Ed private key. | ||
*/ | ||
readonly code: 0x1305 | ||
} | ||
export interface RSAVerifier<M extends string = 'key'> | ||
extends Verifier<M, CODE> { | ||
/** | ||
* This interface parametrizes {@link VerifierKey} and extends it with Ed | ||
* specific details. | ||
*/ | ||
export interface RSAVerifier extends VerifierKey<SigAlg> { | ||
/** | ||
* Multicodec code that corresponds to RSA public key. | ||
*/ | ||
readonly code: 0x1205 | ||
readonly signatureCode: CODE | ||
readonly signatureAlgorithm: ALG | ||
readonly signatureCode: SigAlg | ||
readonly signatureAlgorithm: Name | ||
} |
@@ -25,1 +25,77 @@ import * as API from '@ucanto/interface' | ||
} | ||
/** | ||
* @template {number} Code | ||
* @template {API.DID} ID | ||
* @param {API.Signer<API.DID<'key'>, Code>} signer | ||
* @param {ID} id | ||
* @returns {API.Signer<ID, Code>} | ||
*/ | ||
export const withDID = ({ signer, verifier }, id) => | ||
new Signer(signer, verifier.withDID(id)) | ||
/** | ||
* @template {API.DID} ID | ||
* @template {number} Code | ||
* @implements {API.Signer<ID, Code>} | ||
*/ | ||
class Signer { | ||
/** | ||
* @param {API.Signer<API.DID<'key'>, Code>} key | ||
* @param {API.Verifier<ID, Code>} verifier | ||
*/ | ||
constructor(key, verifier) { | ||
this.key = key | ||
this.verifier = verifier | ||
} | ||
/** @type {API.Signer<ID, Code>} */ | ||
get signer() { | ||
return this | ||
} | ||
get signatureAlgorithm() { | ||
return this.key.signatureAlgorithm | ||
} | ||
get signatureCode() { | ||
return this.key.signatureCode | ||
} | ||
/** | ||
* @returns {ID} | ||
*/ | ||
did() { | ||
return this.verifier.did() | ||
} | ||
/** | ||
* @template {API.DID} ID | ||
* @param {ID} id | ||
*/ | ||
withDID(id) { | ||
return withDID(this.key, id) | ||
} | ||
/** | ||
* @template T | ||
* @param {API.ByteView<T>} payload | ||
*/ | ||
sign(payload) { | ||
return this.key.sign(payload) | ||
} | ||
/** | ||
* @template T | ||
* @param {API.ByteView<T>} payload | ||
* @param {API.Signature<T, Code>} signature | ||
*/ | ||
verify(payload, signature) { | ||
return this.verifier.verify(payload, signature) | ||
} | ||
toArchive() { | ||
const { keys } = this.key.toArchive() | ||
return { | ||
id: this.did(), | ||
keys, | ||
} | ||
} | ||
} |
@@ -18,4 +18,50 @@ import * as API from '@ucanto/interface' | ||
} | ||
throw new Error(`Unsupported principal with DID ${did}`) | ||
throw new Error(`Unsupported did ${did}`) | ||
}, | ||
}) | ||
/** | ||
* @template {API.DID} ID | ||
* @template {number} Code | ||
* @param {API.Verifier<API.DID<"key">, Code>} key | ||
* @param {ID} id | ||
* @returns {API.Verifier<ID, Code>} | ||
*/ | ||
export const withDID = (key, id) => new Verifier(id, key) | ||
/** | ||
* @template {API.DID} ID | ||
* @template {number} Code | ||
* @implements {API.Verifier<ID, Code>} | ||
*/ | ||
class Verifier { | ||
/** | ||
* @param {ID} id | ||
* @param {API.Verifier<API.DID<"key">, Code>} key | ||
*/ | ||
constructor(id, key) { | ||
this.id = id | ||
this.key = key | ||
} | ||
did() { | ||
return this.id | ||
} | ||
/** | ||
* @template T | ||
* @param {API.ByteView<T>} payload | ||
* @param {API.Signature<T, Code>} signature | ||
* @returns {API.Await<boolean>} | ||
*/ | ||
verify(payload, signature) { | ||
return this.key.verify(payload, signature) | ||
} | ||
/** | ||
* @template {API.DID} ID | ||
* @param {ID} id | ||
*/ | ||
withDID(id) { | ||
return withDID(this.key, id) | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75247
54
2156
+ Added@ipld/dag-cbor@9.2.2(transitive)
+ Added@ipld/dag-json@10.2.3(transitive)
+ Added@ipld/dag-ucan@3.4.0(transitive)
+ Added@ucanto/interface@4.4.1(transitive)
+ Addedcborg@4.2.6(transitive)
+ Addedmultiformats@13.3.1(transitive)
- Removed@ucanto/interface@3.0.1(transitive)
Updated@ucanto/interface@^4.0.0