Skip to content

Commit

Permalink
Merge pull request #244 from ArweaveTeam/2.0alpha-release
Browse files Browse the repository at this point in the history
2.0alpha release
  • Loading branch information
rosmcmahon authored Jan 22, 2025
2 parents 5eb56ae + 854d0cb commit 8ed093a
Show file tree
Hide file tree
Showing 16 changed files with 963 additions and 611 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tag=ec
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arweave",
"version": "1.15.5",
"version": "2.0.0-ec.0",
"description": "Arweave JS client library",
"main": "./node/index.js",
"react-native": "./node/index.js",
Expand Down
12 changes: 6 additions & 6 deletions src/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ export default class Arweave {

if (attributes.owner == undefined && keyData && keyData !== "use_wallet") {
let pk: PublicKey;
if (keyData instanceof PrivateKey){
pk = await keyData.public()
if (keyData instanceof PrivateKey) {
pk = await keyData.public();
} else if (keyData instanceof PublicKey) {
pk = keyData;
} else {
pk = await fromJWK(keyData as JsonWebKey)
.then(sk => sk.public());
pk = await fromJWK(keyData as JsonWebKey).then((sk) => sk.public());
}
transaction.owner = await pk.identifier()
.then(id => ArweaveUtils.bufferTob64Url(id));
transaction.owner = await pk
.identifier()
.then((id) => ArweaveUtils.bufferTob64Url(id));
if (pk.type === KeyType.EC_SECP256K1) {
transaction.owner = "";
}
Expand Down
143 changes: 77 additions & 66 deletions src/common/lib/crypto/keys/interface.ts
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}`);
}
};
Loading

0 comments on commit 8ed093a

Please sign in to comment.