@vleap/warps 0.0.49 → 0.0.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { Transaction, TypedValue } from '@multiversx/sdk-core/out';
2
- import { Transaction as Transaction$1, TransactionOnNetwork } from '@multiversx/sdk-core';
1
+ import { Transaction, TransactionOnNetwork } from '@multiversx/sdk-core';
2
+ import { Transaction as Transaction$1, TypedValue } from '@multiversx/sdk-core/out';
3
3
  import QRCodeStyling from 'qr-code-styling';
4
4
 
5
5
  type ChainEnv = 'mainnet' | 'testnet' | 'devnet';
@@ -99,6 +99,33 @@ type Brand = {
99
99
  };
100
100
  };
101
101
 
102
+ declare class BrandBuilder {
103
+ private config;
104
+ private pendingBrand;
105
+ constructor(config: WarpConfig);
106
+ createInscriptionTransaction(brand: Brand): Transaction;
107
+ createFromRaw(encoded: string, validateSchema?: boolean): Promise<Brand>;
108
+ createFromTransaction(tx: TransactionOnNetwork, validateSchema?: boolean): Promise<Brand>;
109
+ createFromTransactionHash(hash: string): Promise<Brand | null>;
110
+ setName(name: string): BrandBuilder;
111
+ setDescription(description: string): BrandBuilder;
112
+ setLogo(logo: string): BrandBuilder;
113
+ setWebsite(website: string): BrandBuilder;
114
+ setColors(colors: {
115
+ primary?: string;
116
+ secondary?: string;
117
+ }): BrandBuilder;
118
+ setCta(cta: {
119
+ title: string;
120
+ description: string;
121
+ label: string;
122
+ url: string;
123
+ }): BrandBuilder;
124
+ build(): Promise<Brand>;
125
+ private ensure;
126
+ private ensureValidSchema;
127
+ }
128
+
102
129
  declare const Config: {
103
130
  ProtocolNameWarp: string;
104
131
  ProtocolNameBrand: string;
@@ -121,7 +148,7 @@ declare class WarpActionExecutor {
121
148
  private config;
122
149
  private url;
123
150
  constructor(config: WarpConfig, url: string);
124
- createTransactionForExecute(action: WarpContractAction): Transaction;
151
+ createTransactionForExecute(action: WarpContractAction): Transaction$1;
125
152
  getPositionValueFromUrl(action: WarpAction, position: WarpActionInputPosition): string | null;
126
153
  getTypedArgsWithInputs(action: WarpContractAction): TypedValue[];
127
154
  private toTypedArg;
@@ -129,12 +156,13 @@ declare class WarpActionExecutor {
129
156
 
130
157
  declare class WarpBuilder {
131
158
  private config;
159
+ private cache;
132
160
  private pendingWarp;
133
161
  constructor(config: WarpConfig);
134
- createInscriptionTransaction(warp: Warp): Transaction$1;
162
+ createInscriptionTransaction(warp: Warp): Transaction;
135
163
  createFromRaw(encoded: string, validateSchema?: boolean): Promise<Warp>;
136
164
  createFromTransaction(tx: TransactionOnNetwork, validateSchema?: boolean): Promise<Warp>;
137
- createFromTransactionHash(hash: string): Promise<Warp | null>;
165
+ createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<Warp | null>;
138
166
  setName(name: string): WarpBuilder;
139
167
  setTitle(title: string): WarpBuilder;
140
168
  setDescription(description: string): WarpBuilder;
@@ -160,13 +188,14 @@ declare class WarpLink {
160
188
 
161
189
  declare class WarpRegistry {
162
190
  private config;
163
- private registerCost;
191
+ private unitPrice;
164
192
  private cache;
165
193
  constructor(config: WarpConfig);
166
194
  init(): Promise<void>;
167
- createRegisterTransaction(txHash: string, alias?: string | null): Transaction;
168
- createAliasAssignTransaction(txHash: string, alias: string): Transaction;
169
- createPublishTransaction(txHash: string): Transaction;
195
+ createRegisterWarpTransaction(txHash: string, alias?: string | null): Transaction$1;
196
+ createRegisterBrandTransaction(txHash: string): Transaction$1;
197
+ createAliasAssignTransaction(txHash: string, alias: string): Transaction$1;
198
+ createPublishWarpTransaction(txHash: string): Transaction$1;
170
199
  getInfoByAlias(alias: string, cache?: WarpCacheConfig): Promise<{
171
200
  warp: WarpInfo | null;
172
201
  brand: Brand | null;
@@ -182,4 +211,4 @@ declare class WarpRegistry {
182
211
  private getController;
183
212
  }
184
213
 
185
- export { type Brand, type ChainEnv, Config, type TrustStatus, type Warp, type WarpAction, type WarpActionExecutionResult, WarpActionExecutor, type WarpActionInput, type WarpActionInputPosition, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpCacheConfig, type WarpConfig, type WarpContractAction, type WarpIdType, type WarpInfo, WarpLink, type WarpLinkAction, type WarpMeta, WarpRegistry };
214
+ export { type Brand, BrandBuilder, type ChainEnv, Config, type TrustStatus, type Warp, type WarpAction, type WarpActionExecutionResult, WarpActionExecutor, type WarpActionInput, type WarpActionInputPosition, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpCacheConfig, type WarpConfig, type WarpContractAction, type WarpIdType, type WarpInfo, WarpLink, type WarpLinkAction, type WarpMeta, WarpRegistry };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Transaction, TypedValue } from '@multiversx/sdk-core/out';
2
- import { Transaction as Transaction$1, TransactionOnNetwork } from '@multiversx/sdk-core';
1
+ import { Transaction, TransactionOnNetwork } from '@multiversx/sdk-core';
2
+ import { Transaction as Transaction$1, TypedValue } from '@multiversx/sdk-core/out';
3
3
  import QRCodeStyling from 'qr-code-styling';
4
4
 
5
5
  type ChainEnv = 'mainnet' | 'testnet' | 'devnet';
@@ -99,6 +99,33 @@ type Brand = {
99
99
  };
100
100
  };
101
101
 
102
+ declare class BrandBuilder {
103
+ private config;
104
+ private pendingBrand;
105
+ constructor(config: WarpConfig);
106
+ createInscriptionTransaction(brand: Brand): Transaction;
107
+ createFromRaw(encoded: string, validateSchema?: boolean): Promise<Brand>;
108
+ createFromTransaction(tx: TransactionOnNetwork, validateSchema?: boolean): Promise<Brand>;
109
+ createFromTransactionHash(hash: string): Promise<Brand | null>;
110
+ setName(name: string): BrandBuilder;
111
+ setDescription(description: string): BrandBuilder;
112
+ setLogo(logo: string): BrandBuilder;
113
+ setWebsite(website: string): BrandBuilder;
114
+ setColors(colors: {
115
+ primary?: string;
116
+ secondary?: string;
117
+ }): BrandBuilder;
118
+ setCta(cta: {
119
+ title: string;
120
+ description: string;
121
+ label: string;
122
+ url: string;
123
+ }): BrandBuilder;
124
+ build(): Promise<Brand>;
125
+ private ensure;
126
+ private ensureValidSchema;
127
+ }
128
+
102
129
  declare const Config: {
103
130
  ProtocolNameWarp: string;
104
131
  ProtocolNameBrand: string;
@@ -121,7 +148,7 @@ declare class WarpActionExecutor {
121
148
  private config;
122
149
  private url;
123
150
  constructor(config: WarpConfig, url: string);
124
- createTransactionForExecute(action: WarpContractAction): Transaction;
151
+ createTransactionForExecute(action: WarpContractAction): Transaction$1;
125
152
  getPositionValueFromUrl(action: WarpAction, position: WarpActionInputPosition): string | null;
126
153
  getTypedArgsWithInputs(action: WarpContractAction): TypedValue[];
127
154
  private toTypedArg;
@@ -129,12 +156,13 @@ declare class WarpActionExecutor {
129
156
 
130
157
  declare class WarpBuilder {
131
158
  private config;
159
+ private cache;
132
160
  private pendingWarp;
133
161
  constructor(config: WarpConfig);
134
- createInscriptionTransaction(warp: Warp): Transaction$1;
162
+ createInscriptionTransaction(warp: Warp): Transaction;
135
163
  createFromRaw(encoded: string, validateSchema?: boolean): Promise<Warp>;
136
164
  createFromTransaction(tx: TransactionOnNetwork, validateSchema?: boolean): Promise<Warp>;
137
- createFromTransactionHash(hash: string): Promise<Warp | null>;
165
+ createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<Warp | null>;
138
166
  setName(name: string): WarpBuilder;
139
167
  setTitle(title: string): WarpBuilder;
140
168
  setDescription(description: string): WarpBuilder;
@@ -160,13 +188,14 @@ declare class WarpLink {
160
188
 
161
189
  declare class WarpRegistry {
162
190
  private config;
163
- private registerCost;
191
+ private unitPrice;
164
192
  private cache;
165
193
  constructor(config: WarpConfig);
166
194
  init(): Promise<void>;
167
- createRegisterTransaction(txHash: string, alias?: string | null): Transaction;
168
- createAliasAssignTransaction(txHash: string, alias: string): Transaction;
169
- createPublishTransaction(txHash: string): Transaction;
195
+ createRegisterWarpTransaction(txHash: string, alias?: string | null): Transaction$1;
196
+ createRegisterBrandTransaction(txHash: string): Transaction$1;
197
+ createAliasAssignTransaction(txHash: string, alias: string): Transaction$1;
198
+ createPublishWarpTransaction(txHash: string): Transaction$1;
170
199
  getInfoByAlias(alias: string, cache?: WarpCacheConfig): Promise<{
171
200
  warp: WarpInfo | null;
172
201
  brand: Brand | null;
@@ -182,4 +211,4 @@ declare class WarpRegistry {
182
211
  private getController;
183
212
  }
184
213
 
185
- export { type Brand, type ChainEnv, Config, type TrustStatus, type Warp, type WarpAction, type WarpActionExecutionResult, WarpActionExecutor, type WarpActionInput, type WarpActionInputPosition, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpCacheConfig, type WarpConfig, type WarpContractAction, type WarpIdType, type WarpInfo, WarpLink, type WarpLinkAction, type WarpMeta, WarpRegistry };
214
+ export { type Brand, BrandBuilder, type ChainEnv, Config, type TrustStatus, type Warp, type WarpAction, type WarpActionExecutionResult, WarpActionExecutor, type WarpActionInput, type WarpActionInputPosition, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpCacheConfig, type WarpConfig, type WarpContractAction, type WarpIdType, type WarpInfo, WarpLink, type WarpLinkAction, type WarpMeta, WarpRegistry };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var E=Object.create;var W=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var O=(n,t)=>{for(var r in t)W(n,r,{get:t[r],enumerable:!0})},P=(n,t,r,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of N(t))!Q.call(n,i)&&i!==r&&W(n,i,{get:()=>t[i],enumerable:!(e=V(t,i))||e.enumerable});return n};var q=(n,t,r)=>(r=n!=null?E(D(n)):{},P(t||!n||!n.__esModule?W(r,"default",{value:n,enumerable:!0}):r,n)),$=n=>P(W({},"__esModule",{value:!0}),n);var _={};O(_,{Config:()=>u,WarpActionExecutor:()=>I,WarpBuilder:()=>y,WarpLink:()=>U,WarpRegistry:()=>w});module.exports=$(_);var u={ProtocolNameWarp:"warp",ProtocolNameBrand:"warp-brand",LatestProtocolVersion:"0.1.0",LatestWarpSchemaUrl:"https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/v0.1.0.schema.json",LatestBrandSchemaUrl:"https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/brand/v0.1.0.schema.json",DefaultClientUrl:n=>n==="devnet"?"https://devnet.xwarp.me/to":n==="testnet"?"###Not implemented###":"https://xwarp.me/to",Chain:{ApiUrl:n=>n==="devnet"?"https://devnet-api.multiversx.com":n==="testnet"?"https://testnet-api.multiversx.com":"https://api.multiversx.com"},Registry:{Contract:n=>n==="devnet"?"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36":n==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"},AvailableActionInputSources:["field","query"],AvailableActionInputTypes:["string","uint8","uint16","uint32","uint64","biguint","boolean","address"],AvailableActionInputPositions:["value","arg:1","arg:2","arg:3","arg:4","arg:5","arg:6","arg:7","arg:8","arg:9","arg:10"]};var o=require("@multiversx/sdk-core/out");var f=n=>n==="devnet"?"D":n==="testnet"?"T":"1",R=n=>`${n}:${u.LatestProtocolVersion}`,C=n=>{var t,r;return{hash:n.hash.toString("hex"),alias:((t=n.alias)==null?void 0:t.toString())||null,trust:n.trust.toString(),creator:n.creator.toString(),createdAt:n.created_at.toNumber(),brand:((r=n.brand)==null?void 0:r.toString())||null}};var I=class{config;url;constructor(t,r){this.config=t,this.url=new URL(r)}createTransactionForExecute(t){if(!this.config.userAddress)throw new Error("WarpActionExecutor: user address not set");let r=new o.TransactionsFactoryConfig({chainID:f(this.config.env)}),e=new o.SmartContractTransactionsFactory({config:r}),i=this.getTypedArgsWithInputs(t),a=this.getPositionValueFromUrl(t,"value"),c=BigInt(a||t.value||0);return e.createTransactionForExecute({sender:o.Address.newFromBech32(this.config.userAddress),contract:o.Address.newFromBech32(t.address),function:t.func||"",gasLimit:BigInt(t.gasLimit),arguments:i,nativeTransferAmount:c})}getPositionValueFromUrl(t,r){var c,l;let e=new URLSearchParams(this.url.search),i=(c=t.inputs)==null?void 0:c.filter(g=>g.source==="query"),a=(l=i==null?void 0:i.find(g=>g.position===r))==null?void 0:l.name;return a?e.get(a):null}getTypedArgsWithInputs(t){return t.args.map(r=>{let[e,i]=r.split(":");return this.toTypedArg(i,e)})}toTypedArg(t,r){if(r==="string")return o.BytesValue.fromUTF8(t);if(r==="uint8")return new o.U8Value(Number(t));if(r==="uint16")return new o.U16Value(Number(t));if(r==="uint32")return new o.U32Value(Number(t));if(r==="uint64")return new o.U64Value(BigInt(t));if(r==="biguint")return new o.BigUIntValue(BigInt(t));if(r==="boolean")return new o.BooleanValue(t==="true");if(r==="address")return new o.AddressValue(o.Address.newFromBech32(t));if(r==="hex")return o.BytesValue.fromHex(t);throw new Error(`WarpActionExecutor: Unsupported input type: ${r}`)}};var h=require("@multiversx/sdk-core"),F=q(require("ajv"));var y=class{config;pendingWarp={protocol:R(u.ProtocolNameWarp),name:"",title:"",description:null,preview:"",actions:[]};constructor(t){this.config=t}createInscriptionTransaction(t){if(!this.config.userAddress)throw new Error("WarpBuilder: user address not set");let r=new h.TransactionsFactoryConfig({chainID:f(this.config.env)}),e=new h.TransferTransactionsFactory({config:r}),i=JSON.stringify(t);return e.createTransactionForNativeTokenTransfer({sender:h.Address.newFromBech32(this.config.userAddress),receiver:h.Address.newFromBech32(this.config.userAddress),nativeAmount:BigInt(0),data:Buffer.from(i).valueOf()})}async createFromRaw(t,r=!0){let e=JSON.parse(t);return r&&await this.ensureValidSchema(e),e}async createFromTransaction(t,r=!1){let e=await this.createFromRaw(t.data.toString(),r);return e.meta={hash:t.hash,creator:t.sender.bech32(),createdAt:new Date(t.timestamp).toISOString()},e}async createFromTransactionHash(t){let r=new h.ApiNetworkProvider(this.config.chainApiUrl||u.Chain.ApiUrl(this.config.env));try{let e=await r.getTransaction(t);return this.createFromTransaction(e)}catch(e){return console.error("WarpBuilder: Error creating from transaction hash",e),null}}setName(t){return this.pendingWarp.name=t,this}setTitle(t){return this.pendingWarp.title=t,this}setDescription(t){return this.pendingWarp.description=t,this}setPreview(t){return this.pendingWarp.preview=t,this}setActions(t){return this.pendingWarp.actions=t,this}addAction(t){return this.pendingWarp.actions.push(t),this}async build(){return this.ensure(this.pendingWarp.protocol,"protocol is required"),this.ensure(this.pendingWarp.name,"name is required"),this.ensure(this.pendingWarp.title,"title is required"),this.ensure(this.pendingWarp.actions.length>0,"actions are required"),await this.ensureValidSchema(this.pendingWarp),this.pendingWarp}ensure(t,r){if(!t)throw new Error(`WarpBuilder: ${r}`)}async ensureValidSchema(t){let r=this.config.warpSchemaUrl||u.LatestWarpSchemaUrl,i=await(await fetch(r)).json(),a=new F.default,c=a.compile(i);if(!c(t))throw new Error(`WarpBuilder: schema validation failed: ${a.errorsText(c.errors)}`)}};var L=q(require("qr-code-styling"));var s=require("@multiversx/sdk-core/out");var T={buildInfo:{rustc:{version:"1.80.0-nightly",commitHash:"791adf759cc065316f054961875052d5bc03e16c",commitDate:"2024-05-21",channel:"Nightly",short:"rustc 1.80.0-nightly (791adf759 2024-05-21)"},contractCrate:{name:"registry",version:"0.0.1"},framework:{name:"multiversx-sc",version:"0.50.6"}},name:"RegistryContract",constructor:{inputs:[{name:"unit_price",type:"BigUint"}],outputs:[]},upgradeConstructor:{inputs:[],outputs:[]},endpoints:[{name:"registerWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[]},{name:"publishWarp",mutability:"mutable",inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"assignAlias",mutability:"mutable",inputs:[{name:"alias",type:"bytes"}],outputs:[]},{name:"getUserWarps",mutability:"readonly",inputs:[{name:"address",type:"Address"}],outputs:[{type:"variadic<WarpInfoView>",multi_result:!0}]},{name:"getInfoByAlias",mutability:"readonly",inputs:[{name:"alias",type:"bytes"}],outputs:[{type:"WarpInfoView"}]},{name:"getInfoByHash",mutability:"readonly",inputs:[{name:"hash",type:"bytes"}],outputs:[{type:"WarpInfoView"}]},{name:"setUnitPrice",onlyOwner:!0,mutability:"mutable",inputs:[{name:"amount",type:"BigUint"}],outputs:[]},{name:"getConfig",mutability:"readonly",inputs:[],outputs:[{type:"BigUint"}]}],events:[{identifier:"warpRegistered",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0}]}],esdtAttributes:[],hasCallback:!1,types:{WarpInfoView:{type:"struct",fields:[{name:"hash",type:"bytes"},{name:"alias",type:"Option<bytes>"},{name:"trust",type:"bytes"},{name:"creator",type:"Address"},{name:"created_at",type:"u64"}]}}};var A={WarpInfo:n=>`warp-info:${n}`,Brand:n=>`brand:${n}`},v=class{cache=new Map;set(t,r,e){let i=Date.now()+e*1e3;this.cache.set(t,{value:r,expiresAt:i})}get(t){let r=this.cache.get(t);return r?Date.now()>r.expiresAt?(this.cache.delete(t),null):r.value:null}clear(){this.cache.clear()}};var w=class{config;registerCost;cache=new v;constructor(t){this.config=t,this.registerCost=BigInt(0)}async init(){await this.loadRegistryConfigs()}createRegisterTransaction(t,r){if(this.registerCost===BigInt(0))throw new Error("registry config not loaded. forgot to call init()?");if(!this.config.userAddress)throw new Error("registry config user address not set");let e=r?this.registerCost*BigInt(2):this.registerCost;return this.getFactory().createTransactionForExecute({sender:s.Address.newFromBech32(this.config.userAddress),contract:s.Address.newFromBech32(u.Registry.Contract(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:e,arguments:r?[s.BytesValue.fromHex(t),s.BytesValue.fromUTF8(r)]:[s.BytesValue.fromHex(t)]})}createAliasAssignTransaction(t,r){if(!this.config.userAddress)throw new Error("registry config user address not set");return this.getFactory().createTransactionForExecute({sender:s.Address.newFromBech32(this.config.userAddress),contract:s.Address.newFromBech32(u.Registry.Contract(this.config.env)),function:"assignAlias",gasLimit:BigInt(1e7),arguments:[s.BytesValue.fromHex(t),s.BytesValue.fromUTF8(r)]})}createPublishTransaction(t){if(!this.config.userAddress)throw new Error("registry config user address not set");return this.getFactory().createTransactionForExecute({sender:s.Address.newFromBech32(this.config.userAddress),contract:s.Address.newFromBech32(u.Registry.Contract(this.config.env)),function:"publishRegistry",gasLimit:BigInt(1e7),arguments:[s.BytesValue.fromHex(t)]})}async getInfoByAlias(t,r){let e=A.WarpInfo(t);if(r){let d=this.cache.get(e);if(d)return d}let i=u.Registry.Contract(this.config.env),a=this.getController(),c=a.createQuery({contract:i,function:"getInfoByAlias",arguments:[s.BytesValue.fromUTF8(t)]}),l=await a.runQuery(c),[g]=a.parseQueryResponse(l),p=g?C(g):null,m=p!=null&&p.brand?await this.fetchBrand(p.brand):null;return r&&r.ttl&&this.cache.set(e,{warp:p,brand:m},r.ttl),{warp:p,brand:m}}async getInfoByHash(t,r){let e=A.WarpInfo(t);if(r){let d=this.cache.get(e);if(d)return d}let i=u.Registry.Contract(this.config.env),a=this.getController(),c=a.createQuery({contract:i,function:"getInfoByHash",arguments:[s.BytesValue.fromUTF8(t)]}),l=await a.runQuery(c),[g]=a.parseQueryResponse(l),p=g?C(g):null,m=p!=null&&p.brand?await this.fetchBrand(p.brand):null;return r&&r.ttl&&this.cache.set(e,{warp:p,brand:m},r.ttl),{warp:p,brand:m}}async getUserWarpInfos(t){let r=t||this.config.userAddress;if(!r)throw new Error("WarpRegistry: user address not set");let e=u.Registry.Contract(this.config.env),i=this.getController(),a=i.createQuery({contract:e,function:"getUserWarps",arguments:[new s.AddressValue(new s.Address(r))]}),c=await i.runQuery(a);return i.parseQueryResponse(c).map(C)}async fetchBrand(t,r){let e=A.Brand(t);if(r){let a=this.cache.get(e);if(a)return a}let i=new s.ApiNetworkProvider(this.config.chainApiUrl||u.Chain.ApiUrl(this.config.env));try{let a=await i.getTransaction(t),c=JSON.parse(a.data.toString());return r&&r.ttl&&this.cache.set(e,c,r.ttl),c}catch(a){return console.error("Error fetching brand from transaction hash",a),null}}async loadRegistryConfigs(){let t=u.Registry.Contract(this.config.env),r=this.getController(),e=r.createQuery({contract:t,function:"getConfig",arguments:[]}),i=await r.runQuery(e),[a]=r.parseQueryResponse(i),c=BigInt(a.toString());this.registerCost=c}getFactory(){let t=new s.TransactionsFactoryConfig({chainID:f(this.config.env)}),r=s.AbiRegistry.create(T);return new s.SmartContractTransactionsFactory({config:t,abi:r})}getController(){let t=this.config.chainApiUrl||u.Chain.ApiUrl(this.config.env),r=new s.ApiNetworkProvider(t,{timeout:3e4}),e=new s.QueryRunnerAdapter({networkProvider:r}),i=s.AbiRegistry.create(T);return new s.SmartContractQueriesController({queryRunner:e,abi:i})}};var B="xwarp",b=":",S="alias",U=class{constructor(t){this.config=t;this.config=t}async detect(t){let i=new URL(t).searchParams.get(B);if(!i)return{match:!1,warp:null};let a=decodeURIComponent(i),c=a.includes(b)?a:`${S}${b}${a}`,[l,g]=c.split(b),p=new y(this.config),m=new w(this.config),d=null;if(l==="hash")d=await p.createFromTransactionHash(g);else if(l==="alias"){let{warp:x}=await m.getInfoByAlias(g);x&&(d=await p.createFromTransactionHash(x.hash))}return d?{match:!0,warp:d}:{match:!1,warp:null}}build(t,r){let e=this.config.clientUrl||u.DefaultClientUrl(this.config.env);return t===S?`${e}?${B}=${encodeURIComponent(r)}`:`${e}?${B}=${encodeURIComponent(t+b+r)}`}generateQrCode(t,r,e=512,i="white",a="black",c="#23F7DD"){let l=this.build(t,r);return new L.default({type:"svg",width:e,height:e,data:String(l),margin:16,qrOptions:{typeNumber:0,mode:"Byte",errorCorrectionLevel:"Q"},backgroundOptions:{color:i},dotsOptions:{type:"extra-rounded",color:a},cornersSquareOptions:{type:"extra-rounded",color:a},cornersDotOptions:{type:"square",color:a},imageOptions:{hideBackgroundDots:!0,imageSize:.4,margin:8},image:`data:image/svg+xml;utf8,<svg width="16" height="16" viewBox="0 0 100 100" fill="${encodeURIComponent(c)}" xmlns="http://www.w3.org/2000/svg"><path d="M54.8383 50.0242L95 28.8232L88.2456 16L51.4717 30.6974C50.5241 31.0764 49.4759 31.0764 48.5283 30.6974L11.7544 16L5 28.8232L45.1616 50.0242L5 71.2255L11.7544 84.0488L48.5283 69.351C49.4759 68.9724 50.5241 68.9724 51.4717 69.351L88.2456 84.0488L95 71.2255L54.8383 50.0242Z"/></svg>`})}};0&&(module.exports={Config,WarpActionExecutor,WarpBuilder,WarpLink,WarpRegistry});
1
+ "use strict";var $=Object.create;var C=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var Q=(n,r)=>{for(var t in r)C(n,t,{get:r[t],enumerable:!0})},S=(n,r,t,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of O(r))!_.call(n,i)&&i!==t&&C(n,i,{get:()=>r[i],enumerable:!(e=D(r,i))||e.enumerable});return n};var I=(n,r,t)=>(t=n!=null?$(k(n)):{},S(r||!n||!n.__esModule?C(t,"default",{value:n,enumerable:!0}):t,n)),H=n=>S(C({},"__esModule",{value:!0}),n);var K={};Q(K,{BrandBuilder:()=>P,Config:()=>u,WarpActionExecutor:()=>F,WarpBuilder:()=>B,WarpLink:()=>x,WarpRegistry:()=>v});module.exports=H(K);var h=require("@multiversx/sdk-core"),L=I(require("ajv"));var u={ProtocolNameWarp:"warp",ProtocolNameBrand:"warp-brand",LatestProtocolVersion:"0.1.0",LatestWarpSchemaUrl:"https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/v0.1.0.schema.json",LatestBrandSchemaUrl:"https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/brand/v0.1.0.schema.json",DefaultClientUrl:n=>n==="devnet"?"https://devnet.xwarp.me/to":n==="testnet"?"###Not implemented###":"https://xwarp.me/to",Chain:{ApiUrl:n=>n==="devnet"?"https://devnet-api.multiversx.com":n==="testnet"?"https://testnet-api.multiversx.com":"https://api.multiversx.com"},Registry:{Contract:n=>n==="devnet"?"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36":n==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"},AvailableActionInputSources:["field","query"],AvailableActionInputTypes:["string","uint8","uint16","uint32","uint64","biguint","boolean","address"],AvailableActionInputPositions:["value","arg:1","arg:2","arg:3","arg:4","arg:5","arg:6","arg:7","arg:8","arg:9","arg:10"]};var f=n=>n==="devnet"?"D":n==="testnet"?"T":"1",A=n=>`${n}:${u.LatestProtocolVersion}`,T=n=>{var r,t;return{hash:n.hash.toString("hex"),alias:((r=n.alias)==null?void 0:r.toString())||null,trust:n.trust.toString(),creator:n.creator.toString(),createdAt:n.created_at.toNumber(),brand:((t=n.brand)==null?void 0:t.toString())||null}};var P=class{config;pendingBrand={protocol:A(u.ProtocolNameBrand),name:"",description:"",logo:"",website:""};constructor(r){this.config=r}createInscriptionTransaction(r){if(!this.config.userAddress)throw new Error("BrandBuilder: user address not set");let t=new h.TransactionsFactoryConfig({chainID:f(this.config.env)}),e=new h.TransferTransactionsFactory({config:t}),i=JSON.stringify(r);return e.createTransactionForNativeTokenTransfer({sender:h.Address.newFromBech32(this.config.userAddress),receiver:h.Address.newFromBech32(this.config.userAddress),nativeAmount:BigInt(0),data:Buffer.from(i).valueOf()})}async createFromRaw(r,t=!0){let e=JSON.parse(r);return t&&await this.ensureValidSchema(e),e}async createFromTransaction(r,t=!1){return await this.createFromRaw(r.data.toString(),t)}async createFromTransactionHash(r){let t=new h.ApiNetworkProvider(this.config.chainApiUrl||u.Chain.ApiUrl(this.config.env));try{let e=await t.getTransaction(r);return this.createFromTransaction(e)}catch(e){return console.error("BrandBuilder: Error creating from transaction hash",e),null}}setName(r){return this.pendingBrand.name=r,this}setDescription(r){return this.pendingBrand.description=r,this}setLogo(r){return this.pendingBrand.logo=r,this}setWebsite(r){return this.pendingBrand.website=r,this}setColors(r){return this.pendingBrand.colors=r,this}setCta(r){return this.pendingBrand.cta=r,this}async build(){return this.ensure(this.pendingBrand.name,"name is required"),this.ensure(this.pendingBrand.description,"description is required"),this.ensure(this.pendingBrand.logo,"logo is required"),await this.ensureValidSchema(this.pendingBrand),this.pendingBrand}ensure(r,t){if(!r)throw new Error(`Warp: ${t}`)}async ensureValidSchema(r){let t=this.config.brandSchemaUrl||u.LatestBrandSchemaUrl,i=await(await fetch(t)).json(),a=new L.default,o=a.compile(i);if(!o(r))throw new Error(`BrandBuilder: schema validation failed: ${a.errorsText(o.errors)}`)}};var c=require("@multiversx/sdk-core/out");var F=class{config;url;constructor(r,t){this.config=r,this.url=new URL(t)}createTransactionForExecute(r){if(!this.config.userAddress)throw new Error("WarpActionExecutor: user address not set");let t=new c.TransactionsFactoryConfig({chainID:f(this.config.env)}),e=new c.SmartContractTransactionsFactory({config:t}),i=this.getTypedArgsWithInputs(r),a=this.getPositionValueFromUrl(r,"value"),o=BigInt(a||r.value||0);return e.createTransactionForExecute({sender:c.Address.newFromBech32(this.config.userAddress),contract:c.Address.newFromBech32(r.address),function:r.func||"",gasLimit:BigInt(r.gasLimit),arguments:i,nativeTransferAmount:o})}getPositionValueFromUrl(r,t){var o,d;let e=new URLSearchParams(this.url.search),i=(o=r.inputs)==null?void 0:o.filter(l=>l.source==="query"),a=(d=i==null?void 0:i.find(l=>l.position===t))==null?void 0:d.name;return a?e.get(a):null}getTypedArgsWithInputs(r){return r.args.map(t=>{let[e,i]=t.split(":");return this.toTypedArg(i,e)})}toTypedArg(r,t){if(t==="string")return c.BytesValue.fromUTF8(r);if(t==="uint8")return new c.U8Value(Number(r));if(t==="uint16")return new c.U16Value(Number(r));if(t==="uint32")return new c.U32Value(Number(r));if(t==="uint64")return new c.U64Value(BigInt(r));if(t==="biguint")return new c.BigUIntValue(BigInt(r));if(t==="boolean")return new c.BooleanValue(r==="true");if(t==="address")return new c.AddressValue(c.Address.newFromBech32(r));if(t==="hex")return c.BytesValue.fromHex(r);throw new Error(`WarpActionExecutor: Unsupported input type: ${t}`)}};var m=require("@multiversx/sdk-core"),E=I(require("ajv"));var W={Warp:n=>`warp:${n}`,WarpInfo:n=>`warp-info:${n}`,Brand:n=>`brand:${n}`},w=class{cache=new Map;set(r,t,e){let i=Date.now()+e*1e3;this.cache.set(r,{value:t,expiresAt:i})}get(r){let t=this.cache.get(r);return t?Date.now()>t.expiresAt?(this.cache.delete(r),null):t.value:null}clear(){this.cache.clear()}};var B=class{config;cache=new w;pendingWarp={protocol:A(u.ProtocolNameWarp),name:"",title:"",description:null,preview:"",actions:[]};constructor(r){this.config=r}createInscriptionTransaction(r){if(!this.config.userAddress)throw new Error("WarpBuilder: user address not set");let t=new m.TransactionsFactoryConfig({chainID:f(this.config.env)}),e=new m.TransferTransactionsFactory({config:t}),i=JSON.stringify(r);return e.createTransactionForNativeTokenTransfer({sender:m.Address.newFromBech32(this.config.userAddress),receiver:m.Address.newFromBech32(this.config.userAddress),nativeAmount:BigInt(0),data:Buffer.from(i).valueOf()})}async createFromRaw(r,t=!0){let e=JSON.parse(r);return t&&await this.ensureValidSchema(e),e}async createFromTransaction(r,t=!1){let e=await this.createFromRaw(r.data.toString(),t);return e.meta={hash:r.hash,creator:r.sender.bech32(),createdAt:new Date(r.timestamp).toISOString()},e}async createFromTransactionHash(r,t){let e=W.Warp(r);if(t){let a=this.cache.get(e);if(a)return console.log(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${r}`),a}let i=new m.ApiNetworkProvider(this.config.chainApiUrl||u.Chain.ApiUrl(this.config.env));try{let a=await i.getTransaction(r),o=await this.createFromTransaction(a);return t&&t.ttl&&o&&this.cache.set(e,o,t.ttl),o}catch(a){return console.error("WarpBuilder: Error creating from transaction hash",a),null}}setName(r){return this.pendingWarp.name=r,this}setTitle(r){return this.pendingWarp.title=r,this}setDescription(r){return this.pendingWarp.description=r,this}setPreview(r){return this.pendingWarp.preview=r,this}setActions(r){return this.pendingWarp.actions=r,this}addAction(r){return this.pendingWarp.actions.push(r),this}async build(){return this.ensure(this.pendingWarp.protocol,"protocol is required"),this.ensure(this.pendingWarp.name,"name is required"),this.ensure(this.pendingWarp.title,"title is required"),this.ensure(this.pendingWarp.actions.length>0,"actions are required"),await this.ensureValidSchema(this.pendingWarp),this.pendingWarp}ensure(r,t){if(!r)throw new Error(`WarpBuilder: ${t}`)}async ensureValidSchema(r){let t=this.config.warpSchemaUrl||u.LatestWarpSchemaUrl,i=await(await fetch(t)).json(),a=new E.default,o=a.compile(i);if(!o(r))throw new Error(`WarpBuilder: schema validation failed: ${a.errorsText(o.errors)}`)}};var V=I(require("qr-code-styling"));var s=require("@multiversx/sdk-core/out");var R={buildInfo:{rustc:{version:"1.80.0-nightly",commitHash:"791adf759cc065316f054961875052d5bc03e16c",commitDate:"2024-05-21",channel:"Nightly",short:"rustc 1.80.0-nightly (791adf759 2024-05-21)"},contractCrate:{name:"registry",version:"0.0.1"},framework:{name:"multiversx-sc",version:"0.50.6"}},name:"RegistryContract",constructor:{inputs:[{name:"unit_price",type:"BigUint"}],outputs:[]},upgradeConstructor:{inputs:[],outputs:[]},endpoints:[{name:"registerWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias_opt",type:"optional<bytes>",multi_arg:!0},{name:"brand_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[],allow_multiple_var_args:!0},{name:"publishWarp",mutability:"mutable",inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"assignAlias",mutability:"mutable",inputs:[{name:"alias",type:"bytes"}],outputs:[]},{name:"getUserWarps",mutability:"readonly",inputs:[{name:"address",type:"Address"}],outputs:[{type:"variadic<WarpInfoView>",multi_result:!0}]},{name:"getInfoByAlias",mutability:"readonly",inputs:[{name:"alias",type:"bytes"}],outputs:[{type:"WarpInfoView"}]},{name:"getInfoByHash",mutability:"readonly",inputs:[{name:"hash",type:"bytes"}],outputs:[{type:"WarpInfoView"}]},{name:"setUnitPrice",onlyOwner:!0,mutability:"mutable",inputs:[{name:"amount",type:"BigUint"}],outputs:[]},{name:"getConfig",mutability:"readonly",inputs:[],outputs:[{type:"BigUint"}]},{name:"registerBrand",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"getUserBrands",mutability:"readonly",inputs:[{name:"user",type:"Address"}],outputs:[{type:"variadic<bytes>",multi_result:!0}]}],events:[{identifier:"warpRegistered",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0}]}],esdtAttributes:[],hasCallback:!1,types:{WarpInfoView:{type:"struct",fields:[{name:"hash",type:"bytes"},{name:"alias",type:"Option<bytes>"},{name:"trust",type:"bytes"},{name:"creator",type:"Address"},{name:"created_at",type:"u64"}]}}};var v=class{config;unitPrice;cache=new w;constructor(r){this.config=r,this.unitPrice=BigInt(0)}async init(){await this.loadRegistryConfigs()}createRegisterWarpTransaction(r,t){if(this.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.config.userAddress)throw new Error("WarpRegistry: user address not set");let e=t?this.unitPrice*BigInt(2):this.unitPrice;return this.getFactory().createTransactionForExecute({sender:s.Address.newFromBech32(this.config.userAddress),contract:s.Address.newFromBech32(u.Registry.Contract(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:e,arguments:t?[s.BytesValue.fromHex(r),s.BytesValue.fromUTF8(t)]:[s.BytesValue.fromHex(r)]})}createRegisterBrandTransaction(r){if(this.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.config.userAddress)throw new Error("WarpRegistry: user address not set");return this.getFactory().createTransactionForExecute({sender:s.Address.newFromBech32(this.config.userAddress),contract:s.Address.newFromBech32(u.Registry.Contract(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.unitPrice,arguments:[s.BytesValue.fromHex(r)]})}createAliasAssignTransaction(r,t){if(!this.config.userAddress)throw new Error("WarpRegistry: user address not set");return this.getFactory().createTransactionForExecute({sender:s.Address.newFromBech32(this.config.userAddress),contract:s.Address.newFromBech32(u.Registry.Contract(this.config.env)),function:"assignAlias",gasLimit:BigInt(1e7),arguments:[s.BytesValue.fromHex(r),s.BytesValue.fromUTF8(t)]})}createPublishWarpTransaction(r){if(!this.config.userAddress)throw new Error("WarpRegistry: user address not set");return this.getFactory().createTransactionForExecute({sender:s.Address.newFromBech32(this.config.userAddress),contract:s.Address.newFromBech32(u.Registry.Contract(this.config.env)),function:"publishWarp",gasLimit:BigInt(1e7),arguments:[s.BytesValue.fromHex(r)]})}async getInfoByAlias(r,t){let e=W.WarpInfo(r);if(t){let g=this.cache.get(e);if(g)return console.log(`WarpRegistry (getInfoByAlias): WarpInfo found in cache: ${r}`),g}let i=u.Registry.Contract(this.config.env),a=this.getController(),o=a.createQuery({contract:i,function:"getInfoByAlias",arguments:[s.BytesValue.fromUTF8(r)]}),d=await a.runQuery(o),[l]=a.parseQueryResponse(d),p=l?T(l):null,y=p!=null&&p.brand?await this.fetchBrand(p.brand):null;return t&&t.ttl&&this.cache.set(e,{warp:p,brand:y},t.ttl),{warp:p,brand:y}}async getInfoByHash(r,t){let e=W.WarpInfo(r);if(t){let g=this.cache.get(e);if(g)return console.log(`WarpRegistry (getInfoByHash): WarpInfo found in cache: ${r}`),g}let i=u.Registry.Contract(this.config.env),a=this.getController(),o=a.createQuery({contract:i,function:"getInfoByHash",arguments:[s.BytesValue.fromUTF8(r)]}),d=await a.runQuery(o),[l]=a.parseQueryResponse(d),p=l?T(l):null,y=p!=null&&p.brand?await this.fetchBrand(p.brand):null;return t&&t.ttl&&this.cache.set(e,{warp:p,brand:y},t.ttl),{warp:p,brand:y}}async getUserWarpInfos(r){let t=r||this.config.userAddress;if(!t)throw new Error("WarpRegistry: user address not set");let e=u.Registry.Contract(this.config.env),i=this.getController(),a=i.createQuery({contract:e,function:"getUserWarps",arguments:[new s.AddressValue(new s.Address(t))]}),o=await i.runQuery(a),[d]=i.parseQueryResponse(o);return d.map(T)}async fetchBrand(r,t){let e=W.Brand(r);if(t){let a=this.cache.get(e);if(a)return console.log(`WarpRegistry (fetchBrand): Brand found in cache: ${r}`),a}let i=new s.ApiNetworkProvider(this.config.chainApiUrl||u.Chain.ApiUrl(this.config.env));try{let a=await i.getTransaction(r),o=JSON.parse(a.data.toString());return t&&t.ttl&&this.cache.set(e,o,t.ttl),o}catch(a){return console.error("WarpRegistry: Error fetching brand from transaction hash",a),null}}async loadRegistryConfigs(){let r=u.Registry.Contract(this.config.env),t=this.getController(),e=t.createQuery({contract:r,function:"getConfig",arguments:[]}),i=await t.runQuery(e),[a]=t.parseQueryResponse(i),o=BigInt(a.toString());this.unitPrice=o}getFactory(){let r=new s.TransactionsFactoryConfig({chainID:f(this.config.env)}),t=s.AbiRegistry.create(R);return new s.SmartContractTransactionsFactory({config:r,abi:t})}getController(){let r=this.config.chainApiUrl||u.Chain.ApiUrl(this.config.env),t=new s.ApiNetworkProvider(r,{timeout:3e4}),e=new s.QueryRunnerAdapter({networkProvider:t}),i=s.AbiRegistry.create(R);return new s.SmartContractQueriesController({queryRunner:e,abi:i})}};var U="xwarp",b=":",N="alias",x=class{constructor(r){this.config=r;this.config=r}async detect(r){let i=new URL(r).searchParams.get(U);if(!i)return{match:!1,warp:null};let a=decodeURIComponent(i),o=a.includes(b)?a:`${N}${b}${a}`,[d,l]=o.split(b),p=new B(this.config),y=new v(this.config),g=null;if(d==="hash")g=await p.createFromTransactionHash(l);else if(d==="alias"){let{warp:q}=await y.getInfoByAlias(l);q&&(g=await p.createFromTransactionHash(q.hash))}return g?{match:!0,warp:g}:{match:!1,warp:null}}build(r,t){let e=this.config.clientUrl||u.DefaultClientUrl(this.config.env);return r===N?`${e}?${U}=${encodeURIComponent(t)}`:`${e}?${U}=${encodeURIComponent(r+b+t)}`}generateQrCode(r,t,e=512,i="white",a="black",o="#23F7DD"){let d=this.build(r,t);return new V.default({type:"svg",width:e,height:e,data:String(d),margin:16,qrOptions:{typeNumber:0,mode:"Byte",errorCorrectionLevel:"Q"},backgroundOptions:{color:i},dotsOptions:{type:"extra-rounded",color:a},cornersSquareOptions:{type:"extra-rounded",color:a},cornersDotOptions:{type:"square",color:a},imageOptions:{hideBackgroundDots:!0,imageSize:.4,margin:8},image:`data:image/svg+xml;utf8,<svg width="16" height="16" viewBox="0 0 100 100" fill="${encodeURIComponent(o)}" xmlns="http://www.w3.org/2000/svg"><path d="M54.8383 50.0242L95 28.8232L88.2456 16L51.4717 30.6974C50.5241 31.0764 49.4759 31.0764 48.5283 30.6974L11.7544 16L5 28.8232L45.1616 50.0242L5 71.2255L11.7544 84.0488L48.5283 69.351C49.4759 68.9724 50.5241 68.9724 51.4717 69.351L88.2456 84.0488L95 71.2255L54.8383 50.0242Z"/></svg>`})}};0&&(module.exports={BrandBuilder,Config,WarpActionExecutor,WarpBuilder,WarpLink,WarpRegistry});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var o={ProtocolNameWarp:"warp",ProtocolNameBrand:"warp-brand",LatestProtocolVersion:"0.1.0",LatestWarpSchemaUrl:"https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/v0.1.0.schema.json",LatestBrandSchemaUrl:"https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/brand/v0.1.0.schema.json",DefaultClientUrl:a=>a==="devnet"?"https://devnet.xwarp.me/to":a==="testnet"?"###Not implemented###":"https://xwarp.me/to",Chain:{ApiUrl:a=>a==="devnet"?"https://devnet-api.multiversx.com":a==="testnet"?"https://testnet-api.multiversx.com":"https://api.multiversx.com"},Registry:{Contract:a=>a==="devnet"?"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36":a==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"},AvailableActionInputSources:["field","query"],AvailableActionInputTypes:["string","uint8","uint16","uint32","uint64","biguint","boolean","address"],AvailableActionInputPositions:["value","arg:1","arg:2","arg:3","arg:4","arg:5","arg:6","arg:7","arg:8","arg:9","arg:10"]};import{Address as A,AddressValue as L,BigUIntValue as E,BooleanValue as V,BytesValue as U,SmartContractTransactionsFactory as N,TransactionsFactoryConfig as D,U16Value as Q,U32Value as O,U64Value as $,U8Value as k}from"@multiversx/sdk-core/out";var m=a=>a==="devnet"?"D":a==="testnet"?"T":"1",B=a=>`${a}:${o.LatestProtocolVersion}`,f=a=>{var t,r;return{hash:a.hash.toString("hex"),alias:((t=a.alias)==null?void 0:t.toString())||null,trust:a.trust.toString(),creator:a.creator.toString(),createdAt:a.created_at.toNumber(),brand:((r=a.brand)==null?void 0:r.toString())||null}};var x=class{config;url;constructor(t,r){this.config=t,this.url=new URL(r)}createTransactionForExecute(t){if(!this.config.userAddress)throw new Error("WarpActionExecutor: user address not set");let r=new D({chainID:m(this.config.env)}),e=new N({config:r}),i=this.getTypedArgsWithInputs(t),n=this.getPositionValueFromUrl(t,"value"),s=BigInt(n||t.value||0);return e.createTransactionForExecute({sender:A.newFromBech32(this.config.userAddress),contract:A.newFromBech32(t.address),function:t.func||"",gasLimit:BigInt(t.gasLimit),arguments:i,nativeTransferAmount:s})}getPositionValueFromUrl(t,r){var s,u;let e=new URLSearchParams(this.url.search),i=(s=t.inputs)==null?void 0:s.filter(p=>p.source==="query"),n=(u=i==null?void 0:i.find(p=>p.position===r))==null?void 0:u.name;return n?e.get(n):null}getTypedArgsWithInputs(t){return t.args.map(r=>{let[e,i]=r.split(":");return this.toTypedArg(i,e)})}toTypedArg(t,r){if(r==="string")return U.fromUTF8(t);if(r==="uint8")return new k(Number(t));if(r==="uint16")return new Q(Number(t));if(r==="uint32")return new O(Number(t));if(r==="uint64")return new $(BigInt(t));if(r==="biguint")return new E(BigInt(t));if(r==="boolean")return new V(t==="true");if(r==="address")return new L(A.newFromBech32(t));if(r==="hex")return U.fromHex(t);throw new Error(`WarpActionExecutor: Unsupported input type: ${r}`)}};import{Address as P,ApiNetworkProvider as _,TransactionsFactoryConfig as H,TransferTransactionsFactory as j}from"@multiversx/sdk-core";import K from"ajv";var y=class{config;pendingWarp={protocol:B(o.ProtocolNameWarp),name:"",title:"",description:null,preview:"",actions:[]};constructor(t){this.config=t}createInscriptionTransaction(t){if(!this.config.userAddress)throw new Error("WarpBuilder: user address not set");let r=new H({chainID:m(this.config.env)}),e=new j({config:r}),i=JSON.stringify(t);return e.createTransactionForNativeTokenTransfer({sender:P.newFromBech32(this.config.userAddress),receiver:P.newFromBech32(this.config.userAddress),nativeAmount:BigInt(0),data:Buffer.from(i).valueOf()})}async createFromRaw(t,r=!0){let e=JSON.parse(t);return r&&await this.ensureValidSchema(e),e}async createFromTransaction(t,r=!1){let e=await this.createFromRaw(t.data.toString(),r);return e.meta={hash:t.hash,creator:t.sender.bech32(),createdAt:new Date(t.timestamp).toISOString()},e}async createFromTransactionHash(t){let r=new _(this.config.chainApiUrl||o.Chain.ApiUrl(this.config.env));try{let e=await r.getTransaction(t);return this.createFromTransaction(e)}catch(e){return console.error("WarpBuilder: Error creating from transaction hash",e),null}}setName(t){return this.pendingWarp.name=t,this}setTitle(t){return this.pendingWarp.title=t,this}setDescription(t){return this.pendingWarp.description=t,this}setPreview(t){return this.pendingWarp.preview=t,this}setActions(t){return this.pendingWarp.actions=t,this}addAction(t){return this.pendingWarp.actions.push(t),this}async build(){return this.ensure(this.pendingWarp.protocol,"protocol is required"),this.ensure(this.pendingWarp.name,"name is required"),this.ensure(this.pendingWarp.title,"title is required"),this.ensure(this.pendingWarp.actions.length>0,"actions are required"),await this.ensureValidSchema(this.pendingWarp),this.pendingWarp}ensure(t,r){if(!t)throw new Error(`WarpBuilder: ${r}`)}async ensureValidSchema(t){let r=this.config.warpSchemaUrl||o.LatestWarpSchemaUrl,i=await(await fetch(r)).json(),n=new K,s=n.compile(i);if(!s(t))throw new Error(`WarpBuilder: schema validation failed: ${n.errorsText(s.errors)}`)}};import Y from"qr-code-styling";import{AbiRegistry as q,Address as h,AddressValue as G,ApiNetworkProvider as R,BytesValue as g,QueryRunnerAdapter as J,SmartContractQueriesController as M,SmartContractTransactionsFactory as Z,TransactionsFactoryConfig as X}from"@multiversx/sdk-core/out";var b={buildInfo:{rustc:{version:"1.80.0-nightly",commitHash:"791adf759cc065316f054961875052d5bc03e16c",commitDate:"2024-05-21",channel:"Nightly",short:"rustc 1.80.0-nightly (791adf759 2024-05-21)"},contractCrate:{name:"registry",version:"0.0.1"},framework:{name:"multiversx-sc",version:"0.50.6"}},name:"RegistryContract",constructor:{inputs:[{name:"unit_price",type:"BigUint"}],outputs:[]},upgradeConstructor:{inputs:[],outputs:[]},endpoints:[{name:"registerWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[]},{name:"publishWarp",mutability:"mutable",inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"assignAlias",mutability:"mutable",inputs:[{name:"alias",type:"bytes"}],outputs:[]},{name:"getUserWarps",mutability:"readonly",inputs:[{name:"address",type:"Address"}],outputs:[{type:"variadic<WarpInfoView>",multi_result:!0}]},{name:"getInfoByAlias",mutability:"readonly",inputs:[{name:"alias",type:"bytes"}],outputs:[{type:"WarpInfoView"}]},{name:"getInfoByHash",mutability:"readonly",inputs:[{name:"hash",type:"bytes"}],outputs:[{type:"WarpInfoView"}]},{name:"setUnitPrice",onlyOwner:!0,mutability:"mutable",inputs:[{name:"amount",type:"BigUint"}],outputs:[]},{name:"getConfig",mutability:"readonly",inputs:[],outputs:[{type:"BigUint"}]}],events:[{identifier:"warpRegistered",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0}]}],esdtAttributes:[],hasCallback:!1,types:{WarpInfoView:{type:"struct",fields:[{name:"hash",type:"bytes"},{name:"alias",type:"Option<bytes>"},{name:"trust",type:"bytes"},{name:"creator",type:"Address"},{name:"created_at",type:"u64"}]}}};var W={WarpInfo:a=>`warp-info:${a}`,Brand:a=>`brand:${a}`},w=class{cache=new Map;set(t,r,e){let i=Date.now()+e*1e3;this.cache.set(t,{value:r,expiresAt:i})}get(t){let r=this.cache.get(t);return r?Date.now()>r.expiresAt?(this.cache.delete(t),null):r.value:null}clear(){this.cache.clear()}};var C=class{config;registerCost;cache=new w;constructor(t){this.config=t,this.registerCost=BigInt(0)}async init(){await this.loadRegistryConfigs()}createRegisterTransaction(t,r){if(this.registerCost===BigInt(0))throw new Error("registry config not loaded. forgot to call init()?");if(!this.config.userAddress)throw new Error("registry config user address not set");let e=r?this.registerCost*BigInt(2):this.registerCost;return this.getFactory().createTransactionForExecute({sender:h.newFromBech32(this.config.userAddress),contract:h.newFromBech32(o.Registry.Contract(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:e,arguments:r?[g.fromHex(t),g.fromUTF8(r)]:[g.fromHex(t)]})}createAliasAssignTransaction(t,r){if(!this.config.userAddress)throw new Error("registry config user address not set");return this.getFactory().createTransactionForExecute({sender:h.newFromBech32(this.config.userAddress),contract:h.newFromBech32(o.Registry.Contract(this.config.env)),function:"assignAlias",gasLimit:BigInt(1e7),arguments:[g.fromHex(t),g.fromUTF8(r)]})}createPublishTransaction(t){if(!this.config.userAddress)throw new Error("registry config user address not set");return this.getFactory().createTransactionForExecute({sender:h.newFromBech32(this.config.userAddress),contract:h.newFromBech32(o.Registry.Contract(this.config.env)),function:"publishRegistry",gasLimit:BigInt(1e7),arguments:[g.fromHex(t)]})}async getInfoByAlias(t,r){let e=W.WarpInfo(t);if(r){let l=this.cache.get(e);if(l)return l}let i=o.Registry.Contract(this.config.env),n=this.getController(),s=n.createQuery({contract:i,function:"getInfoByAlias",arguments:[g.fromUTF8(t)]}),u=await n.runQuery(s),[p]=n.parseQueryResponse(u),c=p?f(p):null,d=c!=null&&c.brand?await this.fetchBrand(c.brand):null;return r&&r.ttl&&this.cache.set(e,{warp:c,brand:d},r.ttl),{warp:c,brand:d}}async getInfoByHash(t,r){let e=W.WarpInfo(t);if(r){let l=this.cache.get(e);if(l)return l}let i=o.Registry.Contract(this.config.env),n=this.getController(),s=n.createQuery({contract:i,function:"getInfoByHash",arguments:[g.fromUTF8(t)]}),u=await n.runQuery(s),[p]=n.parseQueryResponse(u),c=p?f(p):null,d=c!=null&&c.brand?await this.fetchBrand(c.brand):null;return r&&r.ttl&&this.cache.set(e,{warp:c,brand:d},r.ttl),{warp:c,brand:d}}async getUserWarpInfos(t){let r=t||this.config.userAddress;if(!r)throw new Error("WarpRegistry: user address not set");let e=o.Registry.Contract(this.config.env),i=this.getController(),n=i.createQuery({contract:e,function:"getUserWarps",arguments:[new G(new h(r))]}),s=await i.runQuery(n);return i.parseQueryResponse(s).map(f)}async fetchBrand(t,r){let e=W.Brand(t);if(r){let n=this.cache.get(e);if(n)return n}let i=new R(this.config.chainApiUrl||o.Chain.ApiUrl(this.config.env));try{let n=await i.getTransaction(t),s=JSON.parse(n.data.toString());return r&&r.ttl&&this.cache.set(e,s,r.ttl),s}catch(n){return console.error("Error fetching brand from transaction hash",n),null}}async loadRegistryConfigs(){let t=o.Registry.Contract(this.config.env),r=this.getController(),e=r.createQuery({contract:t,function:"getConfig",arguments:[]}),i=await r.runQuery(e),[n]=r.parseQueryResponse(i),s=BigInt(n.toString());this.registerCost=s}getFactory(){let t=new X({chainID:m(this.config.env)}),r=q.create(b);return new Z({config:t,abi:r})}getController(){let t=this.config.chainApiUrl||o.Chain.ApiUrl(this.config.env),r=new R(t,{timeout:3e4}),e=new J({networkProvider:r}),i=q.create(b);return new M({queryRunner:e,abi:i})}};var I="xwarp",v=":",F="alias",S=class{constructor(t){this.config=t;this.config=t}async detect(t){let i=new URL(t).searchParams.get(I);if(!i)return{match:!1,warp:null};let n=decodeURIComponent(i),s=n.includes(v)?n:`${F}${v}${n}`,[u,p]=s.split(v),c=new y(this.config),d=new C(this.config),l=null;if(u==="hash")l=await c.createFromTransactionHash(p);else if(u==="alias"){let{warp:T}=await d.getInfoByAlias(p);T&&(l=await c.createFromTransactionHash(T.hash))}return l?{match:!0,warp:l}:{match:!1,warp:null}}build(t,r){let e=this.config.clientUrl||o.DefaultClientUrl(this.config.env);return t===F?`${e}?${I}=${encodeURIComponent(r)}`:`${e}?${I}=${encodeURIComponent(t+v+r)}`}generateQrCode(t,r,e=512,i="white",n="black",s="#23F7DD"){let u=this.build(t,r);return new Y({type:"svg",width:e,height:e,data:String(u),margin:16,qrOptions:{typeNumber:0,mode:"Byte",errorCorrectionLevel:"Q"},backgroundOptions:{color:i},dotsOptions:{type:"extra-rounded",color:n},cornersSquareOptions:{type:"extra-rounded",color:n},cornersDotOptions:{type:"square",color:n},imageOptions:{hideBackgroundDots:!0,imageSize:.4,margin:8},image:`data:image/svg+xml;utf8,<svg width="16" height="16" viewBox="0 0 100 100" fill="${encodeURIComponent(s)}" xmlns="http://www.w3.org/2000/svg"><path d="M54.8383 50.0242L95 28.8232L88.2456 16L51.4717 30.6974C50.5241 31.0764 49.4759 31.0764 48.5283 30.6974L11.7544 16L5 28.8232L45.1616 50.0242L5 71.2255L11.7544 84.0488L48.5283 69.351C49.4759 68.9724 50.5241 68.9724 51.4717 69.351L88.2456 84.0488L95 71.2255L54.8383 50.0242Z"/></svg>`})}};export{o as Config,x as WarpActionExecutor,y as WarpBuilder,S as WarpLink,C as WarpRegistry};
1
+ import{Address as P,ApiNetworkProvider as N,TransactionsFactoryConfig as V,TransferTransactionsFactory as $}from"@multiversx/sdk-core";import D from"ajv";var o={ProtocolNameWarp:"warp",ProtocolNameBrand:"warp-brand",LatestProtocolVersion:"0.1.0",LatestWarpSchemaUrl:"https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/v0.1.0.schema.json",LatestBrandSchemaUrl:"https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/brand/v0.1.0.schema.json",DefaultClientUrl:a=>a==="devnet"?"https://devnet.xwarp.me/to":a==="testnet"?"###Not implemented###":"https://xwarp.me/to",Chain:{ApiUrl:a=>a==="devnet"?"https://devnet-api.multiversx.com":a==="testnet"?"https://testnet-api.multiversx.com":"https://api.multiversx.com"},Registry:{Contract:a=>a==="devnet"?"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36":a==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"},AvailableActionInputSources:["field","query"],AvailableActionInputTypes:["string","uint8","uint16","uint32","uint64","biguint","boolean","address"],AvailableActionInputPositions:["value","arg:1","arg:2","arg:3","arg:4","arg:5","arg:6","arg:7","arg:8","arg:9","arg:10"]};var h=a=>a==="devnet"?"D":a==="testnet"?"T":"1",w=a=>`${a}:${o.LatestProtocolVersion}`,W=a=>{var r,t;return{hash:a.hash.toString("hex"),alias:((r=a.alias)==null?void 0:r.toString())||null,trust:a.trust.toString(),creator:a.creator.toString(),createdAt:a.created_at.toNumber(),brand:((t=a.brand)==null?void 0:t.toString())||null}};var F=class{config;pendingBrand={protocol:w(o.ProtocolNameBrand),name:"",description:"",logo:"",website:""};constructor(r){this.config=r}createInscriptionTransaction(r){if(!this.config.userAddress)throw new Error("BrandBuilder: user address not set");let t=new V({chainID:h(this.config.env)}),e=new $({config:t}),i=JSON.stringify(r);return e.createTransactionForNativeTokenTransfer({sender:P.newFromBech32(this.config.userAddress),receiver:P.newFromBech32(this.config.userAddress),nativeAmount:BigInt(0),data:Buffer.from(i).valueOf()})}async createFromRaw(r,t=!0){let e=JSON.parse(r);return t&&await this.ensureValidSchema(e),e}async createFromTransaction(r,t=!1){return await this.createFromRaw(r.data.toString(),t)}async createFromTransactionHash(r){let t=new N(this.config.chainApiUrl||o.Chain.ApiUrl(this.config.env));try{let e=await t.getTransaction(r);return this.createFromTransaction(e)}catch(e){return console.error("BrandBuilder: Error creating from transaction hash",e),null}}setName(r){return this.pendingBrand.name=r,this}setDescription(r){return this.pendingBrand.description=r,this}setLogo(r){return this.pendingBrand.logo=r,this}setWebsite(r){return this.pendingBrand.website=r,this}setColors(r){return this.pendingBrand.colors=r,this}setCta(r){return this.pendingBrand.cta=r,this}async build(){return this.ensure(this.pendingBrand.name,"name is required"),this.ensure(this.pendingBrand.description,"description is required"),this.ensure(this.pendingBrand.logo,"logo is required"),await this.ensureValidSchema(this.pendingBrand),this.pendingBrand}ensure(r,t){if(!r)throw new Error(`Warp: ${t}`)}async ensureValidSchema(r){let t=this.config.brandSchemaUrl||o.LatestBrandSchemaUrl,i=await(await fetch(t)).json(),n=new D,s=n.compile(i);if(!s(r))throw new Error(`BrandBuilder: schema validation failed: ${n.errorsText(s.errors)}`)}};import{Address as A,AddressValue as O,BigUIntValue as k,BooleanValue as _,BytesValue as R,SmartContractTransactionsFactory as Q,TransactionsFactoryConfig as H,U16Value as j,U32Value as K,U64Value as J,U8Value as z}from"@multiversx/sdk-core/out";var U=class{config;url;constructor(r,t){this.config=r,this.url=new URL(t)}createTransactionForExecute(r){if(!this.config.userAddress)throw new Error("WarpActionExecutor: user address not set");let t=new H({chainID:h(this.config.env)}),e=new Q({config:t}),i=this.getTypedArgsWithInputs(r),n=this.getPositionValueFromUrl(r,"value"),s=BigInt(n||r.value||0);return e.createTransactionForExecute({sender:A.newFromBech32(this.config.userAddress),contract:A.newFromBech32(r.address),function:r.func||"",gasLimit:BigInt(r.gasLimit),arguments:i,nativeTransferAmount:s})}getPositionValueFromUrl(r,t){var s,u;let e=new URLSearchParams(this.url.search),i=(s=r.inputs)==null?void 0:s.filter(p=>p.source==="query"),n=(u=i==null?void 0:i.find(p=>p.position===t))==null?void 0:u.name;return n?e.get(n):null}getTypedArgsWithInputs(r){return r.args.map(t=>{let[e,i]=t.split(":");return this.toTypedArg(i,e)})}toTypedArg(r,t){if(t==="string")return R.fromUTF8(r);if(t==="uint8")return new z(Number(r));if(t==="uint16")return new j(Number(r));if(t==="uint32")return new K(Number(r));if(t==="uint64")return new J(BigInt(r));if(t==="biguint")return new k(BigInt(r));if(t==="boolean")return new _(r==="true");if(t==="address")return new O(A.newFromBech32(r));if(t==="hex")return R.fromHex(r);throw new Error(`WarpActionExecutor: Unsupported input type: ${t}`)}};import{Address as x,ApiNetworkProvider as G,TransactionsFactoryConfig as M,TransferTransactionsFactory as Z}from"@multiversx/sdk-core";import X from"ajv";var y={Warp:a=>`warp:${a}`,WarpInfo:a=>`warp-info:${a}`,Brand:a=>`brand:${a}`},f=class{cache=new Map;set(r,t,e){let i=Date.now()+e*1e3;this.cache.set(r,{value:t,expiresAt:i})}get(r){let t=this.cache.get(r);return t?Date.now()>t.expiresAt?(this.cache.delete(r),null):t.value:null}clear(){this.cache.clear()}};var B=class{config;cache=new f;pendingWarp={protocol:w(o.ProtocolNameWarp),name:"",title:"",description:null,preview:"",actions:[]};constructor(r){this.config=r}createInscriptionTransaction(r){if(!this.config.userAddress)throw new Error("WarpBuilder: user address not set");let t=new M({chainID:h(this.config.env)}),e=new Z({config:t}),i=JSON.stringify(r);return e.createTransactionForNativeTokenTransfer({sender:x.newFromBech32(this.config.userAddress),receiver:x.newFromBech32(this.config.userAddress),nativeAmount:BigInt(0),data:Buffer.from(i).valueOf()})}async createFromRaw(r,t=!0){let e=JSON.parse(r);return t&&await this.ensureValidSchema(e),e}async createFromTransaction(r,t=!1){let e=await this.createFromRaw(r.data.toString(),t);return e.meta={hash:r.hash,creator:r.sender.bech32(),createdAt:new Date(r.timestamp).toISOString()},e}async createFromTransactionHash(r,t){let e=y.Warp(r);if(t){let n=this.cache.get(e);if(n)return console.log(`WarpBuilder (createFromTransactionHash): Warp found in cache: ${r}`),n}let i=new G(this.config.chainApiUrl||o.Chain.ApiUrl(this.config.env));try{let n=await i.getTransaction(r),s=await this.createFromTransaction(n);return t&&t.ttl&&s&&this.cache.set(e,s,t.ttl),s}catch(n){return console.error("WarpBuilder: Error creating from transaction hash",n),null}}setName(r){return this.pendingWarp.name=r,this}setTitle(r){return this.pendingWarp.title=r,this}setDescription(r){return this.pendingWarp.description=r,this}setPreview(r){return this.pendingWarp.preview=r,this}setActions(r){return this.pendingWarp.actions=r,this}addAction(r){return this.pendingWarp.actions.push(r),this}async build(){return this.ensure(this.pendingWarp.protocol,"protocol is required"),this.ensure(this.pendingWarp.name,"name is required"),this.ensure(this.pendingWarp.title,"title is required"),this.ensure(this.pendingWarp.actions.length>0,"actions are required"),await this.ensureValidSchema(this.pendingWarp),this.pendingWarp}ensure(r,t){if(!r)throw new Error(`WarpBuilder: ${t}`)}async ensureValidSchema(r){let t=this.config.warpSchemaUrl||o.LatestWarpSchemaUrl,i=await(await fetch(t)).json(),n=new X,s=n.compile(i);if(!s(r))throw new Error(`WarpBuilder: schema validation failed: ${n.errorsText(s.errors)}`)}};import ar from"qr-code-styling";import{AbiRegistry as q,Address as l,AddressValue as rr,ApiNetworkProvider as S,BytesValue as g,QueryRunnerAdapter as tr,SmartContractQueriesController as er,SmartContractTransactionsFactory as nr,TransactionsFactoryConfig as ir}from"@multiversx/sdk-core/out";var T={buildInfo:{rustc:{version:"1.80.0-nightly",commitHash:"791adf759cc065316f054961875052d5bc03e16c",commitDate:"2024-05-21",channel:"Nightly",short:"rustc 1.80.0-nightly (791adf759 2024-05-21)"},contractCrate:{name:"registry",version:"0.0.1"},framework:{name:"multiversx-sc",version:"0.50.6"}},name:"RegistryContract",constructor:{inputs:[{name:"unit_price",type:"BigUint"}],outputs:[]},upgradeConstructor:{inputs:[],outputs:[]},endpoints:[{name:"registerWarp",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias_opt",type:"optional<bytes>",multi_arg:!0},{name:"brand_opt",type:"optional<bytes>",multi_arg:!0}],outputs:[],allow_multiple_var_args:!0},{name:"publishWarp",mutability:"mutable",inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"assignAlias",mutability:"mutable",inputs:[{name:"alias",type:"bytes"}],outputs:[]},{name:"getUserWarps",mutability:"readonly",inputs:[{name:"address",type:"Address"}],outputs:[{type:"variadic<WarpInfoView>",multi_result:!0}]},{name:"getInfoByAlias",mutability:"readonly",inputs:[{name:"alias",type:"bytes"}],outputs:[{type:"WarpInfoView"}]},{name:"getInfoByHash",mutability:"readonly",inputs:[{name:"hash",type:"bytes"}],outputs:[{type:"WarpInfoView"}]},{name:"setUnitPrice",onlyOwner:!0,mutability:"mutable",inputs:[{name:"amount",type:"BigUint"}],outputs:[]},{name:"getConfig",mutability:"readonly",inputs:[],outputs:[{type:"BigUint"}]},{name:"registerBrand",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"}],outputs:[]},{name:"getUserBrands",mutability:"readonly",inputs:[{name:"user",type:"Address"}],outputs:[{type:"variadic<bytes>",multi_result:!0}]}],events:[{identifier:"warpRegistered",inputs:[{name:"hash",type:"bytes",indexed:!0},{name:"alias",type:"bytes",indexed:!0}]}],esdtAttributes:[],hasCallback:!1,types:{WarpInfoView:{type:"struct",fields:[{name:"hash",type:"bytes"},{name:"alias",type:"Option<bytes>"},{name:"trust",type:"bytes"},{name:"creator",type:"Address"},{name:"created_at",type:"u64"}]}}};var v=class{config;unitPrice;cache=new f;constructor(r){this.config=r,this.unitPrice=BigInt(0)}async init(){await this.loadRegistryConfigs()}createRegisterWarpTransaction(r,t){if(this.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.config.userAddress)throw new Error("WarpRegistry: user address not set");let e=t?this.unitPrice*BigInt(2):this.unitPrice;return this.getFactory().createTransactionForExecute({sender:l.newFromBech32(this.config.userAddress),contract:l.newFromBech32(o.Registry.Contract(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:e,arguments:t?[g.fromHex(r),g.fromUTF8(t)]:[g.fromHex(r)]})}createRegisterBrandTransaction(r){if(this.unitPrice===BigInt(0))throw new Error("WarpRegistry: config not loaded. forgot to call init()?");if(!this.config.userAddress)throw new Error("WarpRegistry: user address not set");return this.getFactory().createTransactionForExecute({sender:l.newFromBech32(this.config.userAddress),contract:l.newFromBech32(o.Registry.Contract(this.config.env)),function:"registerBrand",gasLimit:BigInt(1e7),nativeTransferAmount:this.unitPrice,arguments:[g.fromHex(r)]})}createAliasAssignTransaction(r,t){if(!this.config.userAddress)throw new Error("WarpRegistry: user address not set");return this.getFactory().createTransactionForExecute({sender:l.newFromBech32(this.config.userAddress),contract:l.newFromBech32(o.Registry.Contract(this.config.env)),function:"assignAlias",gasLimit:BigInt(1e7),arguments:[g.fromHex(r),g.fromUTF8(t)]})}createPublishWarpTransaction(r){if(!this.config.userAddress)throw new Error("WarpRegistry: user address not set");return this.getFactory().createTransactionForExecute({sender:l.newFromBech32(this.config.userAddress),contract:l.newFromBech32(o.Registry.Contract(this.config.env)),function:"publishWarp",gasLimit:BigInt(1e7),arguments:[g.fromHex(r)]})}async getInfoByAlias(r,t){let e=y.WarpInfo(r);if(t){let d=this.cache.get(e);if(d)return console.log(`WarpRegistry (getInfoByAlias): WarpInfo found in cache: ${r}`),d}let i=o.Registry.Contract(this.config.env),n=this.getController(),s=n.createQuery({contract:i,function:"getInfoByAlias",arguments:[g.fromUTF8(r)]}),u=await n.runQuery(s),[p]=n.parseQueryResponse(u),c=p?W(p):null,m=c!=null&&c.brand?await this.fetchBrand(c.brand):null;return t&&t.ttl&&this.cache.set(e,{warp:c,brand:m},t.ttl),{warp:c,brand:m}}async getInfoByHash(r,t){let e=y.WarpInfo(r);if(t){let d=this.cache.get(e);if(d)return console.log(`WarpRegistry (getInfoByHash): WarpInfo found in cache: ${r}`),d}let i=o.Registry.Contract(this.config.env),n=this.getController(),s=n.createQuery({contract:i,function:"getInfoByHash",arguments:[g.fromUTF8(r)]}),u=await n.runQuery(s),[p]=n.parseQueryResponse(u),c=p?W(p):null,m=c!=null&&c.brand?await this.fetchBrand(c.brand):null;return t&&t.ttl&&this.cache.set(e,{warp:c,brand:m},t.ttl),{warp:c,brand:m}}async getUserWarpInfos(r){let t=r||this.config.userAddress;if(!t)throw new Error("WarpRegistry: user address not set");let e=o.Registry.Contract(this.config.env),i=this.getController(),n=i.createQuery({contract:e,function:"getUserWarps",arguments:[new rr(new l(t))]}),s=await i.runQuery(n),[u]=i.parseQueryResponse(s);return u.map(W)}async fetchBrand(r,t){let e=y.Brand(r);if(t){let n=this.cache.get(e);if(n)return console.log(`WarpRegistry (fetchBrand): Brand found in cache: ${r}`),n}let i=new S(this.config.chainApiUrl||o.Chain.ApiUrl(this.config.env));try{let n=await i.getTransaction(r),s=JSON.parse(n.data.toString());return t&&t.ttl&&this.cache.set(e,s,t.ttl),s}catch(n){return console.error("WarpRegistry: Error fetching brand from transaction hash",n),null}}async loadRegistryConfigs(){let r=o.Registry.Contract(this.config.env),t=this.getController(),e=t.createQuery({contract:r,function:"getConfig",arguments:[]}),i=await t.runQuery(e),[n]=t.parseQueryResponse(i),s=BigInt(n.toString());this.unitPrice=s}getFactory(){let r=new ir({chainID:h(this.config.env)}),t=q.create(T);return new nr({config:r,abi:t})}getController(){let r=this.config.chainApiUrl||o.Chain.ApiUrl(this.config.env),t=new S(r,{timeout:3e4}),e=new tr({networkProvider:t}),i=q.create(T);return new er({queryRunner:e,abi:i})}};var b="xwarp",C=":",L="alias",E=class{constructor(r){this.config=r;this.config=r}async detect(r){let i=new URL(r).searchParams.get(b);if(!i)return{match:!1,warp:null};let n=decodeURIComponent(i),s=n.includes(C)?n:`${L}${C}${n}`,[u,p]=s.split(C),c=new B(this.config),m=new v(this.config),d=null;if(u==="hash")d=await c.createFromTransactionHash(p);else if(u==="alias"){let{warp:I}=await m.getInfoByAlias(p);I&&(d=await c.createFromTransactionHash(I.hash))}return d?{match:!0,warp:d}:{match:!1,warp:null}}build(r,t){let e=this.config.clientUrl||o.DefaultClientUrl(this.config.env);return r===L?`${e}?${b}=${encodeURIComponent(t)}`:`${e}?${b}=${encodeURIComponent(r+C+t)}`}generateQrCode(r,t,e=512,i="white",n="black",s="#23F7DD"){let u=this.build(r,t);return new ar({type:"svg",width:e,height:e,data:String(u),margin:16,qrOptions:{typeNumber:0,mode:"Byte",errorCorrectionLevel:"Q"},backgroundOptions:{color:i},dotsOptions:{type:"extra-rounded",color:n},cornersSquareOptions:{type:"extra-rounded",color:n},cornersDotOptions:{type:"square",color:n},imageOptions:{hideBackgroundDots:!0,imageSize:.4,margin:8},image:`data:image/svg+xml;utf8,<svg width="16" height="16" viewBox="0 0 100 100" fill="${encodeURIComponent(s)}" xmlns="http://www.w3.org/2000/svg"><path d="M54.8383 50.0242L95 28.8232L88.2456 16L51.4717 30.6974C50.5241 31.0764 49.4759 31.0764 48.5283 30.6974L11.7544 16L5 28.8232L45.1616 50.0242L5 71.2255L11.7544 84.0488L48.5283 69.351C49.4759 68.9724 50.5241 68.9724 51.4717 69.351L88.2456 84.0488L95 71.2255L54.8383 50.0242Z"/></svg>`})}};export{F as BrandBuilder,o as Config,U as WarpActionExecutor,B as WarpBuilder,E as WarpLink,v as WarpRegistry};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vleap/warps",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",