Socket
Socket
Sign inDemoInstall

arbundles

Package Overview
Dependencies
Maintainers
1
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.1.0 to 0.1.1

build/constants.d.ts

12

build/DataItem.d.ts
/// <reference types="node" />
import { Buffer } from 'buffer';
import { BundleItem } from './BundleItem';
import { Signer } from './signing/index';
import { Buffer } from "buffer";
import { BundleItem } from "./BundleItem";
import { Signer } from "./signing/index";
import { AxiosResponse } from "axios";
export declare const MIN_BINARY_SIZE = 1044;

@@ -50,5 +51,4 @@ export default class DataItem implements BundleItem {

};
static verify(buffer: Buffer, extras?: {
pk: string | Buffer;
}): Promise<boolean>;
sendToBundler(): Promise<AxiosResponse>;
static verify(buffer: Buffer): Promise<boolean>;
private getTagsStart;

@@ -55,0 +55,0 @@ private getTargetStart;

@@ -12,2 +12,4 @@ "use strict";

const ar_data_base_1 = require("./ar-data-base");
const axios_1 = tslib_1.__importDefault(require("axios"));
const constants_1 = require("./constants");
exports.MIN_BINARY_SIZE = 1044;

@@ -37,2 +39,5 @@ class DataItem {

get rawId() {
if (!this._id) {
throw new Error("To get the data item id you must sign the item first");
}
return this._id;

@@ -124,3 +129,15 @@ }

}
static async verify(buffer, extras) {
async sendToBundler() {
const headers = {
"Content-Type": "application/octet-stream"
};
if (!this.isSigned())
throw new Error("You must sign before sending to bundler");
return await axios_1.default.post(`${constants_1.BUNDLER}/tx`, this.getRaw(), {
headers,
timeout: 200000,
maxBodyLength: Infinity,
});
}
static async verify(buffer) {
if (buffer.length < exports.MIN_BINARY_SIZE) {

@@ -150,9 +167,6 @@ return false;

}
if (extras) {
const Signer = index_1.indexToType[sigType];
const signatureData = await ar_data_base_1.getSignatureData(new DataItem(buffer));
if (!await Signer.verify(extras.pk, signatureData, buffer.subarray(2, 514)))
return false;
}
return true;
const Signer = index_1.indexToType[sigType];
const item = new DataItem(buffer);
const signatureData = await ar_data_base_1.getSignatureData(item);
return await Signer.verify(item.owner, signatureData, buffer.subarray(2, 514));
}

@@ -159,0 +173,0 @@ getTagsStart() {

@@ -22,5 +22,12 @@ "use strict";

}
return Uint8Array.from(exports.tagsParser.toBuffer(tags));
let tagsBuffer;
try {
tagsBuffer = exports.tagsParser.toBuffer(tags);
}
catch (e) {
throw new Error("Incorrect tag format used. Make sure your tags are { name: string!, name: string! }[]");
}
return Uint8Array.from(tagsBuffer);
}
exports.serializeTags = serializeTags;
//# sourceMappingURL=parser.js.map

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

import { Signer } from '../build/signing';
import { Buffer } from 'buffer';
export default class FileDataItem implements BundleItem {

@@ -8,0 +7,0 @@ readonly filename: PathLike;

@@ -13,3 +13,2 @@ "use strict";

const signing_1 = require("../build/signing");
const buffer_1 = require("buffer");
const write = util_1.promisify(fs.write);

@@ -41,6 +40,6 @@ const read = util_1.promisify(fs.read);

const handle = await fs.promises.open(filename, 'r');
const sigType = await read(handle.fd, buffer_1.Buffer.allocUnsafe(2), 0, 2, 0)
const sigType = await read(handle.fd, Buffer.allocUnsafe(2), 0, 2, 0)
.then(r => utils_1.byteArrayToLong(r.buffer));
let anchorStart = 1027;
const targetPresentBuffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(1), 0, 1, 1026)
const targetPresentBuffer = await read(handle.fd, Buffer.allocUnsafe(1), 0, 1, 1026)
.then(r => r.buffer);

@@ -51,12 +50,15 @@ const targetPresent = targetPresentBuffer[0] === 1;

}
const anchorPresentBuffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(1), 0, 1, anchorStart)
const anchorPresentBuffer = await read(handle.fd, Buffer.allocUnsafe(1), 0, 1, anchorStart)
.then(r => r.buffer);
const anchorPresent = anchorPresentBuffer[0] === 1;
let tagsStart = anchorStart;
tagsStart += anchorPresent ? 32 : 1;
const numberOfTags = await read(handle.fd, buffer_1.Buffer.allocUnsafe(8), 0, 8, tagsStart)
if (anchorPresent) {
tagsStart += 32;
}
tagsStart++;
const numberOfTags = await read(handle.fd, Buffer.allocUnsafe(8), 0, 8, tagsStart)
.then(r => utils_1.byteArrayToLong(r.buffer));
const numberOfTagsBytes = await read(handle.fd, buffer_1.Buffer.allocUnsafe(8), 0, 8, tagsStart + 8)
const numberOfTagsBytes = await read(handle.fd, Buffer.allocUnsafe(8), 0, 8, tagsStart + 8)
.then(r => utils_1.byteArrayToLong(r.buffer));
const tagsBytes = await read(handle.fd, buffer_1.Buffer.allocUnsafe(numberOfTagsBytes), 0, numberOfTagsBytes, tagsStart + 16)
const tagsBytes = await read(handle.fd, Buffer.allocUnsafe(numberOfTagsBytes), 0, numberOfTagsBytes, tagsStart + 16)
.then(r => r.buffer);

@@ -73,8 +75,8 @@ if (numberOfTags > 0) {

const Signer = signing_1.indexToType[sigType];
const owner = await read(handle.fd, buffer_1.Buffer.allocUnsafe(512), 0, 512, 514)
const owner = await read(handle.fd, Buffer.allocUnsafe(512), 0, 512, 514)
.then(r => r.buffer);
const target = targetPresent ? await read(handle.fd, buffer_1.Buffer.allocUnsafe(32), 0, 32, 1027)
.then(r => r.buffer) : buffer_1.Buffer.allocUnsafe(0);
const anchor = anchorPresent ? await read(handle.fd, buffer_1.Buffer.allocUnsafe(32), 0, 32, anchorStart + 1)
.then(r => r.buffer) : buffer_1.Buffer.allocUnsafe(0);
const target = targetPresent ? await read(handle.fd, Buffer.allocUnsafe(32), 0, 32, 1027)
.then(r => r.buffer) : Buffer.allocUnsafe(0);
const anchor = anchorPresent ? await read(handle.fd, Buffer.allocUnsafe(32), 0, 32, anchorStart + 1)
.then(r => r.buffer) : Buffer.allocUnsafe(0);
const signatureData = await index_1.deepHash([

@@ -90,3 +92,3 @@ utils_2.stringToBuffer('dataitem'),

]);
const signature = await read(handle.fd, buffer_1.Buffer.allocUnsafe(512), 0, 512, 2)
const signature = await read(handle.fd, Buffer.allocUnsafe(512), 0, 512, 2)
.then(r => r.buffer);

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

const handle = await fs.promises.open(this.filename, 'r');
const buffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(2), 0, 2, 0)
const buffer = await read(handle.fd, Buffer.allocUnsafe(2), 0, 2, 0)
.then(r => r.buffer);

@@ -118,3 +120,3 @@ await handle.close();

const handle = await fs.promises.open(this.filename, 'r');
const buffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(512), 0, 512, 2)
const buffer = await read(handle.fd, Buffer.allocUnsafe(512), 0, 512, 2)
.then(r => r.buffer);

@@ -129,3 +131,3 @@ await handle.close();

const handle = await fs.promises.open(this.filename, 'r');
const buffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(512), 0, 512, 514)
const buffer = await read(handle.fd, Buffer.allocUnsafe(512), 0, 512, 514)
.then(r => r.buffer);

@@ -140,7 +142,7 @@ await handle.close();

const handle = await fs.promises.open(this.filename, 'r');
const targetPresentBuffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(1), 0, 1, 1026)
const targetPresentBuffer = await read(handle.fd, Buffer.allocUnsafe(1), 0, 1, 1026)
.then(r => r.buffer);
const targetPresent = targetPresentBuffer[0] === 1;
if (targetPresent) {
const targetBuffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(32), 0, 32, 1027)
const targetBuffer = await read(handle.fd, Buffer.allocUnsafe(32), 0, 32, 1027)
.then(r => r.buffer);

@@ -151,3 +153,3 @@ await handle.close();

await handle.close();
return buffer_1.Buffer.allocUnsafe(0);
return Buffer.allocUnsafe(0);
}

@@ -160,3 +162,3 @@ async target() {

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

@@ -167,7 +169,7 @@ const targetPresent = targetPresentBuffer[0] === 1;

}
const anchorPresentBuffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(1), 0, 1, anchorStart)
const anchorPresentBuffer = await read(handle.fd, Buffer.allocUnsafe(1), 0, 1, anchorStart)
.then(r => r.buffer);
const anchorPresent = anchorPresentBuffer[0] === 1;
if (anchorPresent) {
const anchorBuffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(32), 0, 32, anchorStart + 1)
const anchorBuffer = await read(handle.fd, Buffer.allocUnsafe(32), 0, 32, anchorStart + 1)
.then(r => r.buffer);

@@ -178,3 +180,3 @@ await handle.close();

await handle.close();
return buffer_1.Buffer.allocUnsafe(0);
return Buffer.allocUnsafe(0);
}

@@ -187,11 +189,11 @@ async anchor() {

const tagsStart = await this.tagsStart();
const numberOfTagsBuffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(8), 0, 8, tagsStart)
const numberOfTagsBuffer = await read(handle.fd, Buffer.allocUnsafe(8), 0, 8, tagsStart)
.then(r => r.buffer);
const numberOfTags = utils_1.byteArrayToLong(numberOfTagsBuffer);
if (numberOfTags === 0)
return buffer_1.Buffer.allocUnsafe(0);
const numberOfTagsBytesBuffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(8), 0, 8, tagsStart + 8)
return Buffer.allocUnsafe(0);
const numberOfTagsBytesBuffer = await read(handle.fd, Buffer.allocUnsafe(8), 0, 8, tagsStart + 8)
.then(r => r.buffer);
const numberOfTagsBytes = utils_1.byteArrayToLong(numberOfTagsBytesBuffer);
const tagsBytes = await read(handle.fd, buffer_1.Buffer.allocUnsafe(numberOfTagsBytes), 0, numberOfTagsBytes, tagsStart + 16)
const tagsBytes = await read(handle.fd, Buffer.allocUnsafe(numberOfTagsBytes), 0, numberOfTagsBytes, tagsStart + 16)
.then(r => r.buffer);

@@ -210,3 +212,3 @@ await handle.close();

const tagsStart = await this.tagsStart();
const numberOfTagsBytesBuffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(8), 0, 8, tagsStart + 8)
const numberOfTagsBytesBuffer = await read(handle.fd, Buffer.allocUnsafe(8), 0, 8, tagsStart + 8)
.then(r => r.buffer);

@@ -219,5 +221,5 @@ const numberOfTagsBytes = utils_1.byteArrayToLong(numberOfTagsBytesBuffer);

await handle.close();
return buffer_1.Buffer.allocUnsafe(0);
return Buffer.allocUnsafe(0);
}
const dataBuffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(dataSize), 0, dataSize, dataStart)
const dataBuffer = await read(handle.fd, Buffer.allocUnsafe(dataSize), 0, dataSize, dataStart)
.then(r => r.buffer);

@@ -233,2 +235,11 @@ await handle.close();

const end = await this.size();
console.log(base64url_1.default(Buffer.concat([
utils_2.stringToBuffer('dataitem'),
utils_2.stringToBuffer('1'),
utils_2.stringToBuffer(await this.signatureType().then(n => n.toString())),
await this.rawOwner(),
await this.rawTarget(),
await this.rawAnchor(),
await this.rawTags()
])));
const signatureData = await index_1.deepHash([

@@ -248,5 +259,5 @@ utils_2.stringToBuffer('dataitem'),

await write(handle.fd, signatureBytes, 0, 512, 2);
this.rawId = buffer_1.Buffer.from(idBytes);
this.rawId = Buffer.from(idBytes);
await handle.close();
return buffer_1.Buffer.from(idBytes);
return Buffer.from(idBytes);
}

@@ -256,3 +267,3 @@ async anchorStart() {

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

@@ -263,3 +274,3 @@ const targetPresent = targetPresentBuffer[0] === 1;

}
const anchorPresentBuffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(1), 0, 1, anchorStart)
const anchorPresentBuffer = await read(handle.fd, Buffer.allocUnsafe(1), 0, 1, anchorStart)
.then(r => r.buffer);

@@ -279,3 +290,3 @@ const anchorPresent = anchorPresentBuffer[0] === 1;

const tagsStart = await this.tagsStart();
const numberOfTagsBytesBuffer = await read(handle.fd, buffer_1.Buffer.allocUnsafe(8), 0, 8, tagsStart + 8)
const numberOfTagsBytesBuffer = await read(handle.fd, Buffer.allocUnsafe(8), 0, 8, tagsStart + 8)
.then(r => r.buffer);

@@ -282,0 +293,0 @@ const numberOfTagsBytes = utils_1.byteArrayToLong(numberOfTagsBytesBuffer);

{
"name": "arbundles",
"version": "0.1.0",
"version": "0.1.1",
"description": "Arweave bundling library",

@@ -48,2 +48,3 @@ "main": "build/index.js",

"@akiroz/size-chunker-stream": "^0.0.1",
"@types/axios": "^0.14.0",
"@types/browser-or-node": "^1.3.0",

@@ -55,2 +56,3 @@ "@types/multistream": "^2.1.1",

"avsc": "^5.7.1",
"axios": "^0.21.3",
"base64url": "^3.0.1",

@@ -57,0 +59,0 @@ "combined-stream2": "^1.1.2",

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