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

@collabland/chain

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@collabland/chain - npm Package Compare versions

Comparing version 0.25.0 to 0.26.0

3

dist/base-connector.d.ts

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

import { FetchResponseOptions } from '@collabland/common';
import { AssetName, AssetTypeParams } from './caip';

@@ -55,2 +56,2 @@ import { ChainConnector } from './chain-connector';

}
export declare function fetchTokenMetadata<M extends TokenMetadata>(url?: string): Promise<any>;
export declare function fetchTokenMetadata<M extends TokenMetadata>(url?: string, options?: FetchResponseOptions): Promise<any>;

@@ -205,3 +205,4 @@ "use strict";

exports.BaseChainConnector = BaseChainConnector;
async function fetchTokenMetadata(url) {
async function fetchTokenMetadata(url, options = {}) {
var _a, _b;
debug('Fetching token metadata for %s:', url);

@@ -216,3 +217,5 @@ if (url) {

}
const fetch = (0, common_1.getFetch)();
const timeout = (_a = options.timeout) !== null && _a !== void 0 ? _a : 5 * 60 * 1000; // 5 mins
const bodyLimit = (_b = options.bodyLimit) !== null && _b !== void 0 ? _b : 1024 * 1024; // Limit to 1MB
const fetch = (0, common_1.getFetch)({ timeout: 5 * 60 * 1000 }); // Default timeout to 5 mins
if (url.startsWith('ipfs://') ||

@@ -222,2 +225,3 @@ url.startsWith('https://ipfs.io/ipfs/') ||

url.startsWith('https://gateway.pinata.cloud/ipfs/') ||
url.match(/^https\:\/\/[^\/\.]+\.mypinata\.cloud\/ipfs\//) ||
url.includes('.ipfs.dweb.link')) {

@@ -231,3 +235,6 @@ const ipfsGateway = (0, common_1.getEnvVar)('IPFS_GATEWAY_URL', 'https://collabland.mypinata.cloud');

const res = await fetch(url);
const metadata = await (0, common_1.handleFetchResponse)(res, 200);
const metadata = await (0, common_1.handleFetchResponse)(res, 200, {
timeout,
bodyLimit,
});
return metadata;

@@ -234,0 +241,0 @@ }

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

this.chainId = new chain_id_1.ChainId(params.chainId);
this.address = params.address;
this.address = (0, utils_1.decodeCaipParam)(params.address);
}

@@ -25,0 +25,0 @@ static parse(id) {

@@ -10,2 +10,3 @@ import { AssetName } from './asset-name';

static format(params: AssetNameIdParams): string;
static resolveTokenIds(ids: string, reportErrors?: boolean): Promise<string | undefined>;
/**

@@ -26,3 +27,5 @@ * Parse token ids and ranges into a list of ids

readonly tokenId: string;
private resolvedTokenIds;
constructor(params: AssetNameIdParams | string);
private resolveTokenIds;
tokenIds(): Promise<string[] | undefined>;

@@ -29,0 +32,0 @@ matchesTokenId(id: string | number): boolean;

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

this.assetName = new asset_name_1.AssetName(params.assetName);
this.tokenId = params.tokenId;
this.tokenId = (0, utils_1.decodeCaipParam)(params.tokenId);
}

@@ -34,11 +34,4 @@ static parse(id) {

}
/**
* Parse token ids and ranges into a list of ids
* @param ids - Token ids such as `1,3-4,100` or an http/https/ipfs url that
* points to token ids
* @returns
*/
static async parseTokenIds(ids, reportErrors) {
const result = [];
ids = decodeURIComponent(ids);
static async resolveTokenIds(ids, reportErrors) {
ids = (0, utils_1.decodeCaipParam)(ids);
if (ids.includes('://')) {

@@ -59,2 +52,16 @@ const collection = await (0, base_connector_1.fetchTokenMetadata)(ids);

}
return ids;
}
/**
* Parse token ids and ranges into a list of ids
* @param ids - Token ids such as `1,3-4,100` or an http/https/ipfs url that
* points to token ids
* @returns
*/
static async parseTokenIds(ids, reportErrors) {
const result = [];
const resolved = await AssetNameId.resolveTokenIds(ids, reportErrors);
if (resolved == null)
return undefined;
ids = resolved;
const ranges = (0, common_1.parseRanges)(ids);

@@ -97,7 +104,16 @@ for (const range of ranges) {

}
tokenIds() {
return AssetNameId.parseTokenIds(this.tokenId, true);
async resolveTokenIds() {
if (this.resolvedTokenIds)
return this.resolvedTokenIds;
const resolved = await AssetNameId.resolveTokenIds(this.tokenId, true);
this.resolvedTokenIds = resolved;
return this.resolvedTokenIds;
}
async tokenIds() {
const resolved = await this.resolveTokenIds();
return AssetNameId.parseTokenIds(resolved, true);
}
matchesTokenId(id) {
return (0, common_1.isInRanges)(id, this.tokenId);
var _a;
return (0, common_1.isInRanges)(id, (_a = this.resolvedTokenIds) !== null && _a !== void 0 ? _a : this.tokenId);
}

@@ -104,0 +120,0 @@ toString() {

@@ -20,4 +20,4 @@ "use strict";

}
this.namespace = params.namespace;
this.reference = params.reference;
this.namespace = (0, utils_1.decodeCaipParam)(params.namespace);
this.reference = (0, utils_1.decodeCaipParam)(params.reference);
}

@@ -24,0 +24,0 @@ static parse(id) {

@@ -20,4 +20,4 @@ "use strict";

}
this.namespace = params.namespace;
this.reference = params.reference;
this.namespace = (0, utils_1.decodeCaipParam)(params.namespace);
this.reference = (0, utils_1.decodeCaipParam)(params.reference);
}

@@ -24,0 +24,0 @@ static parse(id) {

@@ -23,1 +23,13 @@ import { IdentifierSpec } from './types';

export declare function isValidCaipId(id: string, spec: IdentifierSpec): boolean;
/**
* Encode CAIP parameter value if not encoded using encodeURIComponent
* @param value - Parameter value
* @returns
*/
export declare function encodeCaipParam(value: string): string;
/**
* Decode CAIP parameter value
* @param value - Parameter value
* @returns
*/
export declare function decodeCaipParam(value: string): string;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidCaipId = exports.formatCaipId = exports.parseCaipId = void 0;
exports.decodeCaipParam = exports.encodeCaipParam = exports.isValidCaipId = exports.formatCaipId = exports.parseCaipId = void 0;
/**

@@ -21,3 +21,3 @@ * Parse regular expression groups into a CAIP identifier object

// Simple string value
params[param] = decodeURIComponent(values[offset]);
params[param] = decodeCaipParam(values[offset]);
offset++;

@@ -59,6 +59,11 @@ continue;

if (typeof param === 'string') {
return params[param];
const value = params[param];
if (typeof value === 'string') {
return encodeCaipParam(value);
}
return value;
}
const value = params[param.name];
if (typeof value === 'string') {
// Return composite value
return value;

@@ -83,2 +88,39 @@ }

exports.isValidCaipId = isValidCaipId;
/**
* Encode CAIP parameter value if not encoded using encodeURIComponent
* @param value - Parameter value
* @returns
*/
function encodeCaipParam(value) {
if (!value.includes('%')) {
// No escaping char % found
return encodeURIComponent(value);
}
try {
const decoded = decodeURIComponent(value);
if (decoded !== value) {
// Already encoded
return value;
}
return encodeURIComponent(value);
}
catch (err) {
return encodeURIComponent(value);
}
}
exports.encodeCaipParam = encodeCaipParam;
/**
* Decode CAIP parameter value
* @param value - Parameter value
* @returns
*/
function decodeCaipParam(value) {
try {
return decodeURIComponent(value);
}
catch (err) {
return value;
}
}
exports.decodeCaipParam = decodeCaipParam;
//# sourceMappingURL=utils.js.map
{
"name": "@collabland/chain",
"version": "0.25.0",
"version": "0.26.0",
"description": "CollabLand Ethereum Integration",

@@ -34,3 +34,3 @@ "main": "dist/index.js",

"dependencies": {
"@collabland/common": "^0.34.0",
"@collabland/common": "^0.35.0",
"is-ipfs": "^6.0.2",

@@ -50,3 +50,3 @@ "parse-data-url": "^4.0.1",

"author": "Abridged, Inc.",
"gitHead": "231ed993bc19870689ec65b2d2ab59b99e403f30"
"gitHead": "5d6e73b095e84c151a00d07d4a1d7406cbc73aea"
}

@@ -10,2 +10,3 @@ // Copyright Abridged, Inc. 2021. All Rights Reserved.

debugFactory,
FetchResponseOptions,
getEnvVar,

@@ -290,2 +291,3 @@ getFetch,

url?: string,
options: FetchResponseOptions = {},
) {

@@ -300,3 +302,6 @@ debug('Fetching token metadata for %s:', url);

}
const fetch = getFetch();
const timeout = options.timeout ?? 5 * 60 * 1000; // 5 mins
const bodyLimit = options.bodyLimit ?? 1024 * 1024; // Limit to 1MB
const fetch = getFetch({timeout: 5 * 60 * 1000}); // Default timeout to 5 mins
if (

@@ -307,2 +312,3 @@ url.startsWith('ipfs://') ||

url.startsWith('https://gateway.pinata.cloud/ipfs/') ||
url.match(/^https\:\/\/[^\/\.]+\.mypinata\.cloud\/ipfs\//) ||
url.includes('.ipfs.dweb.link')

@@ -320,3 +326,6 @@ ) {

const res = await fetch(url);
const metadata = await handleFetchResponse<M>(res, 200);
const metadata = await handleFetchResponse<M>(res, 200, {
timeout,
bodyLimit,
});
return metadata;

@@ -323,0 +332,0 @@ } catch (err: AnyError) {

@@ -9,3 +9,3 @@ // Copyright Abridged, Inc. 2021. All Rights Reserved.

import {AccountIdParams, CAIPIdBase, IdentifierSpec} from './types';
import {formatCaipId, parseCaipId} from './utils';
import {decodeCaipParam, formatCaipId, parseCaipId} from './utils';

@@ -47,3 +47,3 @@ /**

this.chainId = new ChainId(params.chainId);
this.address = params.address;
this.address = decodeCaipParam(params.address);
}

@@ -50,0 +50,0 @@

@@ -18,3 +18,3 @@ // Copyright Abridged, Inc. 2021. All Rights Reserved.

import {AssetNameIdParams, CAIPIdBase, IdentifierSpec} from './types';
import {formatCaipId, parseCaipId} from './utils';
import {decodeCaipParam, formatCaipId, parseCaipId} from './utils';

@@ -39,11 +39,4 @@ const debug = debugFactory('collabland:chain:trace');

/**
* Parse token ids and ranges into a list of ids
* @param ids - Token ids such as `1,3-4,100` or an http/https/ipfs url that
* points to token ids
* @returns
*/
static async parseTokenIds(ids: string, reportErrors?: boolean) {
const result: string[] = [];
ids = decodeURIComponent(ids);
static async resolveTokenIds(ids: string, reportErrors?: boolean) {
ids = decodeCaipParam(ids);
if (ids.includes('://')) {

@@ -62,2 +55,16 @@ const collection = await fetchTokenMetadata(ids);

}
return ids;
}
/**
* Parse token ids and ranges into a list of ids
* @param ids - Token ids such as `1,3-4,100` or an http/https/ipfs url that
* points to token ids
* @returns
*/
static async parseTokenIds(ids: string, reportErrors?: boolean) {
const result: string[] = [];
const resolved = await AssetNameId.resolveTokenIds(ids, reportErrors);
if (resolved == null) return undefined;
ids = resolved;
const ranges = parseRanges(ids);

@@ -111,2 +118,4 @@ for (const range of ranges) {

private resolvedTokenIds: string;
constructor(params: AssetNameIdParams | string) {

@@ -119,11 +128,19 @@ super();

this.assetName = new AssetName(params.assetName);
this.tokenId = params.tokenId;
this.tokenId = decodeCaipParam(params.tokenId);
}
tokenIds() {
return AssetNameId.parseTokenIds(this.tokenId, true);
private async resolveTokenIds() {
if (this.resolvedTokenIds) return this.resolvedTokenIds;
const resolved = await AssetNameId.resolveTokenIds(this.tokenId, true);
this.resolvedTokenIds = resolved!;
return this.resolvedTokenIds;
}
async tokenIds() {
const resolved = await this.resolveTokenIds();
return AssetNameId.parseTokenIds(resolved, true);
}
matchesTokenId(id: string | number) {
return isInRanges(id, this.tokenId);
return isInRanges(id, this.resolvedTokenIds ?? this.tokenId);
}

@@ -130,0 +147,0 @@

@@ -8,3 +8,3 @@ // Copyright Abridged, Inc. 2021. All Rights Reserved.

import {AssetNameParams, CAIPIdBase, IdentifierSpec} from './types';
import {formatCaipId, parseCaipId} from './utils';
import {decodeCaipParam, formatCaipId, parseCaipId} from './utils';

@@ -41,4 +41,4 @@ /**

this.namespace = params.namespace;
this.reference = params.reference;
this.namespace = decodeCaipParam(params.namespace);
this.reference = decodeCaipParam(params.reference);
}

@@ -45,0 +45,0 @@

@@ -8,3 +8,3 @@ // Copyright Abridged, Inc. 2021. All Rights Reserved.

import {CAIPIdBase, ChainIdParams, IdentifierSpec} from './types';
import {formatCaipId, parseCaipId} from './utils';
import {decodeCaipParam, formatCaipId, parseCaipId} from './utils';

@@ -42,4 +42,4 @@ /**

this.namespace = params.namespace;
this.reference = params.reference;
this.namespace = decodeCaipParam(params.namespace);
this.reference = decodeCaipParam(params.reference);
}

@@ -46,0 +46,0 @@

@@ -20,3 +20,3 @@ // Copyright Abridged, Inc. 2021. All Rights Reserved.

// Simple string value
params[param] = decodeURIComponent(values[offset]);
params[param] = decodeCaipParam(values[offset]);
offset++;

@@ -59,6 +59,11 @@ continue;

if (typeof param === 'string') {
return params[param];
const value = params[param];
if (typeof value === 'string') {
return encodeCaipParam(value);
}
return value;
}
const value = params[param.name];
if (typeof value === 'string') {
// Return composite value
return value;

@@ -82,1 +87,36 @@ }

}
/**
* Encode CAIP parameter value if not encoded using encodeURIComponent
* @param value - Parameter value
* @returns
*/
export function encodeCaipParam(value: string) {
if (!value.includes('%')) {
// No escaping char % found
return encodeURIComponent(value);
}
try {
const decoded = decodeURIComponent(value);
if (decoded !== value) {
// Already encoded
return value;
}
return encodeURIComponent(value);
} catch (err) {
return encodeURIComponent(value);
}
}
/**
* Decode CAIP parameter value
* @param value - Parameter value
* @returns
*/
export function decodeCaipParam(value: string) {
try {
return decodeURIComponent(value);
} catch (err) {
return value;
}
}

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