Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
feat: ✨ Replace arweave-js with @irys/arweave
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTheRobot committed Sep 25, 2023
1 parent d3755bd commit 5601d99
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 333 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@
"@ethersproject/signing-key": "^5.7.0",
"@ethersproject/transactions": "^5.7.0",
"@ethersproject/wallet": "^5.7.0",
"@irys/arweave": "^0.0.1",
"@noble/ed25519": "^1.6.1",
"arweave": "=1.11.8",
"base64url": "^3.0.1",
"bs58": "^4.0.1",
"keccak": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/Bundle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import base64url from "base64url";
import { byteArrayToLong } from "./utils";
import DataItem from "./DataItem";
import type Arweave from "arweave";
import type Arweave from "@irys/arweave";
import type { BundleInterface } from "./BundleInterface";
import type { JWKInterface } from "./interface-jwk";
import { createHash } from "crypto";
Expand Down
2 changes: 1 addition & 1 deletion src/BundleInterface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BundleItem } from "./BundleItem";
import type Arweave from "arweave";
import type Arweave from "@irys/arweave";
import type { JWKInterface } from "./interface-jwk";
import type { CreateTransactionInterface, Transaction } from "$/utils";

Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/fileBundle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import Bundle from "../file/FileBundle";
import { EthereumSigner } from "../../index";
import { bundleAndSignData } from "../file";
import base64url from "base64url";
import type Transactions from "arweave/node/transactions";
import type Arweave from "arweave/node/common";
import type Transactions from "@irys/arweave/common/transactions";
import type Arweave from "@irys/arweave";
import type { JWKInterface } from "../";
import Transaction from "arweave/node/lib/transaction";
import Transaction from "@irys/arweave/common/lib/transaction";
import path from "path";
import type { PathLike } from "fs";
import fs from "fs";
Expand Down
7 changes: 3 additions & 4 deletions src/file/FileBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import FileDataItem from "./FileDataItem";
import type { PathLike } from "fs";
import { createReadStream, promises } from "fs";
import { byteArrayToLong } from "../utils";
import type Arweave from "arweave";
import type Arweave from "@irys/arweave";
import { read as FSRead } from "fs";
import MultiStream from "multistream";
// import { pipeline } from 'stream/promises';
Expand All @@ -13,7 +13,6 @@ import { promisify } from "util";
import base64url from "base64url";
import { pipeline } from "stream/promises";

import { createTransactionAsync, uploadTransactionAsync } from "arweave-stream-tx";
import type { CreateTransactionInterface, Transaction } from "$/utils";
import { resolve } from "path";
// import { Readable } from 'stream';
Expand Down Expand Up @@ -100,7 +99,7 @@ export class FileBundle implements BundleInterface {

const stream = MultiStream.obj(streams);

const tx = await pipeline(stream, createTransactionAsync(attributes, arweave, jwk));
const tx = await pipeline(stream, arweave.stream.createTransactionAsync(attributes, jwk));
tx.addTag("Bundle-Format", "binary");
tx.addTag("Bundle-Version", "2.0.0");

Expand All @@ -122,7 +121,7 @@ export class FileBundle implements BundleInterface {
const stream2 = MultiStream.obj(streams2);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
await pipeline(stream2, uploadTransactionAsync(tx, arweave, true) as any);
await pipeline(stream2, arweave.stream.uploadTransactionAsync(tx, true) as any);

return tx;
}
Expand Down
10 changes: 5 additions & 5 deletions src/nodeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { createPublicKey } from "crypto";
import { default as nodeDriver } from "arweave/node/lib/crypto/node-driver";
import { default as nodeDriver } from "@irys/arweave/node/node-driver";
import type { JWKInterface } from "./interface-jwk";
// import CryptoInterface from "arweave/node/lib/crypto/crypto-interface";
export { stringToBuffer, concatBuffers } from "arweave/node/lib/utils";
export { default as Transaction } from "arweave/node/lib/transaction";
export { stringToBuffer, concatBuffers } from "@irys/arweave/common/lib/utils";
export { default as Transaction } from "@irys/arweave/common/lib/transaction";
export { deepHash } from "./deepHash";
// import type { Hash } from "crypto";
// export { default as Arweave } from "arweave/node";
// export const sha384 = (): Hash => createHash("sha384");
export type { CreateTransactionInterface } from "arweave/node/common";
export { default as Arweave } from "arweave/node";
export type { CreateTransactionInterface } from "@irys/arweave/common/arweave";
export { default as Arweave } from "@irys/arweave/node";

// hack as ESM won't unpack .default CJS imports, so we do so dynamically
// eslint-disable-next-line @typescript-eslint/dot-notation
Expand Down
2 changes: 1 addition & 1 deletion src/signing/chains/ArweaveSigner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Rsa4096Pss from "../keys/Rsa4096Pss";
import type { JWKInterface } from "../../interface-jwk";
import { jwkTopem } from "arweave/node/lib/crypto/pem";
import { jwkTopem } from "@irys/arweave/common/lib/crypto/pem";
import base64url from "base64url";
import { getCryptoDriver } from "$/utils";

Expand Down
12 changes: 7 additions & 5 deletions src/signing/chains/arconnectSigner.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import type { Signer } from "..";
import { SignatureConfig, SIG_CONFIG } from "../../constants";
import Arweave from "arweave";
import type Arweave from "@irys/arweave";
import base64url from "base64url";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import type * as _ from "arconnect";
import { getCryptoDriver } from "$/utils";

export default class InjectedArweaveSigner implements Signer {
private signer: Window["arweaveWallet"];
public publicKey: Buffer;
readonly ownerLength: number = SIG_CONFIG[SignatureConfig.ARWEAVE].pubLength;
readonly signatureLength: number = SIG_CONFIG[SignatureConfig.ARWEAVE].sigLength;
readonly signatureType: SignatureConfig = SignatureConfig.ARWEAVE;

constructor(windowArweaveWallet: Window["arweaveWallet"]) {
protected arweave: Arweave;
constructor(windowArweaveWallet: Window["arweaveWallet"], arweave: Arweave) {
this.signer = windowArweaveWallet;
this.arweave = arweave;
}

async setPublicKey(): Promise<void> {
Expand All @@ -32,11 +34,11 @@ export default class InjectedArweaveSigner implements Signer {
};

const signature = await this.signer.signature(message, algorithm);
const buf = new Uint8Array(Object.values(signature));
const buf = new Uint8Array(Object.values(signature).map((v) => +v));
return buf;
}

static async verify(pk: string, message: Uint8Array, signature: Uint8Array): Promise<boolean> {
return await Arweave.crypto.verify(pk, message, signature);
return await getCryptoDriver().verify(pk, message, signature);
}
}
2 changes: 1 addition & 1 deletion src/signing/keys/__tests__/rsa4096.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Rsa4096Pss from "../Rsa4096Pss";
import { jwkTopem } from "arweave/node/lib/crypto/pem";
import { jwkTopem } from "@irys/arweave/common/lib/crypto/pem";
import testKey from "../../../__tests__/test_key0.json";

const privateKey = jwkTopem(testKey);
Expand Down
10 changes: 5 additions & 5 deletions src/webUtils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { JWKInterface } from "./interface-jwk";
export type { default as Transaction } from "arweave/web/lib/transaction";
export type { CreateTransactionInterface } from "arweave/web/common";
import webDriver from "arweave/web/lib/crypto/webcrypto-driver";
export { stringToBuffer, concatBuffers } from "arweave/web/lib/utils";
export type { default as Transaction } from "@irys/arweave/common/lib/transaction";
export type { CreateTransactionInterface } from "@irys/arweave/common/arweave";
import webDriver from "@irys/arweave/web/webcrypto-driver";
export { stringToBuffer, concatBuffers } from "@irys/arweave/common/lib/utils";
export { deepHash } from "./deepHash";
export { default as Arweave } from "arweave/web";
export { Arweave } from "@irys/arweave/web/arweave";
// import { sha384 as SHA384 } from "sha";
// export { default as Arweave } from "arweave/web";
// import type { Hash } from "crypto";
Expand Down
Loading

0 comments on commit 5601d99

Please sign in to comment.