Socket
Socket
Sign inDemoInstall

arbundles

Package Overview
Dependencies
Maintainers
3
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arbundles - npm Package Compare versions

Comparing version 0.9.0-a1 to 0.9.0-a2

16

build/node/cjs/index.js
"use strict";
// import { stringToBuffer } from "arweave/node/lib/utils";
// import type DataItem from "./src/DataItem.js";
// import { deepHash } from "./src/deepHash.js";
// import getSigData from "./src/ar-data-base.js";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

@@ -21,15 +17,3 @@ if (k2 === undefined) k2 = k;

Object.defineProperty(exports, "__esModule", { value: true });
// getSigData.getSignatureData = (item: DataItem): Promise<Uint8Array> => {
// return deepHash([
// stringToBuffer("dataitem"),
// stringToBuffer("1"),
// stringToBuffer(item.signatureType.toString()),
// item.rawOwner,
// item.rawTarget,
// item.rawAnchor,
// item.rawTags,
// item.rawData,
// ]);
// };
__exportStar(require("./src/index"), exports);
//# sourceMappingURL=index.js.map

29

build/node/cjs/src/DataItem.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -37,5 +14,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const constants_1 = require("./constants");
const crypto = __importStar(require("crypto"));
const utils_2 = require("./nodeUtils.js");
const tags_1 = require("./tags");
const crypto_1 = require("crypto");
exports.MIN_BINARY_SIZE = 80;

@@ -66,3 +43,3 @@ class DataItem {

get rawId() {
return crypto.createHash("sha256").update(this.rawSignature).digest();
return (0, crypto_1.createHash)("sha256").update(this.rawSignature).digest();
}

@@ -161,3 +138,3 @@ set rawId(id) {

this.binary.set(signature, 2);
this._id = buffer_1.Buffer.from(await utils_2.Arweave.crypto.hash(signature));
this._id = buffer_1.Buffer.from(await (0, utils_2.getCryptoDriver)().hash(signature));
}

@@ -164,0 +141,0 @@ isSigned() {

20

build/node/cjs/src/deepHash.js

@@ -17,14 +17,14 @@ "use strict";

}
const tag = utils_1.Arweave.utils.concatBuffers([utils_1.Arweave.utils.stringToBuffer("blob"), utils_1.Arweave.utils.stringToBuffer(length.toString())]);
const taggedHash = utils_1.Arweave.utils.concatBuffers([await utils_1.Arweave.crypto.hash(tag, "SHA-384"), context.digest()]);
return await utils_1.Arweave.crypto.hash(taggedHash, "SHA-384");
const tag = (0, utils_1.concatBuffers)([(0, utils_1.stringToBuffer)("blob"), (0, utils_1.stringToBuffer)(length.toString())]);
const taggedHash = (0, utils_1.concatBuffers)([await (0, utils_1.getCryptoDriver)().hash(tag, "SHA-384"), context.digest()]);
return await (0, utils_1.getCryptoDriver)().hash(taggedHash, "SHA-384");
}
else if (Array.isArray(data)) {
const tag = utils_1.Arweave.utils.concatBuffers([utils_1.Arweave.utils.stringToBuffer("list"), utils_1.Arweave.utils.stringToBuffer(data.length.toString())]);
return await deepHashChunks(data, await utils_1.Arweave.crypto.hash(tag, "SHA-384"));
const tag = (0, utils_1.concatBuffers)([(0, utils_1.stringToBuffer)("list"), (0, utils_1.stringToBuffer)(data.length.toString())]);
return await deepHashChunks(data, await (0, utils_1.getCryptoDriver)().hash(tag, "SHA-384"));
}
const _data = data;
const tag = utils_1.Arweave.utils.concatBuffers([utils_1.Arweave.utils.stringToBuffer("blob"), utils_1.Arweave.utils.stringToBuffer(_data.byteLength.toString())]);
const taggedHash = utils_1.Arweave.utils.concatBuffers([await utils_1.Arweave.crypto.hash(tag, "SHA-384"), await utils_1.Arweave.crypto.hash(_data, "SHA-384")]);
return await utils_1.Arweave.crypto.hash(taggedHash, "SHA-384");
const tag = (0, utils_1.concatBuffers)([(0, utils_1.stringToBuffer)("blob"), (0, utils_1.stringToBuffer)(_data.byteLength.toString())]);
const taggedHash = (0, utils_1.concatBuffers)([await (0, utils_1.getCryptoDriver)().hash(tag, "SHA-384"), await (0, utils_1.getCryptoDriver)().hash(_data, "SHA-384")]);
return await (0, utils_1.getCryptoDriver)().hash(taggedHash, "SHA-384");
}

@@ -36,4 +36,4 @@ exports.deepHash = deepHash;

}
const hashPair = utils_1.Arweave.utils.concatBuffers([acc, await deepHash(chunks[0])]);
const newAcc = await utils_1.Arweave.crypto.hash(hashPair, "SHA-384");
const hashPair = (0, utils_1.concatBuffers)([acc, await deepHash(chunks[0])]);
const newAcc = await (0, utils_1.getCryptoDriver)().hash(hashPair, "SHA-384");
return await deepHashChunks(chunks.slice(1), newAcc);

@@ -40,0 +40,0 @@ }

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -31,8 +8,8 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const tmp_promise_1 = require("tmp-promise");
const fs = __importStar(require("fs"));
const utils_1 = require("../utils");
const FileBundle_1 = __importDefault(require("./FileBundle"));
const fs_1 = require("fs");
async function bundleAndSignData(dataItems, signer, dir) {
const headerFile = await (0, tmp_promise_1.file)({ dir });
const headerStream = fs.createWriteStream(headerFile.path);
const headerStream = (0, fs_1.createWriteStream)(headerFile.path);
const files = new Array(dataItems.length);

@@ -39,0 +16,0 @@ headerStream.write((0, utils_1.longTo32ByteArray)(dataItems.length));

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -31,3 +8,2 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const FileDataItem_1 = __importDefault(require("./FileDataItem"));
const fs = __importStar(require("fs"));
const tmp_promise_1 = require("tmp-promise");

@@ -38,6 +14,7 @@ const base64url_1 = __importDefault(require("base64url"));

const promises_1 = require("stream/promises");
const fs_1 = require("fs");
async function createData(data, signer, opts) {
var _a, _b, _c, _d, _e;
const filename = await (0, tmp_promise_1.tmpName)();
const stream = fs.createWriteStream(filename);
const stream = (0, fs_1.createWriteStream)(filename);
// TODO: Add asserts

@@ -44,0 +21,0 @@ // Parse all values to a buffer and

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -30,3 +7,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.signedFileStream = exports.getTags = exports.getAnchor = exports.getTarget = exports.getOwner = exports.getSignature = exports.getId = exports.getHeaders = exports.getHeaderAt = exports.numberOfItems = exports.fileToJson = void 0;
const fs = __importStar(require("fs"));
const fs_1 = require("fs");
const util_1 = require("util");

@@ -37,6 +14,6 @@ const utils_1 = require("../utils");

const tags_1 = require("../tags");
const read = (0, util_1.promisify)(fs.read);
const fileToFd = async (f) => (typeof f === "string" ? await fs.promises.open(f, "r") : f);
const read = (0, util_1.promisify)(fs_1.read);
const fileToFd = async (f) => (typeof f === "string" ? await fs_1.promises.open(f, "r") : f);
async function fileToJson(filename) {
const fd = await fs.promises.open(filename, "r").then((handle) => handle.fd);
const fd = await fs_1.promises.open(filename, "r").then((handle) => handle.fd);
let tagsStart = 512 + 512 + 2;

@@ -177,5 +154,5 @@ const targetPresent = await read(fd, Buffer.alloc(1), 1024, 64, null).then((value) => value.buffer[0] == 1);

async function signedFileStream(path, signer, opts) {
return (0, stream_1.streamSigner)(fs.createReadStream(path), fs.createReadStream(path), signer, opts);
return (0, stream_1.streamSigner)((0, fs_1.createReadStream)(path), (0, fs_1.createReadStream)(path), signer, opts);
}
exports.signedFileStream = signedFileStream;
//# sourceMappingURL=file.js.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -31,4 +8,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const FileDataItem_1 = __importDefault(require("./FileDataItem"));
const fs = __importStar(require("fs"));
const fs_1 = require("fs");
const utils_1 = require("../utils");
const fs_2 = require("fs");
const multistream_1 = __importDefault(require("multistream"));

@@ -42,3 +20,3 @@ const util_1 = require("util");

// import { pipeline } from 'stream/promises';
const read = (0, util_1.promisify)(fs.read);
const read = (0, util_1.promisify)(fs_2.read);
class FileBundle {

@@ -50,7 +28,7 @@ constructor(headerFile, txs) {

static async fromDir(dir) {
const txs = await fs.promises.readdir(dir).then((r) => r.filter(async (f) => !(await fs.promises.stat(f).then((s) => s.isDirectory()))));
const txs = await fs_1.promises.readdir(dir).then((r) => r.filter(async (f) => !(await fs_1.promises.stat(f).then((s) => s.isDirectory()))));
return new FileBundle(dir + "/header", txs);
}
async length() {
const handle = await fs.promises.open(this.headerFile, "r");
const handle = await fs_1.promises.open(this.headerFile, "r");
const lengthBuffer = await read(handle.fd, Buffer.allocUnsafe(32), 0, 32, 0).then((r) => r.buffer);

@@ -84,3 +62,3 @@ await handle.close();

async getRaw() {
const streams = [fs.createReadStream(this.headerFile), ...this.txs.map((t) => fs.createReadStream(t))];
const streams = [(0, fs_1.createReadStream)(this.headerFile), ...this.txs.map((t) => (0, fs_1.createReadStream)(t))];
const stream = multistream_1.default.obj(streams);

@@ -94,3 +72,3 @@ let buff = Buffer.allocUnsafe(0);

async toTransaction(attributes, arweave, jwk) {
const streams = [fs.createReadStream(this.headerFile), ...this.txs.map((t) => fs.createReadStream(t))];
const streams = [(0, fs_1.createReadStream)(this.headerFile), ...this.txs.map((t) => (0, fs_1.createReadStream)(t))];
const stream = multistream_1.default.obj(streams);

@@ -110,3 +88,3 @@ const tx = await (0, promises_1.pipeline)(stream, (0, arweave_stream_tx_1.createTransactionAsync)(attributes, arweave, jwk));

await arweave.transactions.sign(tx, jwk);
const streams2 = [fs.createReadStream(this.headerFile), ...this.txs.map((t) => fs.createReadStream(t))];
const streams2 = [(0, fs_1.createReadStream)(this.headerFile), ...this.txs.map((t) => (0, fs_1.createReadStream)(t))];
const stream2 = multistream_1.default.obj(streams2);

@@ -117,3 +95,3 @@ await (0, promises_1.pipeline)(stream2, (0, arweave_stream_tx_1.uploadTransactionAsync)(tx, arweave, true));

async *getHeaders() {
const handle = await fs.promises.open(this.headerFile, "r");
const handle = await fs_1.promises.open(this.headerFile, "r");
for (let i = 32; i < 32 + 64 * (await this.length()); i += 64) {

@@ -120,0 +98,0 @@ yield {

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -31,7 +8,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const base64url_1 = __importDefault(require("base64url"));
const fs = __importStar(require("fs"));
const fs_1 = require("fs");
const utils_1 = require("../utils");
const __1 = require("..");
const utils_2 = require("../nodeUtils.js");
const utils_3 = require("../nodeUtils.js");
const signing_1 = require("../signing");

@@ -42,4 +18,4 @@ const axios_1 = __importDefault(require("axios"));

const tags_1 = require("../tags");
const read = (0, util_1.promisify)(fs.read);
const write = (0, util_1.promisify)(fs.write);
const read = (0, util_1.promisify)(fs_1.read);
const write = (0, util_1.promisify)(fs_1.write);
class FileDataItem {

@@ -80,3 +56,3 @@ async signatureLength() {

static async verify(filename) {
const handle = await fs.promises.open(filename, "r");
const handle = await fs_1.promises.open(filename, "r");
const item = new FileDataItem(filename);

@@ -111,3 +87,3 @@ const sigType = await item.signatureType();

await item.rawTags(),
fs.createReadStream(filename, {
(0, fs_1.createReadStream)(filename, {
start: await item.dataStart(),

@@ -131,6 +107,6 @@ }),

async size() {
return await fs.promises.stat(this.filename).then((r) => r.size);
return await fs_1.promises.stat(this.filename).then((r) => r.size);
}
async signatureType() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await fs_1.promises.open(this.filename, "r");
const buffer = await read(handle.fd, Buffer.allocUnsafe(2), 0, 2, 0).then((r) => r.buffer);

@@ -141,3 +117,3 @@ await handle.close();

async rawSignature() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await fs_1.promises.open(this.filename, "r");
const length = await this.signatureLength();

@@ -152,3 +128,3 @@ const buffer = await read(handle.fd, Buffer.alloc(length), 0, length, 2).then((r) => r.buffer);

async rawOwner() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await fs_1.promises.open(this.filename, "r");
const length = await this.ownerLength();

@@ -163,3 +139,3 @@ const buffer = await read(handle.fd, Buffer.allocUnsafe(length), 0, length, 2 + (await this.signatureLength())).then((r) => r.buffer);

async rawTarget() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await fs_1.promises.open(this.filename, "r");
const targetStart = await this.getTargetStart();

@@ -185,3 +161,3 @@ const targetPresentBuffer = await read(handle.fd, Buffer.allocUnsafe(1), 0, 1, targetStart).then((r) => r.buffer);

if (anchorPresent) {
const handle = await fs.promises.open(this.filename, "r");
const handle = await fs_1.promises.open(this.filename, "r");
const anchorBuffer = await read(handle.fd, Buffer.allocUnsafe(32), 0, 32, anchorStart + 1).then((r) => r.buffer);

@@ -197,3 +173,3 @@ await handle.close();

async rawTags() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await fs_1.promises.open(this.filename, "r");
const tagsStart = await this.getTagsStart();

@@ -229,3 +205,3 @@ const numberOfTagsBuffer = await read(handle.fd, Buffer.allocUnsafe(8), 0, 8, tagsStart).then((r) => r.buffer);

}
const handle = await fs.promises.open(this.filename, "r");
const handle = await fs_1.promises.open(this.filename, "r");
const dataBuffer = await read(handle.fd, Buffer.allocUnsafe(dataSize), 0, dataSize, dataStart).then((r) => r.buffer);

@@ -248,7 +224,7 @@ await handle.close();

await this.rawTags(),
fs.createReadStream(this.filename, { start: dataStart }),
(0, fs_1.createReadStream)(this.filename, { start: dataStart }),
]);
const signatureBytes = await signer.sign(signatureData);
const idBytes = await utils_3.Arweave.crypto.hash(signatureBytes);
const handle = await fs.promises.open(this.filename, "r+");
const idBytes = await (0, utils_2.getCryptoDriver)().hash(signatureBytes);
const handle = await fs_1.promises.open(this.filename, "r+");
await write(handle.fd, signatureBytes, 0, await this.signatureLength(), 2);

@@ -268,3 +244,3 @@ this.rawId = Buffer.from(idBytes);

throw new Error("You must sign before sending to bundler");
const response = await axios_1.default.post(`${bundler}/tx`, fs.createReadStream(this.filename), {
const response = await axios_1.default.post(`${bundler}/tx`, (0, fs_1.createReadStream)(this.filename), {
headers,

@@ -286,3 +262,3 @@ timeout: 100000,

async dataStart() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await fs_1.promises.open(this.filename, "r");
const tagsStart = await this.getTagsStart();

@@ -296,3 +272,3 @@ const numberOfTagsBytesBuffer = await read(handle.fd, Buffer.allocUnsafe(8), 0, 8, tagsStart + 8).then((r) => r.buffer);

const targetStart = await this.getTargetStart();
const handle = await fs.promises.open(this.filename, "r");
const handle = await fs_1.promises.open(this.filename, "r");
const targetPresentBuffer = await read(handle.fd, Buffer.allocUnsafe(1), 0, 1, targetStart).then((r) => r.buffer);

@@ -299,0 +275,0 @@ const targetPresent = targetPresentBuffer[0] === 1;

@@ -10,3 +10,2 @@ export * from "./signing/index";

export * from "./DataItem";
export * from "./deepHash";
export * from "./error";

@@ -16,1 +15,2 @@ export * from "./interface-jwk";

export * from "./utils";
export * from "./nodeUtils.js";
"use strict";
// import { bundleAndSignData, unbundleData } from "./ar-data-bundle.js";
// import Bundle from "./Bundle.js";
// import DataItem, { MIN_BINARY_SIZE } from "./DataItem.js";
// import { deepHash } from "./deepHash.js";
// import { DataItemCreateOptions } from "./ar-data-base.js";
// import { createData } from "./ar-data-create.js";
// import { ArweaveSigner } from "./signing/index.js";
// import SolanaSigner from "./signing/chains/SolanaSigner.js";
// import EthereumSigner from "./signing/chains/ethereumSigner.js";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

@@ -26,18 +17,2 @@ if (k2 === undefined) k2 = k;

Object.defineProperty(exports, "__esModule", { value: true });
// export {
// MIN_BINARY_SIZE,
// Bundle,
// DataItem,
// createData,
// bundleAndSignData,
// unbundleData,
// deepHash,
// DataItemCreateOptions,
// };
// const signers = {
// ArweaveSigner,
// SolanaSigner,
// EthereumSigner,
// };
// export { signers };
__exportStar(require("./signing/index"), exports);

@@ -52,3 +27,2 @@ __exportStar(require("./ar-data-base"), exports);

__exportStar(require("./DataItem"), exports);
__exportStar(require("./deepHash"), exports);
__exportStar(require("./error"), exports);

@@ -58,2 +32,3 @@ __exportStar(require("./interface-jwk"), exports);

__exportStar(require("./utils"), exports);
__exportStar(require("./nodeUtils.js"), exports);
//# sourceMappingURL=index.js.map

@@ -1,6 +0,10 @@

export type { CreateTransactionInterface } from "arweave/node/common";
export { stringToBuffer } from "arweave/node/lib/utils";
import nodeDriver from "arweave/node/lib/crypto/node-driver";
import type { JWKInterface } from "./interface-jwk";
export { stringToBuffer, concatBuffers } from "arweave/node/lib/utils";
export { default as Transaction } from "arweave/node/lib/transaction";
export { deepHash } from "./deepHash";
export { default as Arweave } from "arweave/node";
export { default as cryptoDriver } from "arweave/node/lib/crypto/node-driver";
export type { CreateTransactionInterface } from "arweave/node/common";
export declare class CryptoDriver extends nodeDriver {
getPublicKey(jwk: JWKInterface): string;
}
export declare function getCryptoDriver(): CryptoDriver;

@@ -6,5 +6,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.cryptoDriver = exports.Arweave = exports.deepHash = exports.Transaction = exports.stringToBuffer = void 0;
exports.getCryptoDriver = exports.CryptoDriver = exports.deepHash = exports.Transaction = exports.concatBuffers = exports.stringToBuffer = void 0;
const crypto_1 = require("crypto");
const node_driver_1 = __importDefault(require("arweave/node/lib/crypto/node-driver"));
var utils_1 = require("arweave/node/lib/utils");
Object.defineProperty(exports, "stringToBuffer", { enumerable: true, get: function () { return utils_1.stringToBuffer; } });
Object.defineProperty(exports, "concatBuffers", { enumerable: true, get: function () { return utils_1.concatBuffers; } });
var transaction_1 = require("arweave/node/lib/transaction");

@@ -14,6 +17,22 @@ Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return __importDefault(transaction_1).default; } });

Object.defineProperty(exports, "deepHash", { enumerable: true, get: function () { return deepHash_1.deepHash; } });
var node_1 = require("arweave/node");
Object.defineProperty(exports, "Arweave", { enumerable: true, get: function () { return __importDefault(node_1).default; } });
var node_driver_1 = require("arweave/node/lib/crypto/node-driver");
Object.defineProperty(exports, "cryptoDriver", { enumerable: true, get: function () { return __importDefault(node_driver_1).default; } });
class CryptoDriver extends node_driver_1.default {
getPublicKey(jwk) {
return (0, crypto_1.createPublicKey)({
key: this.jwkToPem(jwk),
type: "pkcs1",
format: "pem",
})
.export({
format: "pem",
type: "pkcs1",
})
.toString();
}
}
exports.CryptoDriver = CryptoDriver;
let d;
function getCryptoDriver() {
return (d !== null && d !== void 0 ? d : (d = new CryptoDriver()));
}
exports.getCryptoDriver = getCryptoDriver;
//# sourceMappingURL=nodeUtils.js.map

@@ -19,6 +19,6 @@ "use strict";

sign(message) {
return utils_1.Arweave.crypto.sign(this.jwk, message);
return (0, utils_1.getCryptoDriver)().sign(this.jwk, message);
}
static async verify(pk, message, signature) {
return await utils_1.Arweave.crypto.verify(pk, message, signature);
return await (0, utils_1.getCryptoDriver)().verify(pk, message, signature);
}

@@ -25,0 +25,0 @@ }

@@ -6,6 +6,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const crypto_1 = require("crypto");
const utils_1 = require("../../nodeUtils.js");
const base64url_1 = __importDefault(require("base64url"));
const constants_1 = require("../../constants");
const crypto_1 = require("crypto");
class Rsa4096Pss {

@@ -22,12 +22,3 @@ get publicKey() {

if (!pk) {
this.pk = (0, crypto_1.createPublicKey)({
key: _key,
type: "pkcs1",
format: "pem",
})
.export({
format: "pem",
type: "pkcs1",
})
.toString();
this.pk = (0, utils_1.getCryptoDriver)().getPublicKey(JSON.parse(_key));
}

@@ -42,3 +33,3 @@ }

static async verify(pk, message, signature) {
return await utils_1.Arweave.crypto.verify(Buffer.isBuffer(pk) ? base64url_1.default.encode(pk) : pk, message, signature);
return await (0, utils_1.getCryptoDriver)().verify(Buffer.isBuffer(pk) ? base64url_1.default.encode(pk) : pk, message, signature);
}

@@ -45,0 +36,0 @@ }

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -36,6 +13,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const constants_2 = require("../constants");
const crypto = __importStar(require("crypto"));
const utils_2 = require("../nodeUtils.js");
const deepHash_1 = require("../deepHash");
const tags_1 = require("../tags");
const crypto_1 = require("crypto");
async function processStream(stream) {

@@ -139,3 +116,3 @@ const reader = getReader(stream);

// Check id
if (id !== (0, base64url_1.default)(crypto.createHash("sha256").update(signature).digest()))
if (id !== (0, base64url_1.default)((0, crypto_1.createHash)("sha256").update(signature).digest()))
throw new Error("ID doesn't match signature");

@@ -142,0 +119,0 @@ const Signer = constants_1.indexToType[signatureType];

@@ -0,6 +1,11 @@

import type { JWKInterface } from "./interface-jwk";
export type { default as Transaction } from "arweave/web/lib/transaction";
export type { CreateTransactionInterface } from "arweave/web/common";
export { stringToBuffer } from "arweave/web/lib/utils";
export { default as Transaction } from "arweave/web/lib/transaction";
export { default as deepHash } from "arweave/web/lib/deepHash";
export { default as Arweave } from "arweave/web";
export { default as cryptoDriver } from "arweave/web/lib/crypto/webcrypto-driver";
import webDriver from "arweave/web/lib/crypto/webcrypto-driver";
export { stringToBuffer, concatBuffers } from "arweave/web/lib/utils";
export { deepHash } from "./deepHash";
export declare class CryptoDriver extends webDriver {
protected hasSubtle: boolean;
getPublicKey(_jwk: JWKInterface): string;
}
export declare function getCryptoDriver(): CryptoDriver;

@@ -6,13 +6,23 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.cryptoDriver = exports.Arweave = exports.deepHash = exports.Transaction = exports.stringToBuffer = void 0;
exports.getCryptoDriver = exports.CryptoDriver = exports.deepHash = exports.concatBuffers = exports.stringToBuffer = void 0;
// import { sha384 as SHA384 } from "sha.js";
const webcrypto_driver_1 = __importDefault(require("arweave/web/lib/crypto/webcrypto-driver"));
var utils_1 = require("arweave/web/lib/utils");
Object.defineProperty(exports, "stringToBuffer", { enumerable: true, get: function () { return utils_1.stringToBuffer; } });
var transaction_1 = require("arweave/web/lib/transaction");
Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return __importDefault(transaction_1).default; } });
var deepHash_1 = require("arweave/web/lib/deepHash");
Object.defineProperty(exports, "deepHash", { enumerable: true, get: function () { return __importDefault(deepHash_1).default; } });
var web_1 = require("arweave/web");
Object.defineProperty(exports, "Arweave", { enumerable: true, get: function () { return __importDefault(web_1).default; } });
var webcrypto_driver_1 = require("arweave/web/lib/crypto/webcrypto-driver");
Object.defineProperty(exports, "cryptoDriver", { enumerable: true, get: function () { return __importDefault(webcrypto_driver_1).default; } });
Object.defineProperty(exports, "concatBuffers", { enumerable: true, get: function () { return utils_1.concatBuffers; } });
var deepHash_1 = require("./deepHash");
Object.defineProperty(exports, "deepHash", { enumerable: true, get: function () { return deepHash_1.deepHash; } });
// export { default as Arweave } from "arweave/web";
// export const sha384 = (): Hash => SHA384("sha384");
class CryptoDriver extends webcrypto_driver_1.default {
getPublicKey(_jwk) {
throw new Error("Unimplemented");
}
}
exports.CryptoDriver = CryptoDriver;
let d;
function getCryptoDriver() {
return (d !== null && d !== void 0 ? d : (d = new CryptoDriver()));
}
exports.getCryptoDriver = getCryptoDriver;
//# sourceMappingURL=webUtils.js.map

@@ -42,5 +42,2 @@ /// <reference types="node" />

DataItem: typeof arbundlesSrc.DataItem;
deepHash(data: arbundlesSrc.DeepHashChunk): Promise<Uint8Array>;
deepHashChunks(chunks: arbundlesSrc.DeepHashChunks, acc: Uint8Array): Promise<Uint8Array>;
hashStream(stream: AsyncIterable<Buffer>): Promise<Buffer>;
serializeTags(tags: {

@@ -59,4 +56,10 @@ name: string;

byteArrayToLong(byteArray: Uint8Array): number;
getCryptoDriver(): arbundlesSrc.CryptoDriver;
stringToBuffer: typeof arbundlesSrc.stringToBuffer;
concatBuffers: typeof arbundlesSrc.concatBuffers;
Transaction: typeof arbundlesSrc.Transaction;
deepHash: typeof arbundlesSrc.deepHash;
CryptoDriver: typeof arbundlesSrc.CryptoDriver;
};
export * from "./src";
export * from "./src/index";
export * from "./src/stream";

@@ -101,5 +104,2 @@ export default expObj;

DataItem: typeof arbundlesSrc.DataItem;
deepHash(data: arbundlesSrc.DeepHashChunk): Promise<Uint8Array>;
deepHashChunks(chunks: arbundlesSrc.DeepHashChunks, acc: Uint8Array): Promise<Uint8Array>;
hashStream(stream: AsyncIterable<Buffer>): Promise<Buffer>;
serializeTags(tags: {

@@ -118,2 +118,8 @@ name: string;

byteArrayToLong(byteArray: Uint8Array): number;
getCryptoDriver(): arbundlesSrc.CryptoDriver;
stringToBuffer: typeof arbundlesSrc.stringToBuffer;
concatBuffers: typeof arbundlesSrc.concatBuffers;
Transaction: typeof arbundlesSrc.Transaction;
deepHash: typeof arbundlesSrc.deepHash;
CryptoDriver: typeof arbundlesSrc.CryptoDriver;
};

@@ -35,3 +35,3 @@ "use strict";

(_a = globalThis.arbundles) !== null && _a !== void 0 ? _a : (globalThis.arbundles = expObj);
__exportStar(require("./src"), exports);
__exportStar(require("./src/index"), exports);
__exportStar(require("./src/stream"), exports);

@@ -38,0 +38,0 @@ exports.default = expObj;

@@ -1,18 +0,2 @@

// import { stringToBuffer } from "arweave/node/lib/utils";
// import type DataItem from "./src/DataItem.js";
// import { deepHash } from "./src/deepHash.js";
// import getSigData from "./src/ar-data-base.js";
// getSigData.getSignatureData = (item: DataItem): Promise<Uint8Array> => {
// return deepHash([
// stringToBuffer("dataitem"),
// stringToBuffer("1"),
// stringToBuffer(item.signatureType.toString()),
// item.rawOwner,
// item.rawTarget,
// item.rawAnchor,
// item.rawTags,
// item.rawData,
// ]);
// };
export * from "./src/index.js";
//# sourceMappingURL=index.js.map

@@ -8,5 +8,5 @@ import { byteArrayToLong } from "./utils.js";

import { SIG_CONFIG, SignatureConfig } from "./constants.js";
import * as crypto from "crypto";
import { Arweave } from "./nodeUtils.js";
import { getCryptoDriver } from "./nodeUtils.js";
import { deserializeTags } from "./tags.js";
import { createHash } from "crypto";
export const MIN_BINARY_SIZE = 80;

@@ -39,3 +39,3 @@ export class DataItem {

get rawId() {
return crypto.createHash("sha256").update(this.rawSignature).digest();
return createHash("sha256").update(this.rawSignature).digest();
}

@@ -134,3 +134,3 @@ set rawId(id) {

this.binary.set(signature, 2);
this._id = Buffer.from(await Arweave.crypto.hash(signature));
this._id = Buffer.from(await getCryptoDriver().hash(signature));
}

@@ -137,0 +137,0 @@ isSigned() {

// In TypeScript 3.7, could be written as a single type:
// `type DeepHashChunk = Uint8Array | DeepHashChunk[];`
import { Arweave } from "./nodeUtils.js";
import { getCryptoDriver, concatBuffers, stringToBuffer } from "./nodeUtils.js";
import { createHash } from "crypto";

@@ -14,14 +14,14 @@ export async function deepHash(data) {

}
const tag = Arweave.utils.concatBuffers([Arweave.utils.stringToBuffer("blob"), Arweave.utils.stringToBuffer(length.toString())]);
const taggedHash = Arweave.utils.concatBuffers([await Arweave.crypto.hash(tag, "SHA-384"), context.digest()]);
return await Arweave.crypto.hash(taggedHash, "SHA-384");
const tag = concatBuffers([stringToBuffer("blob"), stringToBuffer(length.toString())]);
const taggedHash = concatBuffers([await getCryptoDriver().hash(tag, "SHA-384"), context.digest()]);
return await getCryptoDriver().hash(taggedHash, "SHA-384");
}
else if (Array.isArray(data)) {
const tag = Arweave.utils.concatBuffers([Arweave.utils.stringToBuffer("list"), Arweave.utils.stringToBuffer(data.length.toString())]);
return await deepHashChunks(data, await Arweave.crypto.hash(tag, "SHA-384"));
const tag = concatBuffers([stringToBuffer("list"), stringToBuffer(data.length.toString())]);
return await deepHashChunks(data, await getCryptoDriver().hash(tag, "SHA-384"));
}
const _data = data;
const tag = Arweave.utils.concatBuffers([Arweave.utils.stringToBuffer("blob"), Arweave.utils.stringToBuffer(_data.byteLength.toString())]);
const taggedHash = Arweave.utils.concatBuffers([await Arweave.crypto.hash(tag, "SHA-384"), await Arweave.crypto.hash(_data, "SHA-384")]);
return await Arweave.crypto.hash(taggedHash, "SHA-384");
const tag = concatBuffers([stringToBuffer("blob"), stringToBuffer(_data.byteLength.toString())]);
const taggedHash = concatBuffers([await getCryptoDriver().hash(tag, "SHA-384"), await getCryptoDriver().hash(_data, "SHA-384")]);
return await getCryptoDriver().hash(taggedHash, "SHA-384");
}

@@ -32,4 +32,4 @@ export async function deepHashChunks(chunks, acc) {

}
const hashPair = Arweave.utils.concatBuffers([acc, await deepHash(chunks[0])]);
const newAcc = await Arweave.crypto.hash(hashPair, "SHA-384");
const hashPair = concatBuffers([acc, await deepHash(chunks[0])]);
const newAcc = await getCryptoDriver().hash(hashPair, "SHA-384");
return await deepHashChunks(chunks.slice(1), newAcc);

@@ -36,0 +36,0 @@ }

import { file } from "tmp-promise";
import * as fs from "fs";
import { longTo32ByteArray } from "../utils.js";
import FileBundle from "./FileBundle.js";
import { createWriteStream } from "fs";
export async function bundleAndSignData(dataItems, signer, dir) {
const headerFile = await file({ dir });
const headerStream = fs.createWriteStream(headerFile.path);
const headerStream = createWriteStream(headerFile.path);
const files = new Array(dataItems.length);

@@ -9,0 +9,0 @@ headerStream.write(longTo32ByteArray(dataItems.length));

import FileDataItem from "./FileDataItem.js";
import * as fs from "fs";
import { tmpName } from "tmp-promise";

@@ -8,5 +7,6 @@ import base64url from "base64url";

import { pipeline } from "stream/promises";
import { createWriteStream } from "fs";
export async function createData(data, signer, opts) {
const filename = await tmpName();
const stream = fs.createWriteStream(filename);
const stream = createWriteStream(filename);
// TODO: Add asserts

@@ -13,0 +13,0 @@ // Parse all values to a buffer and

@@ -1,2 +0,2 @@

import * as fs from "fs";
import { createReadStream, promises, read as FSRead } from "fs";
import { promisify } from "util";

@@ -7,6 +7,6 @@ import { byteArrayToLong } from "../utils.js";

import { deserializeTags } from "../tags.js";
const read = promisify(fs.read);
const fileToFd = async (f) => (typeof f === "string" ? await fs.promises.open(f, "r") : f);
const read = promisify(FSRead);
const fileToFd = async (f) => (typeof f === "string" ? await promises.open(f, "r") : f);
export async function fileToJson(filename) {
const fd = await fs.promises.open(filename, "r").then((handle) => handle.fd);
const fd = await promises.open(filename, "r").then((handle) => handle.fd);
let tagsStart = 512 + 512 + 2;

@@ -131,4 +131,4 @@ const targetPresent = await read(fd, Buffer.alloc(1), 1024, 64, null).then((value) => value.buffer[0] == 1);

export async function signedFileStream(path, signer, opts) {
return streamSigner(fs.createReadStream(path), fs.createReadStream(path), signer, opts);
return streamSigner(createReadStream(path), createReadStream(path), signer, opts);
}
//# sourceMappingURL=file.js.map
import FileDataItem from "./FileDataItem.js";
import * as fs from "fs";
import { createReadStream, promises } from "fs";
import { byteArrayToLong } from "../utils.js";
import { read as FSRead } from "fs";
import MultiStream from "multistream";

@@ -12,3 +13,3 @@ import { promisify } from "util";

// import { pipeline } from 'stream/promises';
const read = promisify(fs.read);
const read = promisify(FSRead);
export class FileBundle {

@@ -22,7 +23,7 @@ headerFile;

static async fromDir(dir) {
const txs = await fs.promises.readdir(dir).then((r) => r.filter(async (f) => !(await fs.promises.stat(f).then((s) => s.isDirectory()))));
const txs = await promises.readdir(dir).then((r) => r.filter(async (f) => !(await promises.stat(f).then((s) => s.isDirectory()))));
return new FileBundle(dir + "/header", txs);
}
async length() {
const handle = await fs.promises.open(this.headerFile, "r");
const handle = await promises.open(this.headerFile, "r");
const lengthBuffer = await read(handle.fd, Buffer.allocUnsafe(32), 0, 32, 0).then((r) => r.buffer);

@@ -56,3 +57,3 @@ await handle.close();

async getRaw() {
const streams = [fs.createReadStream(this.headerFile), ...this.txs.map((t) => fs.createReadStream(t))];
const streams = [createReadStream(this.headerFile), ...this.txs.map((t) => createReadStream(t))];
const stream = MultiStream.obj(streams);

@@ -66,3 +67,3 @@ let buff = Buffer.allocUnsafe(0);

async toTransaction(attributes, arweave, jwk) {
const streams = [fs.createReadStream(this.headerFile), ...this.txs.map((t) => fs.createReadStream(t))];
const streams = [createReadStream(this.headerFile), ...this.txs.map((t) => createReadStream(t))];
const stream = MultiStream.obj(streams);

@@ -82,3 +83,3 @@ const tx = await pipeline(stream, createTransactionAsync(attributes, arweave, jwk));

await arweave.transactions.sign(tx, jwk);
const streams2 = [fs.createReadStream(this.headerFile), ...this.txs.map((t) => fs.createReadStream(t))];
const streams2 = [createReadStream(this.headerFile), ...this.txs.map((t) => createReadStream(t))];
const stream2 = MultiStream.obj(streams2);

@@ -89,3 +90,3 @@ await pipeline(stream2, uploadTransactionAsync(tx, arweave, true));

async *getHeaders() {
const handle = await fs.promises.open(this.headerFile, "r");
const handle = await promises.open(this.headerFile, "r");
for (let i = 32; i < 32 + 64 * (await this.length()); i += 64) {

@@ -92,0 +93,0 @@ yield {

import base64url from "base64url";
import * as fs from "fs";
import { createReadStream, promises, read as FSRead, write as FSWrite } from "fs";
import { byteArrayToLong } from "../utils.js";
import { deepHash } from "..";
import { stringToBuffer } from "../nodeUtils.js";
import { Arweave } from "../nodeUtils.js";
import { getCryptoDriver, stringToBuffer } from "../nodeUtils.js";
import { indexToType } from "../signing/index.js";

@@ -12,4 +11,4 @@ import axios from "axios";

import { deserializeTags } from "../tags.js";
const read = promisify(fs.read);
const write = promisify(fs.write);
const read = promisify(FSRead);
const write = promisify(FSWrite);
export class FileDataItem {

@@ -50,3 +49,3 @@ filename;

static async verify(filename) {
const handle = await fs.promises.open(filename, "r");
const handle = await promises.open(filename, "r");
const item = new FileDataItem(filename);

@@ -81,3 +80,3 @@ const sigType = await item.signatureType();

await item.rawTags(),
fs.createReadStream(filename, {
createReadStream(filename, {
start: await item.dataStart(),

@@ -101,6 +100,6 @@ }),

async size() {
return await fs.promises.stat(this.filename).then((r) => r.size);
return await promises.stat(this.filename).then((r) => r.size);
}
async signatureType() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const buffer = await read(handle.fd, Buffer.allocUnsafe(2), 0, 2, 0).then((r) => r.buffer);

@@ -111,3 +110,3 @@ await handle.close();

async rawSignature() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const length = await this.signatureLength();

@@ -122,3 +121,3 @@ const buffer = await read(handle.fd, Buffer.alloc(length), 0, length, 2).then((r) => r.buffer);

async rawOwner() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const length = await this.ownerLength();

@@ -133,3 +132,3 @@ const buffer = await read(handle.fd, Buffer.allocUnsafe(length), 0, length, 2 + (await this.signatureLength())).then((r) => r.buffer);

async rawTarget() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const targetStart = await this.getTargetStart();

@@ -155,3 +154,3 @@ const targetPresentBuffer = await read(handle.fd, Buffer.allocUnsafe(1), 0, 1, targetStart).then((r) => r.buffer);

if (anchorPresent) {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const anchorBuffer = await read(handle.fd, Buffer.allocUnsafe(32), 0, 32, anchorStart + 1).then((r) => r.buffer);

@@ -167,3 +166,3 @@ await handle.close();

async rawTags() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const tagsStart = await this.getTagsStart();

@@ -199,3 +198,3 @@ const numberOfTagsBuffer = await read(handle.fd, Buffer.allocUnsafe(8), 0, 8, tagsStart).then((r) => r.buffer);

}
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const dataBuffer = await read(handle.fd, Buffer.allocUnsafe(dataSize), 0, dataSize, dataStart).then((r) => r.buffer);

@@ -218,7 +217,7 @@ await handle.close();

await this.rawTags(),
fs.createReadStream(this.filename, { start: dataStart }),
createReadStream(this.filename, { start: dataStart }),
]);
const signatureBytes = await signer.sign(signatureData);
const idBytes = await Arweave.crypto.hash(signatureBytes);
const handle = await fs.promises.open(this.filename, "r+");
const idBytes = await getCryptoDriver().hash(signatureBytes);
const handle = await promises.open(this.filename, "r+");
await write(handle.fd, signatureBytes, 0, await this.signatureLength(), 2);

@@ -238,3 +237,3 @@ this.rawId = Buffer.from(idBytes);

throw new Error("You must sign before sending to bundler");
const response = await axios.post(`${bundler}/tx`, fs.createReadStream(this.filename), {
const response = await axios.post(`${bundler}/tx`, createReadStream(this.filename), {
headers,

@@ -256,3 +255,3 @@ timeout: 100000,

async dataStart() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const tagsStart = await this.getTagsStart();

@@ -266,3 +265,3 @@ const numberOfTagsBytesBuffer = await read(handle.fd, Buffer.allocUnsafe(8), 0, 8, tagsStart + 8).then((r) => r.buffer);

const targetStart = await this.getTargetStart();
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const targetPresentBuffer = await read(handle.fd, Buffer.allocUnsafe(1), 0, 1, targetStart).then((r) => r.buffer);

@@ -269,0 +268,0 @@ const targetPresent = targetPresentBuffer[0] === 1;

@@ -10,3 +10,2 @@ export * from "./signing/index";

export * from "./DataItem";
export * from "./deepHash";
export * from "./error";

@@ -16,1 +15,2 @@ export * from "./interface-jwk";

export * from "./utils";
export * from "./nodeUtils.js";

@@ -1,26 +0,1 @@

// import { bundleAndSignData, unbundleData } from "./ar-data-bundle.js";
// import Bundle from "./Bundle.js";
// import DataItem, { MIN_BINARY_SIZE } from "./DataItem.js";
// import { deepHash } from "./deepHash.js";
// import { DataItemCreateOptions } from "./ar-data-base.js";
// import { createData } from "./ar-data-create.js";
// import { ArweaveSigner } from "./signing/index.js";
// import SolanaSigner from "./signing/chains/SolanaSigner.js";
// import EthereumSigner from "./signing/chains/ethereumSigner.js";
// export {
// MIN_BINARY_SIZE,
// Bundle,
// DataItem,
// createData,
// bundleAndSignData,
// unbundleData,
// deepHash,
// DataItemCreateOptions,
// };
// const signers = {
// ArweaveSigner,
// SolanaSigner,
// EthereumSigner,
// };
// export { signers };
export * from "./signing/index.js";

@@ -35,3 +10,2 @@ export * from "./ar-data-base.js";

export * from "./DataItem.js";
export * from "./deepHash.js";
export * from "./error.js";

@@ -41,2 +15,3 @@ export * from "./interface-jwk.js";

export * from "./utils.js";
export * from "./nodeUtils.js";
//# sourceMappingURL=index.js.map

@@ -1,6 +0,10 @@

export type { CreateTransactionInterface } from "arweave/node/common";
export { stringToBuffer } from "arweave/node/lib/utils";
import nodeDriver from "arweave/node/lib/crypto/node-driver";
import type { JWKInterface } from "./interface-jwk";
export { stringToBuffer, concatBuffers } from "arweave/node/lib/utils";
export { default as Transaction } from "arweave/node/lib/transaction";
export { deepHash } from "./deepHash";
export { default as Arweave } from "arweave/node";
export { default as cryptoDriver } from "arweave/node/lib/crypto/node-driver";
export type { CreateTransactionInterface } from "arweave/node/common";
export declare class CryptoDriver extends nodeDriver {
getPublicKey(jwk: JWKInterface): string;
}
export declare function getCryptoDriver(): CryptoDriver;

@@ -1,6 +0,24 @@

export { stringToBuffer } from "arweave/node/lib/utils";
import { /* createHash, */ createPublicKey } from "crypto";
import nodeDriver from "arweave/node/lib/crypto/node-driver";
export { stringToBuffer, concatBuffers } from "arweave/node/lib/utils";
export { default as Transaction } from "arweave/node/lib/transaction";
export { deepHash } from "./deepHash.js";
export { default as Arweave } from "arweave/node";
export { default as cryptoDriver } from "arweave/node/lib/crypto/node-driver";
export class CryptoDriver extends nodeDriver {
getPublicKey(jwk) {
return createPublicKey({
key: this.jwkToPem(jwk),
type: "pkcs1",
format: "pem",
})
.export({
format: "pem",
type: "pkcs1",
})
.toString();
}
}
let d;
export function getCryptoDriver() {
return (d ??= new CryptoDriver());
}
//# sourceMappingURL=nodeUtils.js.map
import Rsa4096Pss from "../keys/Rsa4096Pss.js";
import { jwkTopem } from "arweave/node/lib/crypto/pem";
import base64url from "base64url";
import { Arweave } from "../../nodeUtils.js";
import { getCryptoDriver } from "../../nodeUtils.js";
export default class ArweaveSigner extends Rsa4096Pss {

@@ -15,8 +15,8 @@ jwk;

sign(message) {
return Arweave.crypto.sign(this.jwk, message);
return getCryptoDriver().sign(this.jwk, message);
}
static async verify(pk, message, signature) {
return await Arweave.crypto.verify(pk, message, signature);
return await getCryptoDriver().verify(pk, message, signature);
}
}
//# sourceMappingURL=ArweaveSigner.js.map

@@ -1,5 +0,5 @@

import { constants, createPublicKey, createSign } from "crypto";
import { Arweave } from "../../nodeUtils.js";
import { getCryptoDriver } from "../../nodeUtils.js";
import base64url from "base64url";
import { SIG_CONFIG } from "../../constants.js";
import { constants, createSign } from "crypto";
export default class Rsa4096Pss {

@@ -19,12 +19,3 @@ _key;

if (!pk) {
this.pk = createPublicKey({
key: _key,
type: "pkcs1",
format: "pem",
})
.export({
format: "pem",
type: "pkcs1",
})
.toString();
this.pk = getCryptoDriver().getPublicKey(JSON.parse(_key));
}

@@ -39,5 +30,5 @@ }

static async verify(pk, message, signature) {
return await Arweave.crypto.verify(Buffer.isBuffer(pk) ? base64url.encode(pk) : pk, message, signature);
return await getCryptoDriver().verify(Buffer.isBuffer(pk) ? base64url.encode(pk) : pk, message, signature);
}
}
//# sourceMappingURL=Rsa4096Pss.js.map

@@ -7,6 +7,6 @@ import { PassThrough, Transform } from "stream";

import { SIG_CONFIG } from "../constants.js";
import * as crypto from "crypto";
import { stringToBuffer } from "../nodeUtils.js";
import { deepHash } from "../deepHash.js";
import { deserializeTags } from "../tags.js";
import { createHash } from "crypto";
export default async function processStream(stream) {

@@ -110,3 +110,3 @@ const reader = getReader(stream);

// Check id
if (id !== base64url(crypto.createHash("sha256").update(signature).digest()))
if (id !== base64url(createHash("sha256").update(signature).digest()))
throw new Error("ID doesn't match signature");

@@ -113,0 +113,0 @@ const Signer = indexToType[signatureType];

@@ -0,6 +1,11 @@

import type { JWKInterface } from "./interface-jwk";
export type { default as Transaction } from "arweave/web/lib/transaction";
export type { CreateTransactionInterface } from "arweave/web/common";
export { stringToBuffer } from "arweave/web/lib/utils";
export { default as Transaction } from "arweave/web/lib/transaction";
export { default as deepHash } from "arweave/web/lib/deepHash";
export { default as Arweave } from "arweave/web";
export { default as cryptoDriver } from "arweave/web/lib/crypto/webcrypto-driver";
import webDriver from "arweave/web/lib/crypto/webcrypto-driver";
export { stringToBuffer, concatBuffers } from "arweave/web/lib/utils";
export { deepHash } from "./deepHash";
export declare class CryptoDriver extends webDriver {
protected hasSubtle: boolean;
getPublicKey(_jwk: JWKInterface): string;
}
export declare function getCryptoDriver(): CryptoDriver;

@@ -1,6 +0,16 @@

export { stringToBuffer } from "arweave/web/lib/utils";
export { default as Transaction } from "arweave/web/lib/transaction";
export { default as deepHash } from "arweave/web/lib/deepHash";
export { default as Arweave } from "arweave/web";
export { default as cryptoDriver } from "arweave/web/lib/crypto/webcrypto-driver";
// import { sha384 as SHA384 } from "sha.js";
import webDriver from "arweave/web/lib/crypto/webcrypto-driver";
export { stringToBuffer, concatBuffers } from "arweave/web/lib/utils";
export { deepHash } from "./deepHash.js";
// export { default as Arweave } from "arweave/web";
// export const sha384 = (): Hash => SHA384("sha384");
export class CryptoDriver extends webDriver {
getPublicKey(_jwk) {
throw new Error("Unimplemented");
}
}
let d;
export function getCryptoDriver() {
return (d ??= new CryptoDriver());
}
//# sourceMappingURL=webUtils.js.map

@@ -42,5 +42,2 @@ /// <reference types="node" />

DataItem: typeof arbundlesSrc.DataItem;
deepHash(data: arbundlesSrc.DeepHashChunk): Promise<Uint8Array>;
deepHashChunks(chunks: arbundlesSrc.DeepHashChunks, acc: Uint8Array): Promise<Uint8Array>;
hashStream(stream: AsyncIterable<Buffer>): Promise<Buffer>;
serializeTags(tags: {

@@ -59,4 +56,10 @@ name: string;

byteArrayToLong(byteArray: Uint8Array): number;
getCryptoDriver(): arbundlesSrc.CryptoDriver;
stringToBuffer: typeof arbundlesSrc.stringToBuffer;
concatBuffers: typeof arbundlesSrc.concatBuffers;
Transaction: typeof arbundlesSrc.Transaction;
deepHash: typeof arbundlesSrc.deepHash;
CryptoDriver: typeof arbundlesSrc.CryptoDriver;
};
export * from "./src";
export * from "./src/index";
export * from "./src/stream";

@@ -101,5 +104,2 @@ export default expObj;

DataItem: typeof arbundlesSrc.DataItem;
deepHash(data: arbundlesSrc.DeepHashChunk): Promise<Uint8Array>;
deepHashChunks(chunks: arbundlesSrc.DeepHashChunks, acc: Uint8Array): Promise<Uint8Array>;
hashStream(stream: AsyncIterable<Buffer>): Promise<Buffer>;
serializeTags(tags: {

@@ -118,2 +118,8 @@ name: string;

byteArrayToLong(byteArray: Uint8Array): number;
getCryptoDriver(): arbundlesSrc.CryptoDriver;
stringToBuffer: typeof arbundlesSrc.stringToBuffer;
concatBuffers: typeof arbundlesSrc.concatBuffers;
Transaction: typeof arbundlesSrc.Transaction;
deepHash: typeof arbundlesSrc.deepHash;
CryptoDriver: typeof arbundlesSrc.CryptoDriver;
};

@@ -1,18 +0,2 @@

// import { stringToBuffer } from "arweave/node/lib/utils";
// import type DataItem from "./src/DataItem.js";
// import { deepHash } from "./src/deepHash.js";
// import getSigData from "./src/ar-data-base.js";
// getSigData.getSignatureData = (item: DataItem): Promise<Uint8Array> => {
// return deepHash([
// stringToBuffer("dataitem"),
// stringToBuffer("1"),
// stringToBuffer(item.signatureType.toString()),
// item.rawOwner,
// item.rawTarget,
// item.rawAnchor,
// item.rawTags,
// item.rawData,
// ]);
// };
export * from "./src/index.js";
//# sourceMappingURL=index.js.map

@@ -8,5 +8,5 @@ import { byteArrayToLong } from "./utils.js";

import { SIG_CONFIG, SignatureConfig } from "./constants.js";
import * as crypto from "crypto";
import { Arweave } from "./webUtils.js";
import { getCryptoDriver } from "./webUtils.js";
import { deserializeTags } from "./tags.js";
import { createHash } from "crypto";
export const MIN_BINARY_SIZE = 80;

@@ -39,3 +39,3 @@ export class DataItem {

get rawId() {
return crypto.createHash("sha256").update(this.rawSignature).digest();
return createHash("sha256").update(this.rawSignature).digest();
}

@@ -134,3 +134,3 @@ set rawId(id) {

this.binary.set(signature, 2);
this._id = Buffer.from(await Arweave.crypto.hash(signature));
this._id = Buffer.from(await getCryptoDriver().hash(signature));
}

@@ -137,0 +137,0 @@ isSigned() {

// In TypeScript 3.7, could be written as a single type:
// `type DeepHashChunk = Uint8Array | DeepHashChunk[];`
import { Arweave } from "./webUtils.js";
import { getCryptoDriver, concatBuffers, stringToBuffer } from "./webUtils.js";
import { createHash } from "crypto";

@@ -14,14 +14,14 @@ export async function deepHash(data) {

}
const tag = Arweave.utils.concatBuffers([Arweave.utils.stringToBuffer("blob"), Arweave.utils.stringToBuffer(length.toString())]);
const taggedHash = Arweave.utils.concatBuffers([await Arweave.crypto.hash(tag, "SHA-384"), context.digest()]);
return await Arweave.crypto.hash(taggedHash, "SHA-384");
const tag = concatBuffers([stringToBuffer("blob"), stringToBuffer(length.toString())]);
const taggedHash = concatBuffers([await getCryptoDriver().hash(tag, "SHA-384"), context.digest()]);
return await getCryptoDriver().hash(taggedHash, "SHA-384");
}
else if (Array.isArray(data)) {
const tag = Arweave.utils.concatBuffers([Arweave.utils.stringToBuffer("list"), Arweave.utils.stringToBuffer(data.length.toString())]);
return await deepHashChunks(data, await Arweave.crypto.hash(tag, "SHA-384"));
const tag = concatBuffers([stringToBuffer("list"), stringToBuffer(data.length.toString())]);
return await deepHashChunks(data, await getCryptoDriver().hash(tag, "SHA-384"));
}
const _data = data;
const tag = Arweave.utils.concatBuffers([Arweave.utils.stringToBuffer("blob"), Arweave.utils.stringToBuffer(_data.byteLength.toString())]);
const taggedHash = Arweave.utils.concatBuffers([await Arweave.crypto.hash(tag, "SHA-384"), await Arweave.crypto.hash(_data, "SHA-384")]);
return await Arweave.crypto.hash(taggedHash, "SHA-384");
const tag = concatBuffers([stringToBuffer("blob"), stringToBuffer(_data.byteLength.toString())]);
const taggedHash = concatBuffers([await getCryptoDriver().hash(tag, "SHA-384"), await getCryptoDriver().hash(_data, "SHA-384")]);
return await getCryptoDriver().hash(taggedHash, "SHA-384");
}

@@ -32,4 +32,4 @@ export async function deepHashChunks(chunks, acc) {

}
const hashPair = Arweave.utils.concatBuffers([acc, await deepHash(chunks[0])]);
const newAcc = await Arweave.crypto.hash(hashPair, "SHA-384");
const hashPair = concatBuffers([acc, await deepHash(chunks[0])]);
const newAcc = await getCryptoDriver().hash(hashPair, "SHA-384");
return await deepHashChunks(chunks.slice(1), newAcc);

@@ -36,0 +36,0 @@ }

import { file } from "tmp-promise";
import * as fs from "fs";
import { longTo32ByteArray } from "../utils.js";
import FileBundle from "./FileBundle.js";
import { createWriteStream } from "fs";
export async function bundleAndSignData(dataItems, signer, dir) {
const headerFile = await file({ dir });
const headerStream = fs.createWriteStream(headerFile.path);
const headerStream = createWriteStream(headerFile.path);
const files = new Array(dataItems.length);

@@ -9,0 +9,0 @@ headerStream.write(longTo32ByteArray(dataItems.length));

import FileDataItem from "./FileDataItem.js";
import * as fs from "fs";
import { tmpName } from "tmp-promise";

@@ -8,5 +7,6 @@ import base64url from "base64url";

import { pipeline } from "stream/promises";
import { createWriteStream } from "fs";
export async function createData(data, signer, opts) {
const filename = await tmpName();
const stream = fs.createWriteStream(filename);
const stream = createWriteStream(filename);
// TODO: Add asserts

@@ -13,0 +13,0 @@ // Parse all values to a buffer and

@@ -1,2 +0,2 @@

import * as fs from "fs";
import { createReadStream, promises, read as FSRead } from "fs";
import { promisify } from "util";

@@ -7,6 +7,6 @@ import { byteArrayToLong } from "../utils.js";

import { deserializeTags } from "../tags.js";
const read = promisify(fs.read);
const fileToFd = async (f) => (typeof f === "string" ? await fs.promises.open(f, "r") : f);
const read = promisify(FSRead);
const fileToFd = async (f) => (typeof f === "string" ? await promises.open(f, "r") : f);
export async function fileToJson(filename) {
const fd = await fs.promises.open(filename, "r").then((handle) => handle.fd);
const fd = await promises.open(filename, "r").then((handle) => handle.fd);
let tagsStart = 512 + 512 + 2;

@@ -131,4 +131,4 @@ const targetPresent = await read(fd, Buffer.alloc(1), 1024, 64, null).then((value) => value.buffer[0] == 1);

export async function signedFileStream(path, signer, opts) {
return streamSigner(fs.createReadStream(path), fs.createReadStream(path), signer, opts);
return streamSigner(createReadStream(path), createReadStream(path), signer, opts);
}
//# sourceMappingURL=file.js.map
import FileDataItem from "./FileDataItem.js";
import * as fs from "fs";
import { createReadStream, promises } from "fs";
import { byteArrayToLong } from "../utils.js";
import { read as FSRead } from "fs";
import MultiStream from "multistream";

@@ -12,3 +13,3 @@ import { promisify } from "util";

// import { pipeline } from 'stream/promises';
const read = promisify(fs.read);
const read = promisify(FSRead);
export class FileBundle {

@@ -22,7 +23,7 @@ headerFile;

static async fromDir(dir) {
const txs = await fs.promises.readdir(dir).then((r) => r.filter(async (f) => !(await fs.promises.stat(f).then((s) => s.isDirectory()))));
const txs = await promises.readdir(dir).then((r) => r.filter(async (f) => !(await promises.stat(f).then((s) => s.isDirectory()))));
return new FileBundle(dir + "/header", txs);
}
async length() {
const handle = await fs.promises.open(this.headerFile, "r");
const handle = await promises.open(this.headerFile, "r");
const lengthBuffer = await read(handle.fd, Buffer.allocUnsafe(32), 0, 32, 0).then((r) => r.buffer);

@@ -56,3 +57,3 @@ await handle.close();

async getRaw() {
const streams = [fs.createReadStream(this.headerFile), ...this.txs.map((t) => fs.createReadStream(t))];
const streams = [createReadStream(this.headerFile), ...this.txs.map((t) => createReadStream(t))];
const stream = MultiStream.obj(streams);

@@ -66,3 +67,3 @@ let buff = Buffer.allocUnsafe(0);

async toTransaction(attributes, arweave, jwk) {
const streams = [fs.createReadStream(this.headerFile), ...this.txs.map((t) => fs.createReadStream(t))];
const streams = [createReadStream(this.headerFile), ...this.txs.map((t) => createReadStream(t))];
const stream = MultiStream.obj(streams);

@@ -82,3 +83,3 @@ const tx = await pipeline(stream, createTransactionAsync(attributes, arweave, jwk));

await arweave.transactions.sign(tx, jwk);
const streams2 = [fs.createReadStream(this.headerFile), ...this.txs.map((t) => fs.createReadStream(t))];
const streams2 = [createReadStream(this.headerFile), ...this.txs.map((t) => createReadStream(t))];
const stream2 = MultiStream.obj(streams2);

@@ -89,3 +90,3 @@ await pipeline(stream2, uploadTransactionAsync(tx, arweave, true));

async *getHeaders() {
const handle = await fs.promises.open(this.headerFile, "r");
const handle = await promises.open(this.headerFile, "r");
for (let i = 32; i < 32 + 64 * (await this.length()); i += 64) {

@@ -92,0 +93,0 @@ yield {

import base64url from "base64url";
import * as fs from "fs";
import { createReadStream, promises, read as FSRead, write as FSWrite } from "fs";
import { byteArrayToLong } from "../utils.js";
import { deepHash } from "..";
import { stringToBuffer } from "../webUtils.js";
import { Arweave } from "../webUtils.js";
import { getCryptoDriver, stringToBuffer } from "../webUtils.js";
import { indexToType } from "../signing/index.js";

@@ -12,4 +11,4 @@ import axios from "axios";

import { deserializeTags } from "../tags.js";
const read = promisify(fs.read);
const write = promisify(fs.write);
const read = promisify(FSRead);
const write = promisify(FSWrite);
export class FileDataItem {

@@ -50,3 +49,3 @@ filename;

static async verify(filename) {
const handle = await fs.promises.open(filename, "r");
const handle = await promises.open(filename, "r");
const item = new FileDataItem(filename);

@@ -81,3 +80,3 @@ const sigType = await item.signatureType();

await item.rawTags(),
fs.createReadStream(filename, {
createReadStream(filename, {
start: await item.dataStart(),

@@ -101,6 +100,6 @@ }),

async size() {
return await fs.promises.stat(this.filename).then((r) => r.size);
return await promises.stat(this.filename).then((r) => r.size);
}
async signatureType() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const buffer = await read(handle.fd, Buffer.allocUnsafe(2), 0, 2, 0).then((r) => r.buffer);

@@ -111,3 +110,3 @@ await handle.close();

async rawSignature() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const length = await this.signatureLength();

@@ -122,3 +121,3 @@ const buffer = await read(handle.fd, Buffer.alloc(length), 0, length, 2).then((r) => r.buffer);

async rawOwner() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const length = await this.ownerLength();

@@ -133,3 +132,3 @@ const buffer = await read(handle.fd, Buffer.allocUnsafe(length), 0, length, 2 + (await this.signatureLength())).then((r) => r.buffer);

async rawTarget() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const targetStart = await this.getTargetStart();

@@ -155,3 +154,3 @@ const targetPresentBuffer = await read(handle.fd, Buffer.allocUnsafe(1), 0, 1, targetStart).then((r) => r.buffer);

if (anchorPresent) {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const anchorBuffer = await read(handle.fd, Buffer.allocUnsafe(32), 0, 32, anchorStart + 1).then((r) => r.buffer);

@@ -167,3 +166,3 @@ await handle.close();

async rawTags() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const tagsStart = await this.getTagsStart();

@@ -199,3 +198,3 @@ const numberOfTagsBuffer = await read(handle.fd, Buffer.allocUnsafe(8), 0, 8, tagsStart).then((r) => r.buffer);

}
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const dataBuffer = await read(handle.fd, Buffer.allocUnsafe(dataSize), 0, dataSize, dataStart).then((r) => r.buffer);

@@ -218,7 +217,7 @@ await handle.close();

await this.rawTags(),
fs.createReadStream(this.filename, { start: dataStart }),
createReadStream(this.filename, { start: dataStart }),
]);
const signatureBytes = await signer.sign(signatureData);
const idBytes = await Arweave.crypto.hash(signatureBytes);
const handle = await fs.promises.open(this.filename, "r+");
const idBytes = await getCryptoDriver().hash(signatureBytes);
const handle = await promises.open(this.filename, "r+");
await write(handle.fd, signatureBytes, 0, await this.signatureLength(), 2);

@@ -238,3 +237,3 @@ this.rawId = Buffer.from(idBytes);

throw new Error("You must sign before sending to bundler");
const response = await axios.post(`${bundler}/tx`, fs.createReadStream(this.filename), {
const response = await axios.post(`${bundler}/tx`, createReadStream(this.filename), {
headers,

@@ -256,3 +255,3 @@ timeout: 100000,

async dataStart() {
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const tagsStart = await this.getTagsStart();

@@ -266,3 +265,3 @@ const numberOfTagsBytesBuffer = await read(handle.fd, Buffer.allocUnsafe(8), 0, 8, tagsStart + 8).then((r) => r.buffer);

const targetStart = await this.getTargetStart();
const handle = await fs.promises.open(this.filename, "r");
const handle = await promises.open(this.filename, "r");
const targetPresentBuffer = await read(handle.fd, Buffer.allocUnsafe(1), 0, 1, targetStart).then((r) => r.buffer);

@@ -269,0 +268,0 @@ const targetPresent = targetPresentBuffer[0] === 1;

@@ -10,3 +10,2 @@ export * from "./signing/index";

export * from "./DataItem";
export * from "./deepHash";
export * from "./error";

@@ -16,1 +15,2 @@ export * from "./interface-jwk";

export * from "./utils";
export * from "./webUtils.js";

@@ -1,26 +0,1 @@

// import { bundleAndSignData, unbundleData } from "./ar-data-bundle.js";
// import Bundle from "./Bundle.js";
// import DataItem, { MIN_BINARY_SIZE } from "./DataItem.js";
// import { deepHash } from "./deepHash.js";
// import { DataItemCreateOptions } from "./ar-data-base.js";
// import { createData } from "./ar-data-create.js";
// import { ArweaveSigner } from "./signing/index.js";
// import SolanaSigner from "./signing/chains/SolanaSigner.js";
// import EthereumSigner from "./signing/chains/ethereumSigner.js";
// export {
// MIN_BINARY_SIZE,
// Bundle,
// DataItem,
// createData,
// bundleAndSignData,
// unbundleData,
// deepHash,
// DataItemCreateOptions,
// };
// const signers = {
// ArweaveSigner,
// SolanaSigner,
// EthereumSigner,
// };
// export { signers };
export * from "./signing/index.js";

@@ -35,3 +10,2 @@ export * from "./ar-data-base.js";

export * from "./DataItem.js";
export * from "./deepHash.js";
export * from "./error.js";

@@ -41,2 +15,3 @@ export * from "./interface-jwk.js";

export * from "./utils.js";
export * from "./webUtils.js";
//# sourceMappingURL=index.js.map
import Rsa4096Pss from "../keys/Rsa4096Pss.js";
import { jwkTopem } from "arweave/node/lib/crypto/pem";
import base64url from "base64url";
import { Arweave } from "../../webUtils.js";
import { getCryptoDriver } from "../../webUtils.js";
export default class ArweaveSigner extends Rsa4096Pss {

@@ -15,8 +15,8 @@ jwk;

sign(message) {
return Arweave.crypto.sign(this.jwk, message);
return getCryptoDriver().sign(this.jwk, message);
}
static async verify(pk, message, signature) {
return await Arweave.crypto.verify(pk, message, signature);
return await getCryptoDriver().verify(pk, message, signature);
}
}
//# sourceMappingURL=ArweaveSigner.js.map

@@ -1,5 +0,5 @@

import { constants, createPublicKey, createSign } from "crypto";
import { Arweave } from "../../webUtils.js";
import { getCryptoDriver } from "../../webUtils.js";
import base64url from "base64url";
import { SIG_CONFIG } from "../../constants.js";
import { constants, createSign } from "crypto";
export default class Rsa4096Pss {

@@ -19,12 +19,3 @@ _key;

if (!pk) {
this.pk = createPublicKey({
key: _key,
type: "pkcs1",
format: "pem",
})
.export({
format: "pem",
type: "pkcs1",
})
.toString();
this.pk = getCryptoDriver().getPublicKey(JSON.parse(_key));
}

@@ -39,5 +30,5 @@ }

static async verify(pk, message, signature) {
return await Arweave.crypto.verify(Buffer.isBuffer(pk) ? base64url.encode(pk) : pk, message, signature);
return await getCryptoDriver().verify(Buffer.isBuffer(pk) ? base64url.encode(pk) : pk, message, signature);
}
}
//# sourceMappingURL=Rsa4096Pss.js.map

@@ -7,6 +7,6 @@ import { PassThrough, Transform } from "stream";

import { SIG_CONFIG } from "../constants.js";
import * as crypto from "crypto";
import { stringToBuffer } from "../webUtils.js";
import { deepHash } from "../deepHash.js";
import { deserializeTags } from "../tags.js";
import { createHash } from "crypto";
export default async function processStream(stream) {

@@ -110,3 +110,3 @@ const reader = getReader(stream);

// Check id
if (id !== base64url(crypto.createHash("sha256").update(signature).digest()))
if (id !== base64url(createHash("sha256").update(signature).digest()))
throw new Error("ID doesn't match signature");

@@ -113,0 +113,0 @@ const Signer = indexToType[signatureType];

@@ -0,6 +1,11 @@

import type { JWKInterface } from "./interface-jwk";
export type { default as Transaction } from "arweave/web/lib/transaction";
export type { CreateTransactionInterface } from "arweave/web/common";
export { stringToBuffer } from "arweave/web/lib/utils";
export { default as Transaction } from "arweave/web/lib/transaction";
export { default as deepHash } from "arweave/web/lib/deepHash";
export { default as Arweave } from "arweave/web";
export { default as cryptoDriver } from "arweave/web/lib/crypto/webcrypto-driver";
import webDriver from "arweave/web/lib/crypto/webcrypto-driver";
export { stringToBuffer, concatBuffers } from "arweave/web/lib/utils";
export { deepHash } from "./deepHash";
export declare class CryptoDriver extends webDriver {
protected hasSubtle: boolean;
getPublicKey(_jwk: JWKInterface): string;
}
export declare function getCryptoDriver(): CryptoDriver;

@@ -1,6 +0,16 @@

export { stringToBuffer } from "arweave/web/lib/utils";
export { default as Transaction } from "arweave/web/lib/transaction";
export { default as deepHash } from "arweave/web/lib/deepHash";
export { default as Arweave } from "arweave/web";
export { default as cryptoDriver } from "arweave/web/lib/crypto/webcrypto-driver";
// import { sha384 as SHA384 } from "sha.js";
import webDriver from "arweave/web/lib/crypto/webcrypto-driver";
export { stringToBuffer, concatBuffers } from "arweave/web/lib/utils";
export { deepHash } from "./deepHash.js";
// export { default as Arweave } from "arweave/web";
// export const sha384 = (): Hash => SHA384("sha384");
export class CryptoDriver extends webDriver {
getPublicKey(_jwk) {
throw new Error("Unimplemented");
}
}
let d;
export function getCryptoDriver() {
return (d ??= new CryptoDriver());
}
//# sourceMappingURL=webUtils.js.map

@@ -42,5 +42,2 @@ /// <reference types="node" />

DataItem: typeof arbundlesSrc.DataItem;
deepHash(data: arbundlesSrc.DeepHashChunk): Promise<Uint8Array>;
deepHashChunks(chunks: arbundlesSrc.DeepHashChunks, acc: Uint8Array): Promise<Uint8Array>;
hashStream(stream: AsyncIterable<Buffer>): Promise<Buffer>;
serializeTags(tags: {

@@ -59,4 +56,9 @@ name: string;

byteArrayToLong(byteArray: Uint8Array): number;
getCryptoDriver(): arbundlesSrc.CryptoDriver;
stringToBuffer: typeof arbundlesSrc.stringToBuffer;
concatBuffers: typeof arbundlesSrc.concatBuffers;
deepHash: typeof arbundlesSrc.deepHash;
CryptoDriver: typeof arbundlesSrc.CryptoDriver;
};
export * from "./src";
export * from "./src/index";
export * from "./src/stream";

@@ -101,5 +103,2 @@ export default expObj;

DataItem: typeof arbundlesSrc.DataItem;
deepHash(data: arbundlesSrc.DeepHashChunk): Promise<Uint8Array>;
deepHashChunks(chunks: arbundlesSrc.DeepHashChunks, acc: Uint8Array): Promise<Uint8Array>;
hashStream(stream: AsyncIterable<Buffer>): Promise<Buffer>;
serializeTags(tags: {

@@ -118,2 +117,7 @@ name: string;

byteArrayToLong(byteArray: Uint8Array): number;
getCryptoDriver(): arbundlesSrc.CryptoDriver;
stringToBuffer: typeof arbundlesSrc.stringToBuffer;
concatBuffers: typeof arbundlesSrc.concatBuffers;
deepHash: typeof arbundlesSrc.deepHash;
CryptoDriver: typeof arbundlesSrc.CryptoDriver;
};
{
"name": "arbundles",
"version": "0.9.0-a1",
"version": "0.9.0-a2",
"description": "Arweave bundling library",

@@ -15,7 +15,8 @@ "author": "Josh Benaron <joshbenaron@gmail.com>",

"require": "./build/node/cjs/index.js",
"node": "./build/node/cjs/src/index.js"
"node": "./build/node/cjs/index.js",
"browser": "./build/web/esm/webIndex.js"
},
"./file": {
"types": "./build/node/esm/src/file/index.d.ts",
"import": "./build/node/esm/src/ile/index.js",
"import": "./build/node/esm/src/file/index.js",
"require": "./build/node/cjs/src/file/index.js",

@@ -30,2 +31,8 @@ "node": "./build/node/cjs/src/file/index.js"

},
"./node": {
"types": "./build/node/esm/index.d.ts",
"import": "./build/node/esm/index.js",
"require": "./build/node/cjs/index.js",
"node": "./build/node/cjs/index.js"
},
"./web": {

@@ -41,4 +48,4 @@ "types": "./build/web/esm/webIndex.d.ts",

"./*": {
"default": "./build/*.js",
"types": "./build/*.d.ts"
"types": "./build/*.d.ts",
"default": "./build/*.js"
}

@@ -45,0 +52,0 @@ },

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

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

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

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 too big to display

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc