@vleap/warps 0.0.47 → 0.0.49

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
@@ -8,7 +8,12 @@ type WarpConfig = {
8
8
  clientUrl?: string;
9
9
  userAddress?: string;
10
10
  chainApiUrl?: string;
11
- schemaUrl?: string;
11
+ warpSchemaUrl?: string;
12
+ brandSchemaUrl?: string;
13
+ cacheTtl?: number;
14
+ };
15
+ type WarpCacheConfig = {
16
+ ttl?: number;
12
17
  };
13
18
  type TrustStatus = 'unverified' | 'verified' | 'blacklisted';
14
19
  type WarpInfo = {
@@ -17,6 +22,7 @@ type WarpInfo = {
17
22
  trust: TrustStatus;
18
23
  creator: string;
19
24
  createdAt: number;
25
+ brand: string | null;
20
26
  };
21
27
  type WarpIdType = 'hash' | 'alias';
22
28
  type Warp = {
@@ -26,6 +32,13 @@ type Warp = {
26
32
  description: string | null;
27
33
  preview: string;
28
34
  actions: WarpAction[];
35
+ next?: string;
36
+ meta?: WarpMeta;
37
+ };
38
+ type WarpMeta = {
39
+ hash: string;
40
+ creator: string;
41
+ createdAt: string;
29
42
  };
30
43
  type WarpAction = WarpContractAction | WarpLinkAction;
31
44
  type WarpActionType = 'contract' | 'link';
@@ -39,6 +52,7 @@ type WarpContractAction = {
39
52
  value?: string;
40
53
  gasLimit: number;
41
54
  inputs?: WarpActionInput[];
55
+ next?: string;
42
56
  };
43
57
  type WarpLinkAction = {
44
58
  type: WarpActionType;
@@ -67,17 +81,36 @@ type WarpActionExecutionResult = {
67
81
  };
68
82
  tx?: string;
69
83
  };
84
+ type Brand = {
85
+ protocol: string;
86
+ name: string;
87
+ description: string;
88
+ logo: string;
89
+ website?: string;
90
+ colors?: {
91
+ primary?: string;
92
+ secondary?: string;
93
+ };
94
+ cta?: {
95
+ title: string;
96
+ description: string;
97
+ label: string;
98
+ url: string;
99
+ };
100
+ };
70
101
 
71
102
  declare const Config: {
72
- ProtocolName: string;
73
- LatestVersion: string;
74
- LatestSchemaUrl: string;
103
+ ProtocolNameWarp: string;
104
+ ProtocolNameBrand: string;
105
+ LatestProtocolVersion: string;
106
+ LatestWarpSchemaUrl: string;
107
+ LatestBrandSchemaUrl: string;
75
108
  DefaultClientUrl: (env: ChainEnv) => "https://devnet.xwarp.me/to" | "###Not implemented###" | "https://xwarp.me/to";
76
109
  Chain: {
77
110
  ApiUrl: (env: ChainEnv) => "https://devnet-api.multiversx.com" | "https://testnet-api.multiversx.com" | "https://api.multiversx.com";
78
111
  };
79
112
  Registry: {
80
- Contract: (env: ChainEnv) => "erd1qqqqqqqqqqqqqpgq8h85eq9l3cp40h5s3ujqshj2x775m2wyl3tsl20ltn" | "####" | "erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe";
113
+ Contract: (env: ChainEnv) => "erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36" | "####" | "erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe";
81
114
  };
82
115
  AvailableActionInputSources: WarpActionInputSource[];
83
116
  AvailableActionInputTypes: WarpActionInputType[];
@@ -128,17 +161,25 @@ declare class WarpLink {
128
161
  declare class WarpRegistry {
129
162
  private config;
130
163
  private registerCost;
164
+ private cache;
131
165
  constructor(config: WarpConfig);
132
166
  init(): Promise<void>;
133
167
  createRegisterTransaction(txHash: string, alias?: string | null): Transaction;
134
168
  createAliasAssignTransaction(txHash: string, alias: string): Transaction;
135
169
  createPublishTransaction(txHash: string): Transaction;
136
- getInfoByAlias(alias: string): Promise<WarpInfo | null>;
137
- getInfoByHash(hash: string): Promise<WarpInfo | null>;
138
- getUserWarpInfos(user: string): Promise<WarpInfo[]>;
170
+ getInfoByAlias(alias: string, cache?: WarpCacheConfig): Promise<{
171
+ warp: WarpInfo | null;
172
+ brand: Brand | null;
173
+ }>;
174
+ getInfoByHash(hash: string, cache?: WarpCacheConfig): Promise<{
175
+ warp: WarpInfo | null;
176
+ brand: Brand | null;
177
+ }>;
178
+ getUserWarpInfos(user?: string): Promise<WarpInfo[]>;
179
+ fetchBrand(hash: string, cache?: WarpCacheConfig): Promise<Brand | null>;
139
180
  private loadRegistryConfigs;
140
181
  private getFactory;
141
182
  private getController;
142
183
  }
143
184
 
144
- export { type ChainEnv, Config, type TrustStatus, type Warp, type WarpAction, type WarpActionExecutionResult, WarpActionExecutor, type WarpActionInput, type WarpActionInputPosition, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpConfig, type WarpContractAction, type WarpIdType, type WarpInfo, WarpLink, type WarpLinkAction, WarpRegistry };
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 };
package/dist/index.d.ts CHANGED
@@ -8,7 +8,12 @@ type WarpConfig = {
8
8
  clientUrl?: string;
9
9
  userAddress?: string;
10
10
  chainApiUrl?: string;
11
- schemaUrl?: string;
11
+ warpSchemaUrl?: string;
12
+ brandSchemaUrl?: string;
13
+ cacheTtl?: number;
14
+ };
15
+ type WarpCacheConfig = {
16
+ ttl?: number;
12
17
  };
13
18
  type TrustStatus = 'unverified' | 'verified' | 'blacklisted';
14
19
  type WarpInfo = {
@@ -17,6 +22,7 @@ type WarpInfo = {
17
22
  trust: TrustStatus;
18
23
  creator: string;
19
24
  createdAt: number;
25
+ brand: string | null;
20
26
  };
21
27
  type WarpIdType = 'hash' | 'alias';
22
28
  type Warp = {
@@ -26,6 +32,13 @@ type Warp = {
26
32
  description: string | null;
27
33
  preview: string;
28
34
  actions: WarpAction[];
35
+ next?: string;
36
+ meta?: WarpMeta;
37
+ };
38
+ type WarpMeta = {
39
+ hash: string;
40
+ creator: string;
41
+ createdAt: string;
29
42
  };
30
43
  type WarpAction = WarpContractAction | WarpLinkAction;
31
44
  type WarpActionType = 'contract' | 'link';
@@ -39,6 +52,7 @@ type WarpContractAction = {
39
52
  value?: string;
40
53
  gasLimit: number;
41
54
  inputs?: WarpActionInput[];
55
+ next?: string;
42
56
  };
43
57
  type WarpLinkAction = {
44
58
  type: WarpActionType;
@@ -67,17 +81,36 @@ type WarpActionExecutionResult = {
67
81
  };
68
82
  tx?: string;
69
83
  };
84
+ type Brand = {
85
+ protocol: string;
86
+ name: string;
87
+ description: string;
88
+ logo: string;
89
+ website?: string;
90
+ colors?: {
91
+ primary?: string;
92
+ secondary?: string;
93
+ };
94
+ cta?: {
95
+ title: string;
96
+ description: string;
97
+ label: string;
98
+ url: string;
99
+ };
100
+ };
70
101
 
71
102
  declare const Config: {
72
- ProtocolName: string;
73
- LatestVersion: string;
74
- LatestSchemaUrl: string;
103
+ ProtocolNameWarp: string;
104
+ ProtocolNameBrand: string;
105
+ LatestProtocolVersion: string;
106
+ LatestWarpSchemaUrl: string;
107
+ LatestBrandSchemaUrl: string;
75
108
  DefaultClientUrl: (env: ChainEnv) => "https://devnet.xwarp.me/to" | "###Not implemented###" | "https://xwarp.me/to";
76
109
  Chain: {
77
110
  ApiUrl: (env: ChainEnv) => "https://devnet-api.multiversx.com" | "https://testnet-api.multiversx.com" | "https://api.multiversx.com";
78
111
  };
79
112
  Registry: {
80
- Contract: (env: ChainEnv) => "erd1qqqqqqqqqqqqqpgq8h85eq9l3cp40h5s3ujqshj2x775m2wyl3tsl20ltn" | "####" | "erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe";
113
+ Contract: (env: ChainEnv) => "erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36" | "####" | "erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe";
81
114
  };
82
115
  AvailableActionInputSources: WarpActionInputSource[];
83
116
  AvailableActionInputTypes: WarpActionInputType[];
@@ -128,17 +161,25 @@ declare class WarpLink {
128
161
  declare class WarpRegistry {
129
162
  private config;
130
163
  private registerCost;
164
+ private cache;
131
165
  constructor(config: WarpConfig);
132
166
  init(): Promise<void>;
133
167
  createRegisterTransaction(txHash: string, alias?: string | null): Transaction;
134
168
  createAliasAssignTransaction(txHash: string, alias: string): Transaction;
135
169
  createPublishTransaction(txHash: string): Transaction;
136
- getInfoByAlias(alias: string): Promise<WarpInfo | null>;
137
- getInfoByHash(hash: string): Promise<WarpInfo | null>;
138
- getUserWarpInfos(user: string): Promise<WarpInfo[]>;
170
+ getInfoByAlias(alias: string, cache?: WarpCacheConfig): Promise<{
171
+ warp: WarpInfo | null;
172
+ brand: Brand | null;
173
+ }>;
174
+ getInfoByHash(hash: string, cache?: WarpCacheConfig): Promise<{
175
+ warp: WarpInfo | null;
176
+ brand: Brand | null;
177
+ }>;
178
+ getUserWarpInfos(user?: string): Promise<WarpInfo[]>;
179
+ fetchBrand(hash: string, cache?: WarpCacheConfig): Promise<Brand | null>;
139
180
  private loadRegistryConfigs;
140
181
  private getFactory;
141
182
  private getController;
142
183
  }
143
184
 
144
- export { type ChainEnv, Config, type TrustStatus, type Warp, type WarpAction, type WarpActionExecutionResult, WarpActionExecutor, type WarpActionInput, type WarpActionInputPosition, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpConfig, type WarpContractAction, type WarpIdType, type WarpInfo, WarpLink, type WarpLinkAction, WarpRegistry };
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 };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var L=Object.create;var y=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var Q=(n,t)=>{for(var r in t)y(n,r,{get:t[r],enumerable:!0})},B=(n,t,r,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of V(t))!N.call(n,i)&&i!==r&&y(n,i,{get:()=>t[i],enumerable:!(e=S(t,i))||e.enumerable});return n};var q=(n,t,r)=>(r=n!=null?L(E(n)):{},B(t||!n||!n.__esModule?y(r,"default",{value:n,enumerable:!0}):r,n)),D=n=>B(y({},"__esModule",{value:!0}),n);var $={};Q($,{Config:()=>u,WarpActionExecutor:()=>v,WarpBuilder:()=>f,WarpLink:()=>I,WarpRegistry:()=>h});module.exports=D($);var u={ProtocolName:"warp",LatestVersion:"0.1.0",LatestSchemaUrl:"https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/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"?"erd1qqqqqqqqqqqqqpgq8h85eq9l3cp40h5s3ujqshj2x775m2wyl3tsl20ltn":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 m=n=>n==="devnet"?"D":n==="testnet"?"T":"1",F=()=>`${u.ProtocolName}:${u.LatestVersion}`,w=n=>{var t;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()}};var v=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:m(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,g;let e=new URLSearchParams(this.url.search),i=(c=t.inputs)==null?void 0:c.filter(l=>l.source==="query"),a=(g=i==null?void 0:i.find(l=>l.position===r))==null?void 0:g.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 p=require("@multiversx/sdk-core"),U=q(require("ajv"));var f=class{config;pendingWarp={protocol:F(),name:"",title:"",description:null,preview:"",actions:[]};constructor(t){this.config=t}createInscriptionTransaction(t){if(!this.config.userAddress)throw new Error("warp builder user address not set");let r=new p.TransactionsFactoryConfig({chainID:m(this.config.env)}),e=new p.TransferTransactionsFactory({config:r}),i=JSON.stringify(t);return e.createTransactionForNativeTokenTransfer({sender:p.Address.newFromBech32(this.config.userAddress),receiver:p.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){return this.createFromRaw(t.data.toString(),r)}async createFromTransactionHash(t){let r=new p.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("Error creating warp 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(`Warp: ${r}`)}async ensureValidSchema(t){let r=this.config.schemaUrl||u.LatestSchemaUrl,i=await(await fetch(r)).json(),a=new U.default,c=a.compile(i);if(!c(t))throw new Error(`Warp schema validation failed: ${a.errorsText(c.errors)}`)}};var x=q(require("qr-code-styling"));var s=require("@multiversx/sdk-core/out");var C={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 h=class{config;registerCost;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.fromUTF8(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.fromUTF8(t)]})}async getInfoByAlias(t){let r=u.Registry.Contract(this.config.env),e=this.getController(),i=e.createQuery({contract:r,function:"getInfoByAlias",arguments:[s.BytesValue.fromUTF8(t)]}),a=await e.runQuery(i),[c]=e.parseQueryResponse(a);return c?w(c):null}async getInfoByHash(t){let r=u.Registry.Contract(this.config.env),e=this.getController(),i=e.createQuery({contract:r,function:"getInfoByHash",arguments:[s.BytesValue.fromUTF8(t)]}),a=await e.runQuery(i),[c]=e.parseQueryResponse(a);return c?w(c):null}async getUserWarpInfos(t){let r=u.Registry.Contract(this.config.env),e=this.getController(),i=e.createQuery({contract:r,function:"getUserWarps",arguments:[new s.AddressValue(new s.Address(t))]}),a=await e.runQuery(i);return e.parseQueryResponse(a).map(w)}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:m(this.config.env)}),r=s.AbiRegistry.create(C);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(C);return new s.SmartContractQueriesController({queryRunner:e,abi:i})}};var A="xwarp",W=":",R="alias",I=class{constructor(t){this.config=t;this.config=t}async detect(t){let i=new URL(t).searchParams.get(A);if(!i)return{match:!1,warp:null};let a=decodeURIComponent(i),c=a.includes(W)?a:`${R}${W}${a}`,[g,l]=c.split(W),T=new f(this.config),P=new h(this.config),d=null;if(g==="hash")d=await T.createFromTransactionHash(l);else if(g==="alias"){let b=await P.getInfoByAlias(l);b&&(d=await T.createFromTransactionHash(b.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===R?`${e}?${A}=${encodeURIComponent(r)}`:`${e}?${A}=${encodeURIComponent(t+W+r)}`}generateQrCode(t,r,e=512,i="white",a="black",c="#23F7DD"){let g=this.build(t,r);return new x.default({type:"svg",width:e,height:e,data:String(g),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 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});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var a={ProtocolName:"warp",LatestVersion:"0.1.0",LatestSchemaUrl:"https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/v0.1.0.schema.json",DefaultClientUrl:s=>s==="devnet"?"https://devnet.xwarp.me/to":s==="testnet"?"###Not implemented###":"https://xwarp.me/to",Chain:{ApiUrl:s=>s==="devnet"?"https://devnet-api.multiversx.com":s==="testnet"?"https://testnet-api.multiversx.com":"https://api.multiversx.com"},Registry:{Contract:s=>s==="devnet"?"erd1qqqqqqqqqqqqqpgq8h85eq9l3cp40h5s3ujqshj2x775m2wyl3tsl20ltn":s==="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 w,AddressValue as x,BigUIntValue as P,BooleanValue as L,BytesValue as T,SmartContractTransactionsFactory as S,TransactionsFactoryConfig as V,U16Value as E,U32Value as N,U64Value as Q,U8Value as D}from"@multiversx/sdk-core/out";var l=s=>s==="devnet"?"D":s==="testnet"?"T":"1",I=()=>`${a.ProtocolName}:${a.LatestVersion}`,f=s=>{var t;return{hash:s.hash.toString("hex"),alias:((t=s.alias)==null?void 0:t.toString())||null,trust:s.trust.toString(),creator:s.creator.toString(),createdAt:s.created_at.toNumber()}};var b=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 V({chainID:l(this.config.env)}),e=new S({config:r}),n=this.getTypedArgsWithInputs(t),i=this.getPositionValueFromUrl(t,"value"),o=BigInt(i||t.value||0);return e.createTransactionForExecute({sender:w.newFromBech32(this.config.userAddress),contract:w.newFromBech32(t.address),function:t.func||"",gasLimit:BigInt(t.gasLimit),arguments:n,nativeTransferAmount:o})}getPositionValueFromUrl(t,r){var o,u;let e=new URLSearchParams(this.url.search),n=(o=t.inputs)==null?void 0:o.filter(g=>g.source==="query"),i=(u=n==null?void 0:n.find(g=>g.position===r))==null?void 0:u.name;return i?e.get(i):null}getTypedArgsWithInputs(t){return t.args.map(r=>{let[e,n]=r.split(":");return this.toTypedArg(n,e)})}toTypedArg(t,r){if(r==="string")return T.fromUTF8(t);if(r==="uint8")return new D(Number(t));if(r==="uint16")return new E(Number(t));if(r==="uint32")return new N(Number(t));if(r==="uint64")return new Q(BigInt(t));if(r==="biguint")return new P(BigInt(t));if(r==="boolean")return new L(t==="true");if(r==="address")return new x(w.newFromBech32(t));if(r==="hex")return T.fromHex(t);throw new Error(`WarpActionExecutor: Unsupported input type: ${r}`)}};import{Address as B,ApiNetworkProvider as O,TransactionsFactoryConfig as $,TransferTransactionsFactory as k}from"@multiversx/sdk-core";import _ from"ajv";var h=class{config;pendingWarp={protocol:I(),name:"",title:"",description:null,preview:"",actions:[]};constructor(t){this.config=t}createInscriptionTransaction(t){if(!this.config.userAddress)throw new Error("warp builder user address not set");let r=new $({chainID:l(this.config.env)}),e=new k({config:r}),n=JSON.stringify(t);return e.createTransactionForNativeTokenTransfer({sender:B.newFromBech32(this.config.userAddress),receiver:B.newFromBech32(this.config.userAddress),nativeAmount:BigInt(0),data:Buffer.from(n).valueOf()})}async createFromRaw(t,r=!0){let e=JSON.parse(t);return r&&await this.ensureValidSchema(e),e}async createFromTransaction(t,r=!1){return this.createFromRaw(t.data.toString(),r)}async createFromTransactionHash(t){let r=new O(this.config.chainApiUrl||a.Chain.ApiUrl(this.config.env));try{let e=await r.getTransaction(t);return this.createFromTransaction(e)}catch(e){return console.error("Error creating warp 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(`Warp: ${r}`)}async ensureValidSchema(t){let r=this.config.schemaUrl||a.LatestSchemaUrl,n=await(await fetch(r)).json(),i=new _,o=i.compile(n);if(!o(t))throw new Error(`Warp schema validation failed: ${i.errorsText(o.errors)}`)}};import K from"qr-code-styling";import{AbiRegistry as q,Address as p,AddressValue as H,ApiNetworkProvider as z,BytesValue as c,QueryRunnerAdapter as G,SmartContractQueriesController as J,SmartContractTransactionsFactory as M,TransactionsFactoryConfig as Z}from"@multiversx/sdk-core/out";var W={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 d=class{config;registerCost;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:p.newFromBech32(this.config.userAddress),contract:p.newFromBech32(a.Registry.Contract(this.config.env)),function:"registerWarp",gasLimit:BigInt(1e7),nativeTransferAmount:e,arguments:r?[c.fromHex(t),c.fromUTF8(r)]:[c.fromHex(t)]})}createAliasAssignTransaction(t,r){if(!this.config.userAddress)throw new Error("registry config user address not set");return this.getFactory().createTransactionForExecute({sender:p.newFromBech32(this.config.userAddress),contract:p.newFromBech32(a.Registry.Contract(this.config.env)),function:"assignAlias",gasLimit:BigInt(1e7),arguments:[c.fromUTF8(t),c.fromUTF8(r)]})}createPublishTransaction(t){if(!this.config.userAddress)throw new Error("registry config user address not set");return this.getFactory().createTransactionForExecute({sender:p.newFromBech32(this.config.userAddress),contract:p.newFromBech32(a.Registry.Contract(this.config.env)),function:"publishRegistry",gasLimit:BigInt(1e7),arguments:[c.fromUTF8(t)]})}async getInfoByAlias(t){let r=a.Registry.Contract(this.config.env),e=this.getController(),n=e.createQuery({contract:r,function:"getInfoByAlias",arguments:[c.fromUTF8(t)]}),i=await e.runQuery(n),[o]=e.parseQueryResponse(i);return o?f(o):null}async getInfoByHash(t){let r=a.Registry.Contract(this.config.env),e=this.getController(),n=e.createQuery({contract:r,function:"getInfoByHash",arguments:[c.fromUTF8(t)]}),i=await e.runQuery(n),[o]=e.parseQueryResponse(i);return o?f(o):null}async getUserWarpInfos(t){let r=a.Registry.Contract(this.config.env),e=this.getController(),n=e.createQuery({contract:r,function:"getUserWarps",arguments:[new H(new p(t))]}),i=await e.runQuery(n);return e.parseQueryResponse(i).map(f)}async loadRegistryConfigs(){let t=a.Registry.Contract(this.config.env),r=this.getController(),e=r.createQuery({contract:t,function:"getConfig",arguments:[]}),n=await r.runQuery(e),[i]=r.parseQueryResponse(n),o=BigInt(i.toString());this.registerCost=o}getFactory(){let t=new Z({chainID:l(this.config.env)}),r=q.create(W);return new M({config:t,abi:r})}getController(){let t=this.config.chainApiUrl||a.Chain.ApiUrl(this.config.env),r=new z(t,{timeout:3e4}),e=new G({networkProvider:r}),n=q.create(W);return new J({queryRunner:e,abi:n})}};var v="xwarp",y=":",F="alias",U=class{constructor(t){this.config=t;this.config=t}async detect(t){let n=new URL(t).searchParams.get(v);if(!n)return{match:!1,warp:null};let i=decodeURIComponent(n),o=i.includes(y)?i:`${F}${y}${i}`,[u,g]=o.split(y),C=new h(this.config),R=new d(this.config),m=null;if(u==="hash")m=await C.createFromTransactionHash(g);else if(u==="alias"){let A=await R.getInfoByAlias(g);A&&(m=await C.createFromTransactionHash(A.hash))}return m?{match:!0,warp:m}:{match:!1,warp:null}}build(t,r){let e=this.config.clientUrl||a.DefaultClientUrl(this.config.env);return t===F?`${e}?${v}=${encodeURIComponent(r)}`:`${e}?${v}=${encodeURIComponent(t+y+r)}`}generateQrCode(t,r,e=512,n="white",i="black",o="#23F7DD"){let u=this.build(t,r);return new K({type:"svg",width:e,height:e,data:String(u),margin:16,qrOptions:{typeNumber:0,mode:"Byte",errorCorrectionLevel:"Q"},backgroundOptions:{color:n},dotsOptions:{type:"extra-rounded",color:i},cornersSquareOptions:{type:"extra-rounded",color:i},cornersDotOptions:{type:"square",color:i},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>`})}};export{a as Config,b as WarpActionExecutor,h as WarpBuilder,U as WarpLink,d as WarpRegistry};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vleap/warps",
3
- "version": "0.0.47",
3
+ "version": "0.0.49",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",