@collabland/chain
Advanced tools
Comparing version 0.29.0 to 0.30.0
@@ -158,3 +158,15 @@ "use strict"; | ||
async fetchMetadata(token, asset) { | ||
let metadata = await fetchTokenMetadata(token.uri); | ||
let metadata = token.metadata; | ||
try { | ||
metadata = await fetchTokenMetadata(token.uri); | ||
} | ||
catch (err) { | ||
if (token.metadata != null) { | ||
// Fall back to the cached metadata from Alchemy | ||
metadata = token.metadata; | ||
} | ||
else { | ||
throw err; | ||
} | ||
} | ||
if (metadata != null) { | ||
@@ -310,2 +322,5 @@ if (typeof metadata === 'string') { | ||
} | ||
// Some ipfs urls have `\x00`, let's remove them | ||
// ipfs://Qmd9yvE3JN2p2U9ehDmSWGnFsj4kEg5qXrP5DC2Wrt55v9/PALADIN\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/26 | ||
url = url.replace(/\x00/g, ''); | ||
const res = await fetch(url, { headers }); | ||
@@ -312,0 +327,0 @@ const metadata = await (0, common_1.handleFetchResponse)(res, 200, { |
@@ -16,2 +16,10 @@ "use strict"; | ||
class AccountId extends types_js_1.CAIPIdBase { | ||
static parse(id) { | ||
const { chainId: chainIdParams, address } = (0, utils_js_1.parseCaipId)(id, this.spec); | ||
const chainId = new chain_id_js_1.ChainId(chainIdParams); | ||
return new AccountId({ chainId, address }).toJSON(); | ||
} | ||
static format(params) { | ||
return (0, utils_js_1.formatCaipId)(params, this.spec); | ||
} | ||
constructor(params) { | ||
@@ -25,10 +33,2 @@ super(); | ||
} | ||
static parse(id) { | ||
const { chainId: chainIdParams, address } = (0, utils_js_1.parseCaipId)(id, this.spec); | ||
const chainId = new chain_id_js_1.ChainId(chainIdParams); | ||
return new AccountId({ chainId, address }).toJSON(); | ||
} | ||
static format(params) { | ||
return (0, utils_js_1.formatCaipId)(params, this.spec); | ||
} | ||
toString() { | ||
@@ -35,0 +35,0 @@ return AccountId.format(this.toJSON()); |
@@ -17,2 +17,8 @@ "use strict"; | ||
class AssetId extends asset_name_id_js_1.AssetNameId { | ||
static parse(id) { | ||
return new AssetId((0, utils_js_1.parseCaipId)(id, this.spec)).toJSON(); | ||
} | ||
static format(params) { | ||
return (0, utils_js_1.formatCaipId)(params, this.spec); | ||
} | ||
constructor(params) { | ||
@@ -25,8 +31,2 @@ if (typeof params === 'string') { | ||
} | ||
static parse(id) { | ||
return new AssetId((0, utils_js_1.parseCaipId)(id, this.spec)).toJSON(); | ||
} | ||
static format(params) { | ||
return (0, utils_js_1.formatCaipId)(params, this.spec); | ||
} | ||
[common_1.customInspectSymbol]() { | ||
@@ -33,0 +33,0 @@ return this.toString(); |
@@ -19,10 +19,2 @@ "use strict"; | ||
class AssetNameId extends types_js_1.CAIPIdBase { | ||
constructor(params) { | ||
super(); | ||
if (typeof params === 'string') { | ||
params = AssetNameId.parse(params); | ||
} | ||
this.assetName = new asset_name_js_1.AssetName(params.assetName); | ||
this.tokenId = (0, utils_js_1.decodeCaipParam)(params.tokenId); | ||
} | ||
static parse(id) { | ||
@@ -102,2 +94,10 @@ return new AssetNameId((0, utils_js_1.parseCaipId)(id, this.spec)).toJSON(); | ||
} | ||
constructor(params) { | ||
super(); | ||
if (typeof params === 'string') { | ||
params = AssetNameId.parse(params); | ||
} | ||
this.assetName = new asset_name_js_1.AssetName(params.assetName); | ||
this.tokenId = (0, utils_js_1.decodeCaipParam)(params.tokenId); | ||
} | ||
async resolveTokenIds() { | ||
@@ -104,0 +104,0 @@ if (this.resolvedTokenIds) |
@@ -15,2 +15,8 @@ "use strict"; | ||
class AssetName extends types_js_1.CAIPIdBase { | ||
static parse(id) { | ||
return new AssetName((0, utils_js_1.parseCaipId)(id, this.spec)).toJSON(); | ||
} | ||
static format(params) { | ||
return (0, utils_js_1.formatCaipId)(params, this.spec); | ||
} | ||
constructor(params) { | ||
@@ -24,8 +30,2 @@ super(); | ||
} | ||
static parse(id) { | ||
return new AssetName((0, utils_js_1.parseCaipId)(id, this.spec)).toJSON(); | ||
} | ||
static format(params) { | ||
return (0, utils_js_1.formatCaipId)(params, this.spec); | ||
} | ||
toString() { | ||
@@ -32,0 +32,0 @@ return AssetName.format(this.toJSON()); |
@@ -17,2 +17,8 @@ "use strict"; | ||
class AssetType extends types_js_1.CAIPIdBase { | ||
static parse(id) { | ||
return new AssetType((0, utils_js_1.parseCaipId)(id, this.spec)).toJSON(); | ||
} | ||
static format(params) { | ||
return (0, utils_js_1.formatCaipId)(params, this.spec); | ||
} | ||
constructor(params) { | ||
@@ -26,8 +32,2 @@ super(); | ||
} | ||
static parse(id) { | ||
return new AssetType((0, utils_js_1.parseCaipId)(id, this.spec)).toJSON(); | ||
} | ||
static format(params) { | ||
return (0, utils_js_1.formatCaipId)(params, this.spec); | ||
} | ||
toString() { | ||
@@ -34,0 +34,0 @@ return AssetType.format(this.toJSON()); |
@@ -15,2 +15,8 @@ "use strict"; | ||
class ChainId extends types_js_1.CAIPIdBase { | ||
static parse(id) { | ||
return new ChainId((0, utils_js_1.parseCaipId)(id, this.spec)).toJSON(); | ||
} | ||
static format(params) { | ||
return (0, utils_js_1.formatCaipId)(params, this.spec); | ||
} | ||
constructor(params) { | ||
@@ -24,8 +30,2 @@ super(); | ||
} | ||
static parse(id) { | ||
return new ChainId((0, utils_js_1.parseCaipId)(id, this.spec)).toJSON(); | ||
} | ||
static format(params) { | ||
return (0, utils_js_1.formatCaipId)(params, this.spec); | ||
} | ||
toString() { | ||
@@ -32,0 +32,0 @@ return ChainId.format(this.toJSON()); |
@@ -15,4 +15,4 @@ export * from './account-id.js'; | ||
import { AccountIdParams, AssetIdParams, AssetNameParams, AssetTypeParams, ChainIdParams } from './types.js'; | ||
export declare type CAIPId = AssetId | AssetType | AccountId | ChainId; | ||
export declare type CAIPIdParams = AssetIdParams | AssetTypeParams | AccountIdParams | ChainIdParams; | ||
export type CAIPId = AssetId | AssetType | AccountId | ChainId; | ||
export type CAIPIdParams = AssetIdParams | AssetTypeParams | AccountIdParams | ChainIdParams; | ||
export declare const CAIPTypes: (typeof ChainId | typeof AccountId | typeof AssetType)[]; | ||
@@ -37,5 +37,5 @@ /** | ||
export declare function getChainId(id: CAIPIdParams | string): ChainId; | ||
export declare type CAIPIdParamsType<T extends CAIPId> = T extends AssetId ? AssetIdParams : T extends AssetType ? AssetTypeParams : T extends AccountId ? AccountIdParams : T extends ChainId ? ChainIdParams : T extends AssetName ? AssetNameParams : never; | ||
export declare type CAIPIdType<T extends CAIPIdParams> = T extends AssetIdParams ? AssetId : T extends AssetTypeParams ? AssetType : T extends AccountIdParams ? AccountId : T extends ChainIdParams ? ChainId : T extends AssetNameParams ? AssetName : never; | ||
export declare type Asset = AssetId | AssetType; | ||
export type CAIPIdParamsType<T extends CAIPId> = T extends AssetId ? AssetIdParams : T extends AssetType ? AssetTypeParams : T extends AccountId ? AccountIdParams : T extends ChainId ? ChainIdParams : T extends AssetName ? AssetNameParams : never; | ||
export type CAIPIdType<T extends CAIPIdParams> = T extends AssetIdParams ? AssetId : T extends AssetTypeParams ? AssetType : T extends AccountIdParams ? AccountId : T extends ChainIdParams ? ChainId : T extends AssetNameParams ? AssetName : never; | ||
export type Asset = AssetId | AssetType; | ||
export declare function getTokenId(asset: string | CAIPIdParamsType<Asset>): string | undefined; |
@@ -26,3 +26,3 @@ import { customInspectSymbol } from '@collabland/common'; | ||
*/ | ||
export declare type IdParams = Record<string, string | Record<string, string>>; | ||
export type IdParams = Record<string, string | Record<string, string>>; | ||
/** | ||
@@ -71,3 +71,3 @@ * Chain id parameters | ||
*/ | ||
export declare type AssetParams = AssetIdParams | AssetTypeParams; | ||
export type AssetParams = AssetIdParams | AssetTypeParams; | ||
/** | ||
@@ -74,0 +74,0 @@ * Type guide for chain id |
@@ -6,3 +6,3 @@ import { AccountId, AccountIdParams, AssetId, AssetIdParams, AssetParams, AssetType, AssetTypeParams, CAIPId, CAIPIdParams, CAIPIdParamsType, ChainId, ChainIdParams } from './caip/index.js'; | ||
*/ | ||
export declare type ChainResourceParams<T extends CAIPIdParams = CAIPIdParams> = T & { | ||
export type ChainResourceParams<T extends CAIPIdParams = CAIPIdParams> = T & { | ||
options?: ChainOptions; | ||
@@ -13,3 +13,3 @@ }; | ||
*/ | ||
export declare type ChainResource<T extends CAIPId = CAIPId> = ChainResourceParams<T> & ChainResourceParams<CAIPIdParamsType<T>> & { | ||
export type ChainResource<T extends CAIPId = CAIPId> = ChainResourceParams<T> & ChainResourceParams<CAIPIdParamsType<T>> & { | ||
/** | ||
@@ -99,3 +99,3 @@ * Chain id for the resource | ||
*/ | ||
export declare type ChainResourceId<T extends CAIPIdParams = CAIPIdParams> = ChainResourceParams<T> | string; | ||
export type ChainResourceId<T extends CAIPIdParams = CAIPIdParams> = ChainResourceParams<T> | string; | ||
/** | ||
@@ -131,6 +131,6 @@ * Build an account id resource | ||
*/ | ||
export declare type AssetResource = AssetTypeResource | AssetIdResource; | ||
export type AssetResource = AssetTypeResource | AssetIdResource; | ||
/** | ||
* Asset resource id (type or id) | ||
*/ | ||
export declare type AssetResourceId = ChainResourceId<AssetParams>; | ||
export type AssetResourceId = ChainResourceId<AssetParams>; |
@@ -12,11 +12,11 @@ /** | ||
*/ | ||
export declare type PublicKey = string | Uint8Array; | ||
export type PublicKey = string | Uint8Array; | ||
/** | ||
* Private key | ||
*/ | ||
export declare type PrivateKey = string | Uint8Array; | ||
export type PrivateKey = string | Uint8Array; | ||
/** | ||
* Signature | ||
*/ | ||
export declare type Signature = string | Uint8Array; | ||
export type Signature = string | Uint8Array; | ||
/** | ||
@@ -23,0 +23,0 @@ * Crypto key pair |
@@ -52,3 +52,3 @@ import { AnyType, BigNumber, BigNumberish } from '@collabland/common'; | ||
*/ | ||
export declare type Chain = ChainIdResource; | ||
export type Chain = ChainIdResource; | ||
export declare const ETHEREUM_MAINNET: ChainIdResource; | ||
@@ -60,15 +60,15 @@ export declare const ETHEREUM_ROPSTEN: ChainIdResource; | ||
*/ | ||
export declare type Amount = BigNumberish; | ||
export type Amount = BigNumberish; | ||
/** | ||
* Default type for token ids | ||
*/ | ||
export declare type TokenId = string | number | bigint | BigNumber; | ||
export type TokenId = string | number | bigint | BigNumber; | ||
/** | ||
* Metadata for an asset type | ||
*/ | ||
export declare type AssetMetadata = Record<string, any>; | ||
export type AssetMetadata = Record<string, any>; | ||
/** | ||
* Default type for token metadata | ||
*/ | ||
export declare type TokenMetadata = Record<string, any>; | ||
export type TokenMetadata = Record<string, any>; | ||
export interface NativeCurrency { | ||
@@ -118,2 +118,6 @@ name: string; | ||
royalty?: boolean; | ||
/** | ||
* Other attributes for the request | ||
*/ | ||
[prop: string]: AnyType; | ||
} | ||
@@ -120,0 +124,0 @@ /** |
{ | ||
"name": "@collabland/chain", | ||
"version": "0.29.0", | ||
"version": "0.30.0", | ||
"description": "CollabLand Ethereum Integration", | ||
@@ -25,15 +25,15 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@collabland/common": "^0.38.0", | ||
"@collabland/common": "^0.39.0", | ||
"is-ipfs": "^6.0.2", | ||
"json-fixer": "^1.6.15", | ||
"parse-data-url": "^4.0.1", | ||
"parse-data-url": "^5.0.0", | ||
"tslib": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@loopback/build": "^9.0.4", | ||
"@loopback/eslint-config": "^13.0.4", | ||
"@loopback/testlab": "^5.0.4", | ||
"@types/node": "^18.11.7", | ||
"@loopback/build": "^9.0.6", | ||
"@loopback/eslint-config": "^13.0.6", | ||
"@loopback/testlab": "^5.0.6", | ||
"@types/node": "^18.11.15", | ||
"@types/parse-data-url": "^3.0.0", | ||
"typescript": "~4.8.4" | ||
"typescript": "~4.9.4" | ||
}, | ||
@@ -51,3 +51,3 @@ "license": "MIT", | ||
"author": "Abridged, Inc.", | ||
"gitHead": "bbbaf2dc89b65714e903a863d8373acd836347d5" | ||
"gitHead": "69d7df64a006d25a72431f783558626457b5a09d" | ||
} |
@@ -243,3 +243,13 @@ // Copyright Abridged, Inc. 2021. All Rights Reserved. | ||
async fetchMetadata(token: TokenAsset<TID, M, AMT>, asset: AssetType) { | ||
let metadata = await fetchTokenMetadata<M>(token.uri); | ||
let metadata = token.metadata; | ||
try { | ||
metadata = await fetchTokenMetadata<M>(token.uri); | ||
} catch (err) { | ||
if (token.metadata != null) { | ||
// Fall back to the cached metadata from Alchemy | ||
metadata = token.metadata; | ||
} else { | ||
throw err; | ||
} | ||
} | ||
if (metadata != null) { | ||
@@ -249,3 +259,3 @@ if (typeof metadata === 'string') { | ||
// Some metadata is malformed json - trying to fix it | ||
metadata = jsonFix(metadata).data as Record<string, AnyType>; | ||
metadata = jsonFix(metadata).data as M; | ||
} catch (err) { | ||
@@ -417,2 +427,5 @@ // Ignore | ||
} | ||
// Some ipfs urls have `\x00`, let's remove them | ||
// ipfs://Qmd9yvE3JN2p2U9ehDmSWGnFsj4kEg5qXrP5DC2Wrt55v9/PALADIN\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/26 | ||
url = url.replace(/\x00/g, ''); | ||
const res = await fetch(url, {headers}); | ||
@@ -419,0 +432,0 @@ const metadata = await handleFetchResponse<M>(res, 200, { |
@@ -162,2 +162,7 @@ // Copyright Abridged, Inc. 2021. All Rights Reserved. | ||
royalty?: boolean; | ||
/** | ||
* Other attributes for the request | ||
*/ | ||
[prop: string]: AnyType; | ||
} | ||
@@ -164,0 +169,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
165763
4164
+ Added@collabland/common@0.39.2(transitive)
+ Added@types/jsonwebtoken@9.0.7(transitive)
+ Added@types/qrcode@1.5.5(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedcliui@6.0.0(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addeddijkstrajs@1.0.3(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedjsonata@2.0.6(transitive)
+ Addedjsonwebtoken@9.0.2(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedparse-data-url@5.0.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpngjs@5.0.0(transitive)
+ Addedqrcode@1.5.4(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@2.0.0(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@6.2.0(transitive)
+ Addedy18n@4.0.3(transitive)
+ Addedyargs@15.4.1(transitive)
+ Addedyargs-parser@18.1.3(transitive)
- Removed@collabland/common@0.38.0(transitive)
- Removed@types/jsonwebtoken@8.5.9(transitive)
- Removedjsonata@1.8.7(transitive)
- Removedjsonwebtoken@8.5.1(transitive)
- Removedparse-data-url@4.0.1(transitive)
- Removedsemver@5.7.2(transitive)
Updated@collabland/common@^0.39.0
Updatedparse-data-url@^5.0.0