Skip to content

Commit 8ed093a

Browse files
authored
Merge pull request #244 from ArweaveTeam/2.0alpha-release
2.0alpha release
2 parents 5eb56ae + 854d0cb commit 8ed093a

File tree

16 files changed

+963
-611
lines changed

16 files changed

+963
-611
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tag=ec

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "arweave",
3-
"version": "1.15.5",
3+
"version": "2.0.0-ec.0",
44
"description": "Arweave JS client library",
55
"main": "./node/index.js",
66
"react-native": "./node/index.js",

src/common/common.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,16 @@ export default class Arweave {
9898

9999
if (attributes.owner == undefined && keyData && keyData !== "use_wallet") {
100100
let pk: PublicKey;
101-
if (keyData instanceof PrivateKey){
102-
pk = await keyData.public()
101+
if (keyData instanceof PrivateKey) {
102+
pk = await keyData.public();
103103
} else if (keyData instanceof PublicKey) {
104104
pk = keyData;
105105
} else {
106-
pk = await fromJWK(keyData as JsonWebKey)
107-
.then(sk => sk.public());
106+
pk = await fromJWK(keyData as JsonWebKey).then((sk) => sk.public());
108107
}
109-
transaction.owner = await pk.identifier()
110-
.then(id => ArweaveUtils.bufferTob64Url(id));
108+
transaction.owner = await pk
109+
.identifier()
110+
.then((id) => ArweaveUtils.bufferTob64Url(id));
111111
if (pk.type === KeyType.EC_SECP256K1) {
112112
transaction.owner = "";
113113
}
Lines changed: 77 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,104 @@
11
export enum KeyType {
2-
RSA_65537 = "rsa_65537",
3-
EC_SECP256K1 = "ec_secp256k1",
4-
};
2+
RSA_65537 = "rsa_65537",
3+
EC_SECP256K1 = "ec_secp256k1",
4+
}
55

66
export type Format = "jwk" | "raw";
77

88
export interface SerializationParams<T extends Format = Format> {
9-
format: T;
9+
format: T;
1010
}
1111

1212
export interface SigningParams {
13-
payload: Uint8Array;
14-
isDigest?: boolean;
13+
payload: Uint8Array;
14+
isDigest?: boolean;
1515
}
1616

1717
export interface VerifyingParams {
18-
payload: Uint8Array;
19-
signature: Uint8Array;
20-
isDigest?: boolean;
18+
payload: Uint8Array;
19+
signature: Uint8Array;
20+
isDigest?: boolean;
2121
}
2222

2323
export interface EncryptionParams {
24-
secret: Uint8Array;
25-
24+
secret: Uint8Array;
2625
}
2726

2827
export interface DecryptionParams {
29-
payload: Uint8Array;
28+
payload: Uint8Array;
3029
}
3130

3231
export abstract class PrivateKey {
33-
public readonly type: KeyType;
32+
public readonly type: KeyType;
3433

35-
constructor({type}: {type: KeyType}) {
36-
this.type = type;
37-
}
38-
static async new(_: any): Promise<PrivateKey> {
39-
throw new Error(`PrivateKey does not implement instantiation interface.`);
40-
}
41-
static async deserialize(_: any): Promise<PrivateKey> {
42-
throw new Error(`PrivateKey does not implement deserialization interface.`);
43-
}
44-
abstract serialize(params: SerializationParams): Promise<JsonWebKey | Uint8Array>;
45-
abstract sign(params: SigningParams): Promise<Uint8Array>;
46-
abstract public(): Promise<PublicKey>;
47-
public async decrypt(_: DecryptionParams): Promise<Uint8Array> {
48-
throw new Error(`PrivateKey ${this.type} does not provide decription interface.`);
49-
}
34+
constructor({ type }: { type: KeyType }) {
35+
this.type = type;
36+
}
37+
static async new(_: any): Promise<PrivateKey> {
38+
throw new Error(`PrivateKey does not implement instantiation interface.`);
39+
}
40+
static async deserialize(_: any): Promise<PrivateKey> {
41+
throw new Error(`PrivateKey does not implement deserialization interface.`);
42+
}
43+
abstract serialize(
44+
params: SerializationParams
45+
): Promise<JsonWebKey | Uint8Array>;
46+
abstract sign(params: SigningParams): Promise<Uint8Array>;
47+
abstract public(): Promise<PublicKey>;
48+
public async decrypt(_: DecryptionParams): Promise<Uint8Array> {
49+
throw new Error(
50+
`PrivateKey ${this.type} does not provide decription interface.`
51+
);
52+
}
5053
}
5154

5255
export abstract class PublicKey {
53-
public readonly type: KeyType;
54-
constructor({type}: {type: KeyType}) {
55-
this.type = type;
56-
}
57-
static async deserialize(_: any): Promise<PublicKey> {
58-
throw new Error(`PublicKey does not implement deserialization interface.`);
59-
}
60-
abstract serialize(params: SerializationParams): Promise<JsonWebKey | Uint8Array>;
61-
abstract verify(params: VerifyingParams): Promise<boolean>;
62-
abstract identifier(): Promise<Uint8Array>;
63-
public async encrypt(_: EncryptionParams): Promise<Uint8Array> {
64-
throw new Error(`PrivateKey ${this.type} does not provide encyrption interface.`);
65-
}
56+
public readonly type: KeyType;
57+
constructor({ type }: { type: KeyType }) {
58+
this.type = type;
59+
}
60+
static async deserialize(_: any): Promise<PublicKey> {
61+
throw new Error(`PublicKey does not implement deserialization interface.`);
62+
}
63+
abstract serialize(
64+
params: SerializationParams
65+
): Promise<JsonWebKey | Uint8Array>;
66+
abstract verify(params: VerifyingParams): Promise<boolean>;
67+
abstract identifier(): Promise<Uint8Array>;
68+
public async encrypt(_: EncryptionParams): Promise<Uint8Array> {
69+
throw new Error(
70+
`PrivateKey ${this.type} does not provide encyrption interface.`
71+
);
72+
}
6673
}
6774

68-
export const getInitializationOptions = (type: KeyType): AlgorithmIdentifier | RsaHashedKeyGenParams | EcKeyGenParams => {
69-
switch(type) {
70-
case KeyType.RSA_65537:
71-
return {
72-
name: "RSA-PSS",
73-
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
74-
hash: {
75-
name: "SHA-256"
76-
}
77-
};
78-
default:
79-
throw new Error(`Unsupported RSA KeyType ${type}`);
80-
}
81-
}
75+
export const getInitializationOptions = (
76+
type: KeyType
77+
): AlgorithmIdentifier | RsaHashedKeyGenParams | EcKeyGenParams => {
78+
switch (type) {
79+
case KeyType.RSA_65537:
80+
return {
81+
name: "RSA-PSS",
82+
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
83+
hash: {
84+
name: "SHA-256",
85+
},
86+
};
87+
default:
88+
throw new Error(`Unsupported RSA KeyType ${type}`);
89+
}
90+
};
8291

83-
export const getSigningParameters = (type: KeyType): AlgorithmIdentifier | RsaPssParams | EcdsaParams => {
84-
switch(type) {
85-
case KeyType.RSA_65537:
86-
return {
87-
name: "RSA-PSS",
88-
saltLength: 32,
89-
};
90-
default:
91-
throw new Error(`Unsupported RSA KeyType ${type}`);
92-
}
93-
}
92+
export const getSigningParameters = (
93+
type: KeyType
94+
): AlgorithmIdentifier | RsaPssParams | EcdsaParams => {
95+
switch (type) {
96+
case KeyType.RSA_65537:
97+
return {
98+
name: "RSA-PSS",
99+
saltLength: 32,
100+
};
101+
default:
102+
throw new Error(`Unsupported RSA KeyType ${type}`);
103+
}
104+
};

0 commit comments

Comments
 (0)