New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ardrive/turbo-sdk

Package Overview
Dependencies
Maintainers
6
Versions
133
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ardrive/turbo-sdk - npm Package Compare versions

Comparing version 1.0.0-alpha.16 to 1.0.0-alpha.17

18

lib/esm/common/factory.js

@@ -1,9 +0,12 @@

import { TurboUnauthenticatedPaymentService } from './payment.js';
import { TurboUnauthenticatedClient } from './turbo.js';
import { TurboUnauthenticatedUploadService } from './upload.js';
export class TurboBaseFactory {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TurboBaseFactory = void 0;
const payment_js_1 = require("./payment.js");
const turbo_js_1 = require("./turbo.js");
const upload_js_1 = require("./upload.js");
class TurboBaseFactory {
static unauthenticated({ paymentServiceConfig = {}, uploadServiceConfig = {}, } = {}) {
const paymentService = new TurboUnauthenticatedPaymentService(Object.assign({}, paymentServiceConfig));
const uploadService = new TurboUnauthenticatedUploadService(Object.assign({}, uploadServiceConfig));
return new TurboUnauthenticatedClient({
const paymentService = new payment_js_1.TurboUnauthenticatedPaymentService(Object.assign({}, paymentServiceConfig));
const uploadService = new upload_js_1.TurboUnauthenticatedUploadService(Object.assign({}, uploadServiceConfig));
return new turbo_js_1.TurboUnauthenticatedClient({
uploadService,

@@ -14,1 +17,2 @@ paymentService,

}
exports.TurboBaseFactory = TurboBaseFactory;

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

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -10,7 +11,9 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
import { createAxiosInstance } from '../utils/axiosClient.js';
import { FailedRequestError } from '../utils/errors.js';
export class TurboHTTPService {
Object.defineProperty(exports, "__esModule", { value: true });
exports.TurboHTTPService = void 0;
const axiosClient_js_1 = require("../utils/axiosClient.js");
const errors_js_1 = require("../utils/errors.js");
class TurboHTTPService {
constructor({ url, retryConfig, }) {
this.axios = createAxiosInstance({
this.axios = (0, axiosClient_js_1.createAxiosInstance)({
axiosConfig: {

@@ -29,3 +32,3 @@ baseURL: url,

if (!allowedStatuses.includes(status)) {
throw new FailedRequestError(status, statusText);
throw new errors_js_1.FailedRequestError(status, statusText);
}

@@ -42,3 +45,3 @@ return data;

if (!allowedStatuses.includes(status)) {
throw new FailedRequestError(status, statusText);
throw new errors_js_1.FailedRequestError(status, statusText);
}

@@ -49,1 +52,2 @@ return response;

}
exports.TurboHTTPService = TurboHTTPService;

@@ -0,1 +1,17 @@

"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 __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
/**

@@ -17,4 +33,4 @@ * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.

*/
export * from './upload.js';
export * from './payment.js';
export * from './turbo.js';
__exportStar(require("./upload.js"), exports);
__exportStar(require("./payment.js"), exports);
__exportStar(require("./turbo.js"), exports);

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

export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

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

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -10,6 +11,8 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
import { TurboHTTPService } from './http.js';
export class TurboUnauthenticatedPaymentService {
Object.defineProperty(exports, "__esModule", { value: true });
exports.TurboAuthenticatedPaymentService = exports.TurboUnauthenticatedPaymentService = void 0;
const http_js_1 = require("./http.js");
class TurboUnauthenticatedPaymentService {
constructor({ url = 'https://payment.ardrive.dev', retryConfig, }) {
this.httpService = new TurboHTTPService({
this.httpService = new http_js_1.TurboHTTPService({
url: `${url}/v1`,

@@ -64,4 +67,5 @@ retryConfig,

}
exports.TurboUnauthenticatedPaymentService = TurboUnauthenticatedPaymentService;
// NOTE: to avoid redundancy, we use inheritance here - but generally prefer composition over inheritance
export class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentService {
class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentService {
constructor({ url = 'https://payment.ardrive.dev', retryConfig, signer, }) {

@@ -84,1 +88,2 @@ super({ url, retryConfig });

}
exports.TurboAuthenticatedPaymentService = TurboAuthenticatedPaymentService;

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

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -10,6 +11,8 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
import { TurboUnauthenticatedPaymentService } from './payment.js';
import { TurboUnauthenticatedUploadService } from './upload.js';
export class TurboUnauthenticatedClient {
constructor({ uploadService = new TurboUnauthenticatedUploadService({}), paymentService = new TurboUnauthenticatedPaymentService({}), }) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.TurboAuthenticatedClient = exports.TurboUnauthenticatedClient = void 0;
const payment_js_1 = require("./payment.js");
const upload_js_1 = require("./upload.js");
class TurboUnauthenticatedClient {
constructor({ uploadService = new upload_js_1.TurboUnauthenticatedUploadService({}), paymentService = new payment_js_1.TurboUnauthenticatedPaymentService({}), }) {
this.paymentService = paymentService;

@@ -81,3 +84,4 @@ this.uploadService = uploadService;

}
export class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
exports.TurboUnauthenticatedClient = TurboUnauthenticatedClient;
class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
constructor({ paymentService, uploadService, }) {

@@ -103,1 +107,2 @@ super({ paymentService, uploadService });

}
exports.TurboAuthenticatedClient = TurboAuthenticatedClient;

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

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -10,6 +11,8 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
import { TurboHTTPService } from './http.js';
export class TurboUnauthenticatedUploadService {
Object.defineProperty(exports, "__esModule", { value: true });
exports.TurboAuthenticatedUploadService = exports.TurboUnauthenticatedUploadService = void 0;
const http_js_1 = require("./http.js");
class TurboUnauthenticatedUploadService {
constructor({ url = 'https://upload.ardrive.dev', retryConfig, }) {
this.httpService = new TurboHTTPService({
this.httpService = new http_js_1.TurboHTTPService({
url: `${url}/v1`,

@@ -33,4 +36,5 @@ retryConfig,

}
exports.TurboUnauthenticatedUploadService = TurboUnauthenticatedUploadService;
// NOTE: to avoid redundancy, we use inheritance here - but generally prefer composition over inheritance
export class TurboAuthenticatedUploadService extends TurboUnauthenticatedUploadService {
class TurboAuthenticatedUploadService extends TurboUnauthenticatedUploadService {
constructor({ url = 'https://upload.ardrive.dev', retryConfig, signer, }) {

@@ -57,1 +61,2 @@ super({ url, retryConfig });

}
exports.TurboAuthenticatedUploadService = TurboAuthenticatedUploadService;

@@ -0,1 +1,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TurboFactory = void 0;
/**

@@ -17,11 +20,11 @@ * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.

*/
import { TurboBaseFactory } from '../common/factory.js';
import { TurboAuthenticatedClient, TurboAuthenticatedPaymentService, TurboAuthenticatedUploadService, } from '../common/index.js';
import { TurboNodeArweaveSigner } from './signer.js';
export class TurboFactory extends TurboBaseFactory {
const factory_js_1 = require("../common/factory.js");
const index_js_1 = require("../common/index.js");
const signer_js_1 = require("./signer.js");
class TurboFactory extends factory_js_1.TurboBaseFactory {
static authenticated({ privateKey, paymentServiceConfig = {}, uploadServiceConfig = {}, }) {
const signer = new TurboNodeArweaveSigner({ privateKey });
const paymentService = new TurboAuthenticatedPaymentService(Object.assign(Object.assign({}, paymentServiceConfig), { signer }));
const uploadService = new TurboAuthenticatedUploadService(Object.assign(Object.assign({}, uploadServiceConfig), { signer }));
return new TurboAuthenticatedClient({
const signer = new signer_js_1.TurboNodeArweaveSigner({ privateKey });
const paymentService = new index_js_1.TurboAuthenticatedPaymentService(Object.assign(Object.assign({}, paymentServiceConfig), { signer }));
const uploadService = new index_js_1.TurboAuthenticatedUploadService(Object.assign(Object.assign({}, uploadServiceConfig), { signer }));
return new index_js_1.TurboAuthenticatedClient({
uploadService,

@@ -32,1 +35,2 @@ paymentService,

}
exports.TurboFactory = TurboFactory;

@@ -0,1 +1,17 @@

"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 __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
/**

@@ -17,5 +33,5 @@ * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.

*/
export * from './factory.js';
export * from './signer.js';
export * from '../types.js';
export * from '../common/index.js';
__exportStar(require("./factory.js"), exports);
__exportStar(require("./signer.js"), exports);
__exportStar(require("../types.js"), exports);
__exportStar(require("../common/index.js"), exports);

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

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -10,2 +11,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TurboNodeArweaveSigner = void 0;
/**

@@ -27,11 +33,11 @@ * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.

*/
import { ArweaveSigner, streamSigner } from 'arbundles';
import Arweave from 'arweave/node/index.js';
import { randomBytes } from 'node:crypto';
import { toB64Url } from '../utils/base64.js';
export class TurboNodeArweaveSigner {
const arbundles_1 = require("arbundles");
const index_js_1 = __importDefault(require("arweave/node/index.js"));
const node_crypto_1 = require("node:crypto");
const base64_js_1 = require("../utils/base64.js");
class TurboNodeArweaveSigner {
// TODO: replace with internal signer class
constructor({ privateKey }) {
this.privateKey = privateKey;
this.signer = new ArweaveSigner(this.privateKey);
this.signer = new arbundles_1.ArweaveSigner(this.privateKey);
}

@@ -41,3 +47,3 @@ signDataItem({ fileStreamFactory, }) {

const [stream1, stream2] = [fileStreamFactory(), fileStreamFactory()];
return streamSigner(stream1, stream2, this.signer);
return (0, arbundles_1.streamSigner)(stream1, stream2, this.signer);
}

@@ -47,9 +53,9 @@ // NOTE: this might be better in a parent class or elsewhere - easy enough to leave in here now and does require specific environment version of crypto

return __awaiter(this, void 0, void 0, function* () {
const nonce = randomBytes(16).toString('hex');
const nonce = (0, node_crypto_1.randomBytes)(16).toString('hex');
const buffer = Buffer.from(nonce);
const signature = yield Arweave.crypto.sign(this.privateKey, buffer);
const signature = yield index_js_1.default.crypto.sign(this.privateKey, buffer);
return {
'x-public-key': this.privateKey.n,
'x-nonce': nonce,
'x-signature': toB64Url(Buffer.from(signature)),
'x-signature': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
};

@@ -59,1 +65,2 @@ });

}
exports.TurboNodeArweaveSigner = TurboNodeArweaveSigner;

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

{\n "type": "module"\n}
{"type": "module"}

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

export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

@@ -0,1 +1,30 @@

"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) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createAxiosInstance = void 0;
/**

@@ -17,10 +46,10 @@ * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.

*/
import axios, { CanceledError } from 'axios';
import axiosRetry from 'axios-retry';
export const createAxiosInstance = ({ axiosConfig = {}, retryConfig = {
retryDelay: axiosRetry.exponentialDelay,
const axios_1 = __importStar(require("axios"));
const axios_retry_1 = __importDefault(require("axios-retry"));
const createAxiosInstance = ({ axiosConfig = {}, retryConfig = {
retryDelay: axios_retry_1.default.exponentialDelay,
retries: 3,
retryCondition: (error) => {
return (!(error instanceof CanceledError) &&
axiosRetry.isNetworkOrIdempotentRequestError(error));
return (!(error instanceof axios_1.CanceledError) &&
axios_retry_1.default.isNetworkOrIdempotentRequestError(error));
},

@@ -31,8 +60,9 @@ onRetry: (retryCount, error) => {

}, }) => {
const axiosInstance = axios.create(Object.assign(Object.assign({}, axiosConfig), { validateStatus: () => true }));
const axiosInstance = axios_1.default.create(Object.assign(Object.assign({}, axiosConfig), { validateStatus: () => true }));
// eslint-disable-next-line
if (retryConfig.retries && retryConfig.retries > 0) {
axiosRetry(axiosInstance, retryConfig);
(0, axios_retry_1.default)(axiosInstance, retryConfig);
}
return axiosInstance;
};
exports.createAxiosInstance = createAxiosInstance;

@@ -0,1 +1,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sha256B64Url = exports.toB64Url = exports.fromB64Url = exports.ownerToAddress = exports.jwkToPublicArweaveAddress = exports.base64URLRegex = void 0;
/**

@@ -17,12 +20,14 @@ * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.

*/
import { bufferTob64Url } from 'arweave/node/lib/utils.js';
import { createHash } from 'crypto';
export const base64URLRegex = /^[a-zA-Z0-9_-]{43}$/;
export function jwkToPublicArweaveAddress(jwk) {
const utils_js_1 = require("arweave/node/lib/utils.js");
const crypto_1 = require("crypto");
exports.base64URLRegex = /^[a-zA-Z0-9_-]{43}$/;
function jwkToPublicArweaveAddress(jwk) {
return ownerToAddress(jwk.n);
}
export function ownerToAddress(owner) {
exports.jwkToPublicArweaveAddress = jwkToPublicArweaveAddress;
function ownerToAddress(owner) {
return sha256B64Url(fromB64Url(owner));
}
export function fromB64Url(input) {
exports.ownerToAddress = ownerToAddress;
function fromB64Url(input) {
const paddingLength = input.length % 4 === 0 ? 0 : 4 - (input.length % 4);

@@ -35,7 +40,10 @@ const base64 = input

}
export function toB64Url(buffer) {
return bufferTob64Url(buffer);
exports.fromB64Url = fromB64Url;
function toB64Url(buffer) {
return (0, utils_js_1.bufferTob64Url)(buffer);
}
export function sha256B64Url(input) {
return toB64Url(createHash('sha256').update(input).digest());
exports.toB64Url = toB64Url;
function sha256B64Url(input) {
return toB64Url((0, crypto_1.createHash)('sha256').update(input).digest());
}
exports.sha256B64Url = sha256B64Url;

@@ -0,1 +1,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FailedRequestError = exports.UnauthenticatedRequestError = void 0;
/**

@@ -17,3 +20,3 @@ * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.

*/
export class UnauthenticatedRequestError extends Error {
class UnauthenticatedRequestError extends Error {
constructor() {

@@ -24,3 +27,4 @@ super('Failed authentication. JWK is required.');

}
export class FailedRequestError extends Error {
exports.UnauthenticatedRequestError = UnauthenticatedRequestError;
class FailedRequestError extends Error {
constructor(status, message) {

@@ -31,1 +35,2 @@ super(`Failed request: ${status}: ${message}`);

}
exports.FailedRequestError = FailedRequestError;

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

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -10,3 +11,5 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
export function readableStreamToBuffer({ stream, }) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.readableStreamToBuffer = void 0;
function readableStreamToBuffer({ stream, }) {
return __awaiter(this, void 0, void 0, function* () {

@@ -26,1 +29,2 @@ const reader = stream.getReader();

}
exports.readableStreamToBuffer = readableStreamToBuffer;

@@ -0,1 +1,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TurboFactory = void 0;
/**

@@ -17,11 +20,11 @@ * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.

*/
import { TurboBaseFactory } from '../common/factory.js';
import { TurboAuthenticatedClient, TurboAuthenticatedPaymentService, TurboAuthenticatedUploadService, } from '../common/index.js';
import { TurboWebArweaveSigner } from './signer.js';
export class TurboFactory extends TurboBaseFactory {
const factory_js_1 = require("../common/factory.js");
const index_js_1 = require("../common/index.js");
const signer_js_1 = require("./signer.js");
class TurboFactory extends factory_js_1.TurboBaseFactory {
static authenticated({ privateKey, paymentServiceConfig = {}, uploadServiceConfig = {}, }) {
const signer = new TurboWebArweaveSigner({ privateKey });
const paymentService = new TurboAuthenticatedPaymentService(Object.assign(Object.assign({}, paymentServiceConfig), { signer }));
const uploadService = new TurboAuthenticatedUploadService(Object.assign(Object.assign({}, uploadServiceConfig), { signer }));
return new TurboAuthenticatedClient({
const signer = new signer_js_1.TurboWebArweaveSigner({ privateKey });
const paymentService = new index_js_1.TurboAuthenticatedPaymentService(Object.assign(Object.assign({}, paymentServiceConfig), { signer }));
const uploadService = new index_js_1.TurboAuthenticatedUploadService(Object.assign(Object.assign({}, uploadServiceConfig), { signer }));
return new index_js_1.TurboAuthenticatedClient({
uploadService,

@@ -32,1 +35,2 @@ paymentService,

}
exports.TurboFactory = TurboFactory;

@@ -0,1 +1,17 @@

"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 __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
/**

@@ -17,5 +33,5 @@ * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.

*/
export * from './factory.js';
export * from './signer.js';
export * from '../common/index.js';
export * from '../types.js';
__exportStar(require("./factory.js"), exports);
__exportStar(require("./signer.js"), exports);
__exportStar(require("../common/index.js"), exports);
__exportStar(require("../types.js"), exports);

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

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -10,2 +11,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TurboWebArweaveSigner = void 0;
/**

@@ -27,11 +33,11 @@ * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.

*/
import { ArweaveSigner, createData } from 'arbundles';
import Arweave from 'arweave';
import { randomBytes } from 'node:crypto';
import { toB64Url } from '../utils/base64.js';
import { readableStreamToBuffer } from '../utils/readableStream.js';
export class TurboWebArweaveSigner {
const arbundles_1 = require("arbundles");
const arweave_1 = __importDefault(require("arweave"));
const node_crypto_1 = require("node:crypto");
const base64_js_1 = require("../utils/base64.js");
const readableStream_js_1 = require("../utils/readableStream.js");
class TurboWebArweaveSigner {
constructor({ privateKey }) {
this.privateKey = privateKey;
this.signer = new ArweaveSigner(this.privateKey);
this.signer = new arbundles_1.ArweaveSigner(this.privateKey);
}

@@ -41,7 +47,7 @@ signDataItem({ fileStreamFactory, }) {

// TODO: converts the readable stream to a buffer bc incrementally signing ReadableStreams is not trivial
const buffer = yield readableStreamToBuffer({
const buffer = yield (0, readableStream_js_1.readableStreamToBuffer)({
stream: fileStreamFactory(),
// TODO: add payload size to get performance improvements
});
const signedDataItem = createData(buffer, this.signer);
const signedDataItem = (0, arbundles_1.createData)(buffer, this.signer);
yield signedDataItem.sign(this.signer);

@@ -56,4 +62,4 @@ return signedDataItem.getRaw();

// a bit hacky - but arweave exports cause issues in tests vs. browser
const arweave = (_a = Arweave.default) !== null && _a !== void 0 ? _a : Arweave;
const nonce = randomBytes(16).toString('hex');
const arweave = (_a = arweave_1.default.default) !== null && _a !== void 0 ? _a : arweave_1.default;
const nonce = (0, node_crypto_1.randomBytes)(16).toString('hex');
const buffer = Buffer.from(nonce);

@@ -64,3 +70,3 @@ const signature = yield arweave.crypto.sign(this.privateKey, buffer, {});

'x-nonce': nonce,
'x-signature': toB64Url(Buffer.from(signature)),
'x-signature': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
};

@@ -70,1 +76,2 @@ });

}
exports.TurboWebArweaveSigner = TurboWebArweaveSigner;
{
"name": "@ardrive/turbo-sdk",
"version": "1.0.0-alpha.16",
"version": "1.0.0-alpha.17",
"main": "./lib/cjs/node/index.js",

@@ -5,0 +5,0 @@ "types": "./lib/types/node/index.d.ts",

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

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