Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

arweave

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arweave - npm Package Compare versions

Comparing version 1.8.0 to 1.9.0

LICENSE.md

4

node/chunks.d.ts

@@ -14,5 +14,7 @@ import Api from "./lib/api";

constructor(api: Api);
getTransactionOffset(tx: string): Promise<TransactionOffsetResponse>;
getTransactionOffset(id: string): Promise<TransactionOffsetResponse>;
getChunk(offset: string | number | BigInt): Promise<TransactionChunkResponse>;
getChunkData(offset: string | number | BigInt): Promise<Uint8Array>;
firstChunkOffset(offsetResponse: TransactionOffsetResponse): number;
downloadChunkedData(id: string): Promise<Uint8Array>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const error_1 = require("./lib/error");
const ArweaveUtils = require("./lib/utils");
class Chunks {

@@ -8,4 +9,4 @@ constructor(api) {

}
async getTransactionOffset(tx) {
const resp = await this.api.request().get(`/tx/${tx}/offset`);
async getTransactionOffset(id) {
const resp = await this.api.get(`tx/${id}/offset`);
if (resp.status === 200) {

@@ -17,3 +18,3 @@ return resp.data;

async getChunk(offset) {
const resp = await this.api.request().get(`/chunk/${offset}`);
const resp = await this.api.get(`chunk/${offset}`);
if (resp.status === 200) {

@@ -24,7 +25,26 @@ return resp.data;

}
async getChunkData(offset) {
const chunk = await this.getChunk(offset);
const buf = ArweaveUtils.b64UrlToBuffer(chunk.chunk);
return buf;
}
firstChunkOffset(offsetResponse) {
return parseInt(offsetResponse.offset) - parseInt(offsetResponse.size) + 1;
}
async downloadChunkedData(id) {
const offsetResponse = await this.getTransactionOffset(id);
const size = parseInt(offsetResponse.size);
const endOffset = parseInt(offsetResponse.offset);
const startOffset = endOffset - size + 1;
const data = new Uint8Array(size);
let byte = 0;
while (startOffset + byte < endOffset) {
const chunkData = await this.getChunkData(startOffset + byte);
data.set(chunkData, byte);
byte += chunkData.length;
}
return data;
}
}
exports.default = Chunks;
//# sourceMappingURL=chunks.js.map

@@ -41,5 +41,5 @@ import Ar from "./ar";

/** @deprecated */
readonly crypto: CryptoInterface;
get crypto(): CryptoInterface;
/** @deprecated */
readonly utils: typeof ArweaveUtils;
get utils(): typeof ArweaveUtils;
getConfig(): Config;

@@ -46,0 +46,0 @@ createTransaction(attributes: Partial<CreateTransactionInterface>, jwk: JWKInterface): Promise<Transaction>;

@@ -16,7 +16,7 @@ "use strict";

this.wallets = new wallets_1.default(this.api, Arweave.crypto);
this.transactions = new transactions_1.default(this.api, Arweave.crypto);
this.chunks = new chunks_1.default(this.api);
this.transactions = new transactions_1.default(this.api, Arweave.crypto, this.chunks);
this.silo = new silo_1.default(this.api, this.crypto, this.transactions);
this.network = new network_1.default(this.api);
this.ar = new ar_1.default();
this.chunks = new chunks_1.default(this.api);
}

@@ -107,4 +107,4 @@ /** @deprecated */

}
exports.default = Arweave;
Arweave.utils = ArweaveUtils;
exports.default = Arweave;
//# sourceMappingURL=common.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.jwkTopem = exports.pemTojwk = void 0;
// @ts-ignore

@@ -4,0 +5,0 @@ const asn = require("arweave-asn1");

@@ -24,3 +24,3 @@ import { AxiosResponse } from "axios";

};
export declare const getError: (resp: AxiosResponseLite) => any;
export declare function getError(resp: AxiosResponseLite): any;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getError = void 0;
class ArweaveError extends Error {

@@ -22,6 +23,27 @@ constructor(type, optional = {}) {

// resp.data, statusText or 'unknown'.
exports.getError = (resp) => resp.data ?
(resp.data.error || resp.data)
:
(resp.statusText || 'unknown');
// Note: a wrongly set content-type can
// cause what is a json response to be interepted
// as a string or Buffer, so we handle that too.
function getError(resp) {
let data = resp.data;
if (typeof resp.data === 'string') {
try {
data = JSON.parse(resp.data);
}
catch (e) {
}
}
if (resp.data instanceof ArrayBuffer || resp.data instanceof Uint8Array) {
try {
data = JSON.parse(data.toString());
}
catch (e) {
}
}
return data ?
(data.error || data)
:
(resp.statusText || 'unknown');
}
exports.getError = getError;
//# sourceMappingURL=error.js.map

@@ -70,3 +70,3 @@ export interface Chunk {

export declare function bufferToInt(buffer: Uint8Array): number;
export declare const arrayCompare: (a: any[] | Uint8Array, b: any[] | Uint8Array) => boolean;
export declare const arrayCompare: (a: Uint8Array | any[], b: Uint8Array | any[]) => boolean;
export declare function validatePath(id: Uint8Array, dest: number, leftBound: number, rightBound: number, path: Uint8Array): Promise<false | {

@@ -73,0 +73,0 @@ offset: number;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.debug = exports.validatePath = exports.arrayCompare = exports.bufferToInt = exports.intToBuffer = exports.arrayFlatten = exports.generateProofs = exports.buildLayers = exports.generateTransactionChunks = exports.generateTree = exports.computeRootHash = exports.generateLeaves = exports.chunkData = exports.MIN_CHUNK_SIZE = exports.MAX_CHUNK_SIZE = void 0;
/**

@@ -4,0 +5,0 @@ * @see {@link https://github.com/ArweaveTeam/arweave/blob/fbc381e0e36efffa45d13f2faa6199d3766edaa2/apps/arweave/src/ar_merkle.erl}

@@ -21,6 +21,6 @@ import Transaction from './transaction';

lastResponseError: string;
readonly isComplete: boolean;
readonly totalChunks: number;
readonly uploadedChunks: number;
readonly pctComplete: number;
get isComplete(): boolean;
get totalChunks(): number;
get uploadedChunks(): number;
get pctComplete(): number;
constructor(api: Api, transaction: Transaction);

@@ -27,0 +27,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionUploader = void 0;
const transaction_1 = require("./transaction");

@@ -31,2 +32,5 @@ const ArweaveUtils = require("./utils");

}
if (!transaction.chunks) {
throw new Error(`Transaction chunks not prepared`);
}
// Make a copy of transaction, zeroing the data so we can serialize.

@@ -33,0 +37,0 @@ this.data = transaction.data;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tag = void 0;
const ArweaveUtils = require("./utils");

@@ -4,0 +5,0 @@ const deepHash_1 = require("./deepHash");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.b64UrlDecode = exports.b64UrlEncode = exports.bufferTob64Url = exports.bufferTob64 = exports.b64UrlToBuffer = exports.stringToB64Url = exports.stringToBuffer = exports.bufferToString = exports.b64UrlToString = exports.concatBuffers = void 0;
const B64js = require("base64-js");

@@ -4,0 +5,0 @@ function concatBuffers(buffers) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SiloResource = void 0;
const ArweaveUtils = require("./lib/utils");

@@ -4,0 +5,0 @@ class Silo {

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

import { TransactionUploader, SerializedUploader } from "./lib/transaction-uploader";
import Chunks from "./chunks";
export interface TransactionConfirmedData {

@@ -20,3 +21,4 @@ block_indep_hash: string;

private crypto;
constructor(api: Api, crypto: CryptoInterface);
private chunks;
constructor(api: Api, crypto: CryptoInterface, chunks: Chunks);
getTransactionAnchor(): Promise<string>;

@@ -71,3 +73,3 @@ getPrice(byteSize: number, targetAddress?: string): Promise<string>;

*/
upload(upload: Transaction | SerializedUploader | string, data?: Uint8Array): AsyncIterableIterator<TransactionUploader>;
upload(upload: Transaction | SerializedUploader | string, data?: Uint8Array): AsyncGenerator<TransactionUploader, TransactionUploader, unknown>;
}

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

class Transactions {
constructor(api, crypto) {
constructor(api, crypto, chunks) {
this.api = api;
this.crypto = crypto;
this.chunks = chunks;
}

@@ -56,7 +57,8 @@ getTransactionAnchor() {

if (response.status == 200) {
if (response.data.format >= 2 && response.data.data_size > 0) {
const data_size = parseInt(response.data.data_size);
if (response.data.format >= 2 && data_size > 0 && data_size <= 1024 * 1024 * 12) {
const data = await this.getData(id);
return new transaction_1.default(Object.assign({}, response.data, { data }));
return new transaction_1.default(Object.assign(Object.assign({}, response.data), { data }));
}
return new transaction_1.default(Object.assign({}, response.data, { format: response.data.format || 1 }));
return new transaction_1.default(Object.assign(Object.assign({}, response.data), { format: response.data.format || 1 }));
}

@@ -105,16 +107,34 @@ if (response.status == 202) {

}
getData(id, options) {
return this.api.get(`tx/${id}/data`).then(response => {
if (response.status === 200) {
const data = response.data;
if (options && options.decode == true) {
if (options && options.string) {
return ArweaveUtils.b64UrlToString(data);
}
return ArweaveUtils.b64UrlToBuffer(data);
}
return data;
async getData(id, options) {
// Attempt to download from /txid, fall back to downloading chunks.
const resp = await this.api.get(`${id}`, { responseType: 'arraybuffer' });
let data = undefined;
if (resp.status === 200) {
data = new Uint8Array(resp.data);
}
if (resp.status === 400 && error_1.getError(resp) === 'tx_data_too_big') {
data = await this.chunks.downloadChunkedData(id);
}
// If we don't have data, throw an exception. Previously we
// just returned an empty data object.
if (!data) {
if (resp.status == 202) {
throw new error_1.default("TX_PENDING" /* TX_PENDING */);
}
return (options && options.decode) ? new Uint8Array(0) : '';
});
if (resp.status == 404) {
throw new error_1.default("TX_NOT_FOUND" /* TX_NOT_FOUND */);
}
if (resp.status == 410) {
throw new error_1.default("TX_FAILED" /* TX_FAILED */);
}
throw new Error(`Unable to get data: ${resp.status} - ${error_1.getError(resp)}`);
}
if (options && options.decode && !options.string) {
return data;
}
if (options && options.decode && options.string) {
return ArweaveUtils.bufferToString(data);
}
// Since decode wasn't requested, caller expects b64url encoded data.
return ArweaveUtils.bufferTob64Url(data);
}

@@ -153,3 +173,3 @@ async sign(transaction, jwk) {

}
else if (transaction instanceof Buffer) {
else if (typeof transaction.readInt32BE === 'function') {
transaction = new transaction_1.default(JSON.parse(transaction.toString()));

@@ -163,4 +183,4 @@ }

}
if (transaction.data.byteLength > 1024 * 1024 * 10) {
console.warn(`transactions.getUploader() or transactions.upload() is recommended for large data transactions`);
if (!transaction.chunks) {
await transaction.prepareChunks(transaction.data);
}

@@ -167,0 +187,0 @@ const uploader = await this.getUploader(transaction);

{
"name": "arweave",
"version": "1.8.0",
"version": "1.9.0",
"description": "Arweave JS client library",
"main": "index.js",
"main": "./node/index.js",
"browser": "./web/index.js",
"files": [

@@ -42,4 +43,9 @@ "node",

],
"author": "Kyle Beckles",
"license": "GPL-2.0",
"author": "Arweave Team <team@arweave.org>",
"contributors": [
"Kyle Beckles <kyle@arweave.org>",
"Aidan O'Kelly <aidan@arweave.org>",
"Cedrik Boudreau <cedrik@arweave.org>"
],
"license": "MIT",
"bugs": {

@@ -50,6 +56,6 @@ "url": "https://github.com/ArweaveTeam/arweave-js/issues"

"devDependencies": {
"@types/base64-js": "^1.2.5",
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.6",
"@types/node": "^10.14.7",
"@types/base64-js": "^1.3.0",
"@types/chai": "^4.2.12",
"@types/mocha": "^5.2.7",
"@types/node": "^10.17.28",
"babel-minify-webpack-plugin": "^0.3.1",

@@ -61,9 +67,9 @@ "chai": "^4.2.0",

"prettier": "1.16.4",
"rimraf": "^3.0.0",
"rimraf": "^3.0.2",
"ts-loader": "^5.4.5",
"ts-node": "^7.0.1",
"typescript": "^3.4.5",
"webpack": "^4.32.1",
"webpack-bundle-analyzer": "^3.3.2",
"webpack-cli": "^3.3.11"
"typescript": "^3.9.7",
"webpack": "^4.44.1",
"webpack-bundle-analyzer": "^3.8.0",
"webpack-cli": "^3.3.12"
},

@@ -76,6 +82,6 @@ "targets": {

"arweave-asn1": "github:arweave-kyle/asn1.js",
"axios": "^0.18.0",
"base64-js": "^1.3.0",
"axios": "^0.19.2",
"base64-js": "^1.3.1",
"bignumber.js": "^8.1.1"
}
}

@@ -32,2 +32,3 @@ # Arweave JS

- [ArQL](#arql)
- [License](#license)

@@ -64,3 +65,3 @@ ## Installation

const instance = Arweave.init({
const arweave = Arweave.init({
host: '127.0.0.1',

@@ -141,3 +142,3 @@ port: 1984,

```js
arweave.wallets.jwkToAddress(jwk).then((address) => {
arweave.wallets.jwkToAddress(key).then((address) => {
console.log(address);

@@ -269,3 +270,3 @@ //1seRanklLU_1VTGkEk7P0xAwMJfA7owA1JHW5KyZKlY

// format: 2,
// id: 'dUaZG84fJpiPQTt4J1VMBGvAr2ugyevFf0zmdkC1Ch4',
// id: '',
// last_tx: 'Tk-0c7260Ya5zjfjzl4f6-W-vRO94qiqZMAScKBcYXc68v1Pd8bYfTbKWi7pepUF',

@@ -284,3 +285,3 @@ // owner: 'kmM4O08BJB85RbxfQ2nkka9VNO6Czm2Tc_IGQNYC...',

// reward: '7673074',
// signature: 'JhioDyYS76tkfCqoRUfqvy-GW1tn3abARX0q8Fo_SRygCq...'
// signature: ''
// }

@@ -332,5 +333,5 @@ ```

await arweave.transaction.sign(transaction, key);
await arweave.transactions.sign(transaction, key);
let uploader = arweave.transactions.getUploader(transaction);
let uploader = await arweave.transactions.getUploader(transaction);

@@ -372,3 +373,3 @@ while (!uploader.isComplete) {

let uploader = arweave.transactions.getUploader(resumeObject, data);
let uploader = await arweave.transactions.getUploader(resumeObject, data);
while (!uploader.isComplete) {

@@ -389,3 +390,3 @@ await uploader.uploadChunk();

let uploader = arweave.transactions.getUploader(resumeTxId, data);
let uploader = await arweave.transactions.getUploader(resumeTxId, data);
while (!uploader.isComplete) {

@@ -548,1 +549,5 @@ await uploader.uploadChunks();

- https://www.npmjs.com/package/arql-ops
### License
This software is released under MIT license. See [LICENSE.md](./LICENSE.md) for full license details.

@@ -14,5 +14,7 @@ import Api from "./lib/api";

constructor(api: Api);
getTransactionOffset(tx: string): Promise<TransactionOffsetResponse>;
getTransactionOffset(id: string): Promise<TransactionOffsetResponse>;
getChunk(offset: string | number | BigInt): Promise<TransactionChunkResponse>;
getChunkData(offset: string | number | BigInt): Promise<Uint8Array>;
firstChunkOffset(offsetResponse: TransactionOffsetResponse): number;
downloadChunkedData(id: string): Promise<Uint8Array>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const error_1 = require("./lib/error");
const ArweaveUtils = require("./lib/utils");
class Chunks {

@@ -8,4 +9,4 @@ constructor(api) {

}
async getTransactionOffset(tx) {
const resp = await this.api.request().get(`/tx/${tx}/offset`);
async getTransactionOffset(id) {
const resp = await this.api.get(`tx/${id}/offset`);
if (resp.status === 200) {

@@ -17,3 +18,3 @@ return resp.data;

async getChunk(offset) {
const resp = await this.api.request().get(`/chunk/${offset}`);
const resp = await this.api.get(`chunk/${offset}`);
if (resp.status === 200) {

@@ -24,7 +25,26 @@ return resp.data;

}
async getChunkData(offset) {
const chunk = await this.getChunk(offset);
const buf = ArweaveUtils.b64UrlToBuffer(chunk.chunk);
return buf;
}
firstChunkOffset(offsetResponse) {
return parseInt(offsetResponse.offset) - parseInt(offsetResponse.size) + 1;
}
async downloadChunkedData(id) {
const offsetResponse = await this.getTransactionOffset(id);
const size = parseInt(offsetResponse.size);
const endOffset = parseInt(offsetResponse.offset);
const startOffset = endOffset - size + 1;
const data = new Uint8Array(size);
let byte = 0;
while (startOffset + byte < endOffset) {
const chunkData = await this.getChunkData(startOffset + byte);
data.set(chunkData, byte);
byte += chunkData.length;
}
return data;
}
}
exports.default = Chunks;
//# sourceMappingURL=chunks.js.map

@@ -41,5 +41,5 @@ import Ar from "./ar";

/** @deprecated */
readonly crypto: CryptoInterface;
get crypto(): CryptoInterface;
/** @deprecated */
readonly utils: typeof ArweaveUtils;
get utils(): typeof ArweaveUtils;
getConfig(): Config;

@@ -46,0 +46,0 @@ createTransaction(attributes: Partial<CreateTransactionInterface>, jwk: JWKInterface): Promise<Transaction>;

@@ -16,7 +16,7 @@ "use strict";

this.wallets = new wallets_1.default(this.api, Arweave.crypto);
this.transactions = new transactions_1.default(this.api, Arweave.crypto);
this.chunks = new chunks_1.default(this.api);
this.transactions = new transactions_1.default(this.api, Arweave.crypto, this.chunks);
this.silo = new silo_1.default(this.api, this.crypto, this.transactions);
this.network = new network_1.default(this.api);
this.ar = new ar_1.default();
this.chunks = new chunks_1.default(this.api);
}

@@ -107,4 +107,4 @@ /** @deprecated */

}
exports.default = Arweave;
Arweave.utils = ArweaveUtils;
exports.default = Arweave;
//# sourceMappingURL=common.js.map
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -47,3 +54,3 @@ const common_1 = require("./common");

const port = apiConfig.port || defaultConfig.port;
return new common_1.default(Object.assign({}, apiConfig, { host,
return new common_1.default(Object.assign(Object.assign({}, apiConfig), { host,
protocol,

@@ -53,4 +60,4 @@ port }));

window.Arweave = common_1.default;
__export(require("./common"));
__exportStar(require("./common"), exports);
exports.default = common_1.default;
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.jwkTopem = exports.pemTojwk = void 0;
// @ts-ignore

@@ -4,0 +5,0 @@ const asn = require("arweave-asn1");

@@ -24,3 +24,3 @@ import { AxiosResponse } from "axios";

};
export declare const getError: (resp: AxiosResponseLite) => any;
export declare function getError(resp: AxiosResponseLite): any;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getError = void 0;
class ArweaveError extends Error {

@@ -22,6 +23,27 @@ constructor(type, optional = {}) {

// resp.data, statusText or 'unknown'.
exports.getError = (resp) => resp.data ?
(resp.data.error || resp.data)
:
(resp.statusText || 'unknown');
// Note: a wrongly set content-type can
// cause what is a json response to be interepted
// as a string or Buffer, so we handle that too.
function getError(resp) {
let data = resp.data;
if (typeof resp.data === 'string') {
try {
data = JSON.parse(resp.data);
}
catch (e) {
}
}
if (resp.data instanceof ArrayBuffer || resp.data instanceof Uint8Array) {
try {
data = JSON.parse(data.toString());
}
catch (e) {
}
}
return data ?
(data.error || data)
:
(resp.statusText || 'unknown');
}
exports.getError = getError;
//# sourceMappingURL=error.js.map

@@ -70,3 +70,3 @@ export interface Chunk {

export declare function bufferToInt(buffer: Uint8Array): number;
export declare const arrayCompare: (a: any[] | Uint8Array, b: any[] | Uint8Array) => boolean;
export declare const arrayCompare: (a: Uint8Array | any[], b: Uint8Array | any[]) => boolean;
export declare function validatePath(id: Uint8Array, dest: number, leftBound: number, rightBound: number, path: Uint8Array): Promise<false | {

@@ -73,0 +73,0 @@ offset: number;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.debug = exports.validatePath = exports.arrayCompare = exports.bufferToInt = exports.intToBuffer = exports.arrayFlatten = exports.generateProofs = exports.buildLayers = exports.generateTransactionChunks = exports.generateTree = exports.computeRootHash = exports.generateLeaves = exports.chunkData = exports.MIN_CHUNK_SIZE = exports.MAX_CHUNK_SIZE = void 0;
/**

@@ -4,0 +5,0 @@ * @see {@link https://github.com/ArweaveTeam/arweave/blob/fbc381e0e36efffa45d13f2faa6199d3766edaa2/apps/arweave/src/ar_merkle.erl}

@@ -21,6 +21,6 @@ import Transaction from './transaction';

lastResponseError: string;
readonly isComplete: boolean;
readonly totalChunks: number;
readonly uploadedChunks: number;
readonly pctComplete: number;
get isComplete(): boolean;
get totalChunks(): number;
get uploadedChunks(): number;
get pctComplete(): number;
constructor(api: Api, transaction: Transaction);

@@ -27,0 +27,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionUploader = void 0;
const transaction_1 = require("./transaction");

@@ -31,2 +32,5 @@ const ArweaveUtils = require("./utils");

}
if (!transaction.chunks) {
throw new Error(`Transaction chunks not prepared`);
}
// Make a copy of transaction, zeroing the data so we can serialize.

@@ -33,0 +37,0 @@ this.data = transaction.data;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tag = void 0;
const ArweaveUtils = require("./utils");

@@ -4,0 +5,0 @@ const deepHash_1 = require("./deepHash");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.b64UrlDecode = exports.b64UrlEncode = exports.bufferTob64Url = exports.bufferTob64 = exports.b64UrlToBuffer = exports.stringToB64Url = exports.stringToBuffer = exports.bufferToString = exports.b64UrlToString = exports.concatBuffers = void 0;
const B64js = require("base64-js");

@@ -4,0 +5,0 @@ function concatBuffers(buffers) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SiloResource = void 0;
const ArweaveUtils = require("./lib/utils");

@@ -4,0 +5,0 @@ class Silo {

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

import { TransactionUploader, SerializedUploader } from "./lib/transaction-uploader";
import Chunks from "./chunks";
export interface TransactionConfirmedData {

@@ -20,3 +21,4 @@ block_indep_hash: string;

private crypto;
constructor(api: Api, crypto: CryptoInterface);
private chunks;
constructor(api: Api, crypto: CryptoInterface, chunks: Chunks);
getTransactionAnchor(): Promise<string>;

@@ -71,3 +73,3 @@ getPrice(byteSize: number, targetAddress?: string): Promise<string>;

*/
upload(upload: Transaction | SerializedUploader | string, data?: Uint8Array): AsyncIterableIterator<TransactionUploader>;
upload(upload: Transaction | SerializedUploader | string, data?: Uint8Array): AsyncGenerator<TransactionUploader, TransactionUploader, unknown>;
}

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

class Transactions {
constructor(api, crypto) {
constructor(api, crypto, chunks) {
this.api = api;
this.crypto = crypto;
this.chunks = chunks;
}

@@ -56,7 +57,8 @@ getTransactionAnchor() {

if (response.status == 200) {
if (response.data.format >= 2 && response.data.data_size > 0) {
const data_size = parseInt(response.data.data_size);
if (response.data.format >= 2 && data_size > 0 && data_size <= 1024 * 1024 * 12) {
const data = await this.getData(id);
return new transaction_1.default(Object.assign({}, response.data, { data }));
return new transaction_1.default(Object.assign(Object.assign({}, response.data), { data }));
}
return new transaction_1.default(Object.assign({}, response.data, { format: response.data.format || 1 }));
return new transaction_1.default(Object.assign(Object.assign({}, response.data), { format: response.data.format || 1 }));
}

@@ -105,16 +107,34 @@ if (response.status == 202) {

}
getData(id, options) {
return this.api.get(`tx/${id}/data`).then(response => {
if (response.status === 200) {
const data = response.data;
if (options && options.decode == true) {
if (options && options.string) {
return ArweaveUtils.b64UrlToString(data);
}
return ArweaveUtils.b64UrlToBuffer(data);
}
return data;
async getData(id, options) {
// Attempt to download from /txid, fall back to downloading chunks.
const resp = await this.api.get(`${id}`, { responseType: 'arraybuffer' });
let data = undefined;
if (resp.status === 200) {
data = new Uint8Array(resp.data);
}
if (resp.status === 400 && error_1.getError(resp) === 'tx_data_too_big') {
data = await this.chunks.downloadChunkedData(id);
}
// If we don't have data, throw an exception. Previously we
// just returned an empty data object.
if (!data) {
if (resp.status == 202) {
throw new error_1.default("TX_PENDING" /* TX_PENDING */);
}
return (options && options.decode) ? new Uint8Array(0) : '';
});
if (resp.status == 404) {
throw new error_1.default("TX_NOT_FOUND" /* TX_NOT_FOUND */);
}
if (resp.status == 410) {
throw new error_1.default("TX_FAILED" /* TX_FAILED */);
}
throw new Error(`Unable to get data: ${resp.status} - ${error_1.getError(resp)}`);
}
if (options && options.decode && !options.string) {
return data;
}
if (options && options.decode && options.string) {
return ArweaveUtils.bufferToString(data);
}
// Since decode wasn't requested, caller expects b64url encoded data.
return ArweaveUtils.bufferTob64Url(data);
}

@@ -153,3 +173,3 @@ async sign(transaction, jwk) {

}
else if (transaction instanceof Buffer) {
else if (typeof transaction.readInt32BE === 'function') {
transaction = new transaction_1.default(JSON.parse(transaction.toString()));

@@ -163,4 +183,4 @@ }

}
if (transaction.data.byteLength > 1024 * 1024 * 10) {
console.warn(`transactions.getUploader() or transactions.upload() is recommended for large data transactions`);
if (!transaction.chunks) {
await transaction.prepareChunks(transaction.data);
}

@@ -167,0 +187,0 @@ const uploader = await this.getUploader(transaction);

Sorry, the diff of this file is too big to display

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

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