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.10.0 to 0.11.0

dist/caip/asset-name-id.d.ts

23

dist/base-connector.js

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

exports.BaseChainConnector = void 0;
const tslib_1 = require("tslib");
const common_1 = require("@collabland/common");
const assert_1 = (0, tslib_1.__importDefault)(require("assert"));
const caip_1 = require("./caip");
const asset_name_id_1 = require("./caip/asset-name-id");
const chain_resource_1 = require("./chain-resource");

@@ -69,21 +68,3 @@ const types_1 = require("./types");

parseTokenIds(ids) {
const parts = ids.split(',').filter(Boolean);
const result = [];
for (const id of parts) {
if (id.includes('-')) {
// 2-100
const bounds = id.split('-');
const from = parseInt(bounds[0]);
const to = parseInt(bounds[1]);
(0, assert_1.default)(!isNaN(from), `Invalid token id range: ${id}`);
(0, assert_1.default)(!isNaN(to), `Invalid token id range: ${id}`);
for (let i = from; i <= to; i++) {
result.push(String(i));
}
}
else {
result.push(id);
}
}
return result;
return asset_name_id_1.AssetNameId.parseTokenIds(ids);
}

@@ -90,0 +71,0 @@ async getBalances(account, requests, options) {

import { ChainId } from './chain-id';
import { AccountIdParams, IdentifierSpec } from './types';
/**
* CAIP Account id
*/
export declare class AccountId implements AccountIdParams {

@@ -7,3 +10,9 @@ static spec: IdentifierSpec;

static format(params: AccountIdParams): string;
/**
* Chain id
*/
readonly chainId: ChainId;
/**
* Account address/name
*/
readonly address: string;

@@ -10,0 +19,0 @@ constructor(params: AccountIdParams | string);

@@ -11,2 +11,5 @@ "use strict";

const utils_1 = require("./utils");
/**
* CAIP Account id
*/
class AccountId {

@@ -13,0 +16,0 @@ constructor(params) {

@@ -1,11 +0,15 @@

import { AssetName } from './asset-name';
import { AssetNameId } from './asset-name-id';
import { ChainId } from './chain-id';
import { AssetIdParams, IdentifierSpec } from './types';
export declare class AssetId implements AssetIdParams {
/**
* CAIP Asset id
*/
export declare class AssetId extends AssetNameId implements AssetIdParams {
static spec: IdentifierSpec;
static parse(id: string): AssetIdParams;
static format(params: AssetIdParams): string;
/**
* Chain id
*/
readonly chainId: ChainId;
readonly assetName: AssetName;
readonly tokenId: string;
constructor(params: AssetIdParams | string);

@@ -12,0 +16,0 @@ toString(): string;

@@ -8,7 +8,10 @@ "use strict";

exports.AssetId = void 0;
const asset_name_1 = require("./asset-name");
const asset_name_id_1 = require("./asset-name-id");
const chain_id_1 = require("./chain-id");
const spec_1 = require("./spec");
const utils_1 = require("./utils");
class AssetId {
/**
* CAIP Asset id
*/
class AssetId extends asset_name_id_1.AssetNameId {
constructor(params) {

@@ -18,5 +21,4 @@ if (typeof params === 'string') {

}
super(params);
this.chainId = new chain_id_1.ChainId(params.chainId);
this.assetName = new asset_name_1.AssetName(params.assetName);
this.tokenId = params.tokenId;
}

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

import { AssetNameParams, IdentifierSpec } from './types';
/**
* CAIP Asset name
*/
export declare class AssetName implements AssetNameParams {

@@ -6,3 +9,9 @@ static spec: IdentifierSpec;

static format(params: AssetNameParams): string;
/**
* Asset namespace, such as ERC20, erc721, NEP141, or NEP171
*/
readonly namespace: string;
/**
* Asset contract address
*/
readonly reference: string;

@@ -9,0 +18,0 @@ constructor(params: AssetNameParams | string);

@@ -10,2 +10,5 @@ "use strict";

const utils_1 = require("./utils");
/**
* CAIP Asset name
*/
class AssetName {

@@ -12,0 +15,0 @@ constructor(params) {

import { AssetName } from './asset-name';
import { ChainId } from './chain-id';
import { AssetTypeParams, IdentifierSpec } from './types';
/**
* CAIP asset type
*/
export declare class AssetType implements AssetTypeParams {

@@ -8,3 +11,9 @@ static spec: IdentifierSpec;

static format(params: AssetTypeParams): string;
/**
* Chain id
*/
readonly chainId: ChainId;
/**
* Asset name
*/
readonly assetName: AssetName;

@@ -11,0 +20,0 @@ constructor(params: AssetTypeParams | string);

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

const utils_1 = require("./utils");
/**
* CAIP asset type
*/
class AssetType {

@@ -14,0 +17,0 @@ constructor(params) {

import { ChainIdParams, IdentifierSpec } from './types';
/**
* CAIP chain id
*/
export declare class ChainId implements ChainIdParams {

@@ -6,3 +9,10 @@ static spec: IdentifierSpec;

static format(params: ChainIdParams): string;
/**
* Chain namespace, such as `evm`, `eip115`, `near`, `solana`, `tezos`, `algorand`,
* and `flow`
*/
readonly namespace: string;
/**
* Chain id or network name, such as `1`, `mainnet`, `testnet`, `ropsten`, and `edonet`
*/
readonly reference: string;

@@ -9,0 +19,0 @@ constructor(params: ChainIdParams | string);

@@ -10,2 +10,5 @@ "use strict";

const utils_1 = require("./utils");
/**
* CAIP chain id
*/
class ChainId {

@@ -12,0 +15,0 @@ constructor(params) {

export * from './account-id';
export * from './asset-id';
export * from './asset-name';
export * from './asset-name-id';
export * from './asset-type';

@@ -5,0 +6,0 @@ export * from './chain-id';

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

(0, tslib_1.__exportStar)(require("./asset-name"), exports);
(0, tslib_1.__exportStar)(require("./asset-name-id"), exports);
(0, tslib_1.__exportStar)(require("./asset-type"), exports);

@@ -15,0 +16,0 @@ (0, tslib_1.__exportStar)(require("./chain-id"), exports);

@@ -10,2 +10,3 @@ import { IdentifierSpec } from './types';

assetName: IdentifierSpec;
assetNameId: IdentifierSpec;
assetType: IdentifierSpec;

@@ -12,0 +13,0 @@ assetId: IdentifierSpec;

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

const accountAddress = '[a-zA-Z0-9._]{1,64}';
const tokenId = '[-a-zA-Z0-9._:]{1,32}';
/**
* Extension: we want to allow multiple token ids, such as `1-100` or `1,3,100`.
*/
const tokenId = '[-a-zA-Z0-9._:,]{1,32}';
const CAIP2 = {

@@ -35,2 +38,9 @@ name: 'chainId',

};
// represents namespace:reference/tokenId in CAIP-19
const AssetNameId = {
name: 'assetNameId',
regex: `${AssetName.regex}/(${tokenId})`,
properties: [AssetName, 'tokenId'],
delimiter: '/',
};
const CAIP19AssetType = {

@@ -56,2 +66,3 @@ name: 'assetType',

assetName: AssetName,
assetNameId: AssetNameId,
assetType: CAIP19AssetType,

@@ -58,0 +69,0 @@ assetId: CAIP19AssetId,

@@ -48,2 +48,9 @@ /**

/**
* Asset name and id
*/
export interface AssetNameIdParams {
assetName: string | AssetNameParams;
tokenId: string;
}
/**
* Asset type

@@ -58,4 +65,3 @@ */

*/
export interface AssetIdParams extends AssetTypeParams {
tokenId: string;
export interface AssetIdParams extends AssetTypeParams, AssetNameIdParams {
}

@@ -62,0 +68,0 @@ /**

@@ -80,5 +80,5 @@ import { AccountId, AccountIdParams, AssetId, AssetIdParams, AssetType, AssetTypeParams, CAIPId, CAIPIdParams, CAIPIdParamsType, ChainId, ChainIdParams } from './caip';

options: ChainOptions | undefined;
tokenId: string;
chainId: string | ChainIdParams;
assetName: string | import("./caip").AssetNameParams;
tokenId: string;
};

@@ -85,0 +85,0 @@ }

{
"name": "@collabland/chain",
"version": "0.10.0",
"version": "0.11.0",
"description": "CollabLand Ethereum Integration",

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

"dependencies": {
"@collabland/common": "^0.21.5",
"@collabland/common": "^0.22.0",
"tslib": "^2.0.0"
},
"devDependencies": {
"@loopback/build": "^7.0.0",
"@loopback/eslint-config": "^11.0.0",
"@loopback/testlab": "^3.4.2",
"@loopback/build": "^7.0.1",
"@loopback/eslint-config": "^11.0.1",
"@loopback/testlab": "^3.4.3",
"@types/node": "^12.12.6",

@@ -47,3 +47,3 @@ "typescript": "~4.4.2"

"author": "Abridged, Inc.",
"gitHead": "a64f8bb15a9310e48a189115a0d64a3388c70284"
"gitHead": "ad6d1039f419a915b1d37f8c4a7a7e11b34479a8"
}

@@ -16,4 +16,4 @@ // Copyright Abridged, Inc. 2021. All Rights Reserved.

} from '@collabland/common';
import assert from 'assert';
import {AssetName, AssetTypeParams} from './caip';
import {AssetNameId} from './caip/asset-name-id';
import {ChainConnector} from './chain-connector';

@@ -129,20 +129,3 @@ import {

protected parseTokenIds(ids: string) {
const parts = ids.split(',').filter(Boolean);
const result: string[] = [];
for (const id of parts) {
if (id.includes('-')) {
// 2-100
const bounds = id.split('-');
const from = parseInt(bounds[0]);
const to = parseInt(bounds[1]);
assert(!isNaN(from), `Invalid token id range: ${id}`);
assert(!isNaN(to), `Invalid token id range: ${id}`);
for (let i = from; i <= to; i++) {
result.push(String(i));
}
} else {
result.push(id);
}
}
return result;
return AssetNameId.parseTokenIds(ids);
}

@@ -149,0 +132,0 @@

@@ -11,2 +11,5 @@ // Copyright Abridged, Inc. 2021. All Rights Reserved.

/**
* CAIP Account id
*/
export class AccountId implements AccountIdParams {

@@ -28,3 +31,9 @@ static spec: IdentifierSpec = CAIP['10'];

/**
* Chain id
*/
readonly chainId: ChainId;
/**
* Account address/name
*/
readonly address: string;

@@ -31,0 +40,0 @@

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

import {AssetName} from './asset-name';
import {AssetNameId} from './asset-name-id';
import {ChainId} from './chain-id';

@@ -13,3 +13,6 @@ import {CAIP} from './spec';

export class AssetId implements AssetIdParams {
/**
* CAIP Asset id
*/
export class AssetId extends AssetNameId implements AssetIdParams {
static spec: IdentifierSpec = CAIP['19'].assetId;

@@ -25,5 +28,6 @@

/**
* Chain id
*/
readonly chainId: ChainId;
readonly assetName: AssetName;
readonly tokenId: string;

@@ -35,5 +39,4 @@ constructor(params: AssetIdParams | string) {

super(params);
this.chainId = new ChainId(params.chainId);
this.assetName = new AssetName(params.assetName);
this.tokenId = params.tokenId;
}

@@ -40,0 +43,0 @@

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

/**
* CAIP Asset name
*/
export class AssetName implements AssetNameParams {

@@ -22,3 +25,10 @@ static spec: IdentifierSpec = CAIP['19'].assetName;

/**
* Asset namespace, such as ERC20, erc721, NEP141, or NEP171
*/
readonly namespace: string;
/**
* Asset contract address
*/
readonly reference: string;

@@ -25,0 +35,0 @@

@@ -12,2 +12,5 @@ // Copyright Abridged, Inc. 2021. All Rights Reserved.

/**
* CAIP asset type
*/
export class AssetType implements AssetTypeParams {

@@ -24,3 +27,9 @@ static spec: IdentifierSpec = CAIP['19'].assetType;

/**
* Chain id
*/
readonly chainId: ChainId;
/**
* Asset name
*/
readonly assetName: AssetName;

@@ -27,0 +36,0 @@

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

/**
* CAIP chain id
*/
export class ChainId implements ChainIdParams {

@@ -22,3 +25,11 @@ static spec: IdentifierSpec = CAIP['2'];

/**
* Chain namespace, such as `evm`, `eip115`, `near`, `solana`, `tezos`, `algorand`,
* and `flow`
*/
readonly namespace: string;
/**
* Chain id or network name, such as `1`, `mainnet`, `testnet`, `ropsten`, and `edonet`
*/
readonly reference: string;

@@ -25,0 +36,0 @@

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

export * from './asset-name';
export * from './asset-name-id';
export * from './asset-type';

@@ -13,0 +14,0 @@ export * from './chain-id';

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

const tokenId = '[-a-zA-Z0-9._:]{1,32}';
/**
* Extension: we want to allow multiple token ids, such as `1-100` or `1,3,100`.
*/
const tokenId = '[-a-zA-Z0-9._:,]{1,32}';

@@ -41,2 +44,10 @@ const CAIP2: IdentifierSpec = {

// represents namespace:reference/tokenId in CAIP-19
const AssetNameId: IdentifierSpec = {
name: 'assetNameId',
regex: `${AssetName.regex}/(${tokenId})`,
properties: [AssetName, 'tokenId'],
delimiter: '/',
};
const CAIP19AssetType: IdentifierSpec = {

@@ -64,2 +75,3 @@ name: 'assetType',

assetName: AssetName,
assetNameId: AssetNameId,
assetType: CAIP19AssetType,

@@ -66,0 +78,0 @@ assetId: CAIP19AssetId,

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

/**
* Asset name and id
*/
export interface AssetNameIdParams {
assetName: string | AssetNameParams;
tokenId: string;
}
/**
* Asset type

@@ -69,5 +77,3 @@ */

*/
export interface AssetIdParams extends AssetTypeParams {
tokenId: string;
}
export interface AssetIdParams extends AssetTypeParams, AssetNameIdParams {}

@@ -74,0 +80,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

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