-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from ArweaveTeam/2.0alpha-release
2.0alpha release
- Loading branch information
Showing
16 changed files
with
963 additions
and
611 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
tag=ec |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,104 @@ | ||
export enum KeyType { | ||
RSA_65537 = "rsa_65537", | ||
EC_SECP256K1 = "ec_secp256k1", | ||
}; | ||
RSA_65537 = "rsa_65537", | ||
EC_SECP256K1 = "ec_secp256k1", | ||
} | ||
|
||
export type Format = "jwk" | "raw"; | ||
|
||
export interface SerializationParams<T extends Format = Format> { | ||
format: T; | ||
format: T; | ||
} | ||
|
||
export interface SigningParams { | ||
payload: Uint8Array; | ||
isDigest?: boolean; | ||
payload: Uint8Array; | ||
isDigest?: boolean; | ||
} | ||
|
||
export interface VerifyingParams { | ||
payload: Uint8Array; | ||
signature: Uint8Array; | ||
isDigest?: boolean; | ||
payload: Uint8Array; | ||
signature: Uint8Array; | ||
isDigest?: boolean; | ||
} | ||
|
||
export interface EncryptionParams { | ||
secret: Uint8Array; | ||
|
||
secret: Uint8Array; | ||
} | ||
|
||
export interface DecryptionParams { | ||
payload: Uint8Array; | ||
payload: Uint8Array; | ||
} | ||
|
||
export abstract class PrivateKey { | ||
public readonly type: KeyType; | ||
public readonly type: KeyType; | ||
|
||
constructor({type}: {type: KeyType}) { | ||
this.type = type; | ||
} | ||
static async new(_: any): Promise<PrivateKey> { | ||
throw new Error(`PrivateKey does not implement instantiation interface.`); | ||
} | ||
static async deserialize(_: any): Promise<PrivateKey> { | ||
throw new Error(`PrivateKey does not implement deserialization interface.`); | ||
} | ||
abstract serialize(params: SerializationParams): Promise<JsonWebKey | Uint8Array>; | ||
abstract sign(params: SigningParams): Promise<Uint8Array>; | ||
abstract public(): Promise<PublicKey>; | ||
public async decrypt(_: DecryptionParams): Promise<Uint8Array> { | ||
throw new Error(`PrivateKey ${this.type} does not provide decription interface.`); | ||
} | ||
constructor({ type }: { type: KeyType }) { | ||
this.type = type; | ||
} | ||
static async new(_: any): Promise<PrivateKey> { | ||
throw new Error(`PrivateKey does not implement instantiation interface.`); | ||
} | ||
static async deserialize(_: any): Promise<PrivateKey> { | ||
throw new Error(`PrivateKey does not implement deserialization interface.`); | ||
} | ||
abstract serialize( | ||
params: SerializationParams | ||
): Promise<JsonWebKey | Uint8Array>; | ||
abstract sign(params: SigningParams): Promise<Uint8Array>; | ||
abstract public(): Promise<PublicKey>; | ||
public async decrypt(_: DecryptionParams): Promise<Uint8Array> { | ||
throw new Error( | ||
`PrivateKey ${this.type} does not provide decription interface.` | ||
); | ||
} | ||
} | ||
|
||
export abstract class PublicKey { | ||
public readonly type: KeyType; | ||
constructor({type}: {type: KeyType}) { | ||
this.type = type; | ||
} | ||
static async deserialize(_: any): Promise<PublicKey> { | ||
throw new Error(`PublicKey does not implement deserialization interface.`); | ||
} | ||
abstract serialize(params: SerializationParams): Promise<JsonWebKey | Uint8Array>; | ||
abstract verify(params: VerifyingParams): Promise<boolean>; | ||
abstract identifier(): Promise<Uint8Array>; | ||
public async encrypt(_: EncryptionParams): Promise<Uint8Array> { | ||
throw new Error(`PrivateKey ${this.type} does not provide encyrption interface.`); | ||
} | ||
public readonly type: KeyType; | ||
constructor({ type }: { type: KeyType }) { | ||
this.type = type; | ||
} | ||
static async deserialize(_: any): Promise<PublicKey> { | ||
throw new Error(`PublicKey does not implement deserialization interface.`); | ||
} | ||
abstract serialize( | ||
params: SerializationParams | ||
): Promise<JsonWebKey | Uint8Array>; | ||
abstract verify(params: VerifyingParams): Promise<boolean>; | ||
abstract identifier(): Promise<Uint8Array>; | ||
public async encrypt(_: EncryptionParams): Promise<Uint8Array> { | ||
throw new Error( | ||
`PrivateKey ${this.type} does not provide encyrption interface.` | ||
); | ||
} | ||
} | ||
|
||
export const getInitializationOptions = (type: KeyType): AlgorithmIdentifier | RsaHashedKeyGenParams | EcKeyGenParams => { | ||
switch(type) { | ||
case KeyType.RSA_65537: | ||
return { | ||
name: "RSA-PSS", | ||
publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | ||
hash: { | ||
name: "SHA-256" | ||
} | ||
}; | ||
default: | ||
throw new Error(`Unsupported RSA KeyType ${type}`); | ||
} | ||
} | ||
export const getInitializationOptions = ( | ||
type: KeyType | ||
): AlgorithmIdentifier | RsaHashedKeyGenParams | EcKeyGenParams => { | ||
switch (type) { | ||
case KeyType.RSA_65537: | ||
return { | ||
name: "RSA-PSS", | ||
publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | ||
hash: { | ||
name: "SHA-256", | ||
}, | ||
}; | ||
default: | ||
throw new Error(`Unsupported RSA KeyType ${type}`); | ||
} | ||
}; | ||
|
||
export const getSigningParameters = (type: KeyType): AlgorithmIdentifier | RsaPssParams | EcdsaParams => { | ||
switch(type) { | ||
case KeyType.RSA_65537: | ||
return { | ||
name: "RSA-PSS", | ||
saltLength: 32, | ||
}; | ||
default: | ||
throw new Error(`Unsupported RSA KeyType ${type}`); | ||
} | ||
} | ||
export const getSigningParameters = ( | ||
type: KeyType | ||
): AlgorithmIdentifier | RsaPssParams | EcdsaParams => { | ||
switch (type) { | ||
case KeyType.RSA_65537: | ||
return { | ||
name: "RSA-PSS", | ||
saltLength: 32, | ||
}; | ||
default: | ||
throw new Error(`Unsupported RSA KeyType ${type}`); | ||
} | ||
}; |
Oops, something went wrong.