@vleap/warps 0.0.26 → 0.0.28

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
@@ -7,6 +7,7 @@ type WarpConfig = {
7
7
  clientUrl?: string;
8
8
  userAddress?: string;
9
9
  chainApiUrl?: string;
10
+ schemaUrl?: string;
10
11
  };
11
12
  type WarpIdType = 'hash' | 'alias';
12
13
  type Warp = {
@@ -22,7 +23,7 @@ type WarpActionType = 'contract' | 'link';
22
23
  type WarpContractAction = {
23
24
  type: WarpActionType;
24
25
  label: string;
25
- description: string | null;
26
+ description?: string | null;
26
27
  address: string;
27
28
  func: string | null;
28
29
  args: any[];
@@ -33,7 +34,7 @@ type WarpContractAction = {
33
34
  type WarpLinkAction = {
34
35
  type: WarpActionType;
35
36
  label: string;
36
- description: string | null;
37
+ description?: string | null;
37
38
  url: string;
38
39
  inputs?: WarpActionInput[];
39
40
  };
@@ -41,18 +42,19 @@ type WarpActionInputSource = 'field' | 'query';
41
42
  type WarpActionInputType = 'text' | 'number' | 'bigint' | 'boolean' | 'address';
42
43
  type WarpActionInput = {
43
44
  name: string;
45
+ description?: string | null;
44
46
  type: WarpActionInputType;
45
47
  position: string;
46
48
  source: WarpActionInputSource;
47
- };
48
- type RegistryInfo = {
49
- alias: string | null;
50
- isPublic: boolean;
49
+ required?: boolean;
50
+ min?: number;
51
+ max?: number;
51
52
  };
52
53
 
53
54
  declare const Config: {
54
55
  ProtocolName: string;
55
56
  LatestVersion: string;
57
+ LatestSchemaUrl: string;
56
58
  DefaultClientUrl: (env: ChainEnv) => "https://devnet.xwarp.me/to" | "###Not implemented###" | "https://xwarp.me/to";
57
59
  Chain: {
58
60
  ApiUrl: (env: ChainEnv) => "https://devnet-api.multiversx.com" | "https://testnet-api.multiversx.com" | "https://api.multiversx.com";
@@ -85,8 +87,9 @@ declare class WarpBuilder {
85
87
  setPreview(preview: string): WarpBuilder;
86
88
  setActions(actions: WarpAction[]): WarpBuilder;
87
89
  addAction(action: WarpAction): WarpBuilder;
88
- build(): Warp;
90
+ build(): Promise<Warp>;
89
91
  private ensure;
92
+ private ensureValidSchema;
90
93
  }
91
94
 
92
95
  type DetectionResult = {
@@ -105,12 +108,12 @@ declare class WarpRegistry {
105
108
  private registerCost;
106
109
  constructor(config: WarpConfig);
107
110
  init(): Promise<void>;
108
- createRegisterTransaction(txHash: string, registryInfo: RegistryInfo): Transaction;
111
+ createRegisterTransaction(txHash: string, alias?: string | null): Transaction;
109
112
  createAliasAssignTransaction(txHash: string, alias: string): Transaction;
110
113
  resolveAlias(alias: string): Promise<string | null>;
111
- private loadRegistryInfo;
114
+ private loadRegistryConfigs;
112
115
  private getFactory;
113
116
  private getController;
114
117
  }
115
118
 
116
- export { type ChainEnv, Config, type RegistryInfo, type Warp, type WarpAction, WarpActionExecutor, type WarpActionInput, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpConfig, type WarpContractAction, type WarpIdType, WarpLink, type WarpLinkAction, WarpRegistry };
119
+ export { type ChainEnv, Config, type Warp, type WarpAction, WarpActionExecutor, type WarpActionInput, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpConfig, type WarpContractAction, type WarpIdType, WarpLink, type WarpLinkAction, WarpRegistry };
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ type WarpConfig = {
7
7
  clientUrl?: string;
8
8
  userAddress?: string;
9
9
  chainApiUrl?: string;
10
+ schemaUrl?: string;
10
11
  };
11
12
  type WarpIdType = 'hash' | 'alias';
12
13
  type Warp = {
@@ -22,7 +23,7 @@ type WarpActionType = 'contract' | 'link';
22
23
  type WarpContractAction = {
23
24
  type: WarpActionType;
24
25
  label: string;
25
- description: string | null;
26
+ description?: string | null;
26
27
  address: string;
27
28
  func: string | null;
28
29
  args: any[];
@@ -33,7 +34,7 @@ type WarpContractAction = {
33
34
  type WarpLinkAction = {
34
35
  type: WarpActionType;
35
36
  label: string;
36
- description: string | null;
37
+ description?: string | null;
37
38
  url: string;
38
39
  inputs?: WarpActionInput[];
39
40
  };
@@ -41,18 +42,19 @@ type WarpActionInputSource = 'field' | 'query';
41
42
  type WarpActionInputType = 'text' | 'number' | 'bigint' | 'boolean' | 'address';
42
43
  type WarpActionInput = {
43
44
  name: string;
45
+ description?: string | null;
44
46
  type: WarpActionInputType;
45
47
  position: string;
46
48
  source: WarpActionInputSource;
47
- };
48
- type RegistryInfo = {
49
- alias: string | null;
50
- isPublic: boolean;
49
+ required?: boolean;
50
+ min?: number;
51
+ max?: number;
51
52
  };
52
53
 
53
54
  declare const Config: {
54
55
  ProtocolName: string;
55
56
  LatestVersion: string;
57
+ LatestSchemaUrl: string;
56
58
  DefaultClientUrl: (env: ChainEnv) => "https://devnet.xwarp.me/to" | "###Not implemented###" | "https://xwarp.me/to";
57
59
  Chain: {
58
60
  ApiUrl: (env: ChainEnv) => "https://devnet-api.multiversx.com" | "https://testnet-api.multiversx.com" | "https://api.multiversx.com";
@@ -85,8 +87,9 @@ declare class WarpBuilder {
85
87
  setPreview(preview: string): WarpBuilder;
86
88
  setActions(actions: WarpAction[]): WarpBuilder;
87
89
  addAction(action: WarpAction): WarpBuilder;
88
- build(): Warp;
90
+ build(): Promise<Warp>;
89
91
  private ensure;
92
+ private ensureValidSchema;
90
93
  }
91
94
 
92
95
  type DetectionResult = {
@@ -105,12 +108,12 @@ declare class WarpRegistry {
105
108
  private registerCost;
106
109
  constructor(config: WarpConfig);
107
110
  init(): Promise<void>;
108
- createRegisterTransaction(txHash: string, registryInfo: RegistryInfo): Transaction;
111
+ createRegisterTransaction(txHash: string, alias?: string | null): Transaction;
109
112
  createAliasAssignTransaction(txHash: string, alias: string): Transaction;
110
113
  resolveAlias(alias: string): Promise<string | null>;
111
- private loadRegistryInfo;
114
+ private loadRegistryConfigs;
112
115
  private getFactory;
113
116
  private getController;
114
117
  }
115
118
 
116
- export { type ChainEnv, Config, type RegistryInfo, type Warp, type WarpAction, WarpActionExecutor, type WarpActionInput, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpConfig, type WarpContractAction, type WarpIdType, WarpLink, type WarpLinkAction, WarpRegistry };
119
+ export { type ChainEnv, Config, type Warp, type WarpAction, WarpActionExecutor, type WarpActionInput, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpConfig, type WarpContractAction, type WarpIdType, WarpLink, type WarpLinkAction, WarpRegistry };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var m=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var x=(n,r)=>{for(var t in r)m(n,t,{get:r[t],enumerable:!0})},P=(n,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of F(r))!I.call(n,o)&&o!==t&&m(n,o,{get:()=>r[o],enumerable:!(i=q(r,o))||i.enumerable});return n};var R=n=>P(m({},"__esModule",{value:!0}),n);var B={};x(B,{Config:()=>s,WarpActionExecutor:()=>h,WarpBuilder:()=>l,WarpLink:()=>d,WarpRegistry:()=>g});module.exports=R(B);var s={ProtocolName:"warp",LatestVersion:"0.1.0",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:["text","number","bigint","boolean","address"],AvailableActionInputPositions:["value"]};var h=class{constructor(r){this.config=r;this.config=r}execute(r){throw new Error("not implemented")}};var c=require("@multiversx/sdk-core");var f=n=>n==="devnet"?"D":n==="testnet"?"T":"1",C=()=>`${s.ProtocolName}:${s.LatestVersion}`;var l=class{config;pendingWarp={protocol:C(),name:"",title:"",description:null,preview:"",actions:[]};constructor(r){this.config=r}createInscriptionTransaction(r){if(!this.config.userAddress)throw new Error("warp builder user address not set");let t=new c.TransactionsFactoryConfig({chainID:f(this.config.env)}),i=new c.TransferTransactionsFactory({config:t}),o=JSON.stringify(r);return i.createTransactionForNativeTokenTransfer({sender:c.Address.newFromBech32(this.config.userAddress),receiver:c.Address.newFromBech32(this.config.userAddress),nativeAmount:BigInt(0),data:Buffer.from(o).valueOf()})}createFromRaw(r){return JSON.parse(r)}createFromTransaction(r){return this.createFromRaw(r.data.toString())}async createFromTransactionHash(r){let t=new c.ApiNetworkProvider(this.config.chainApiUrl||s.Chain.ApiUrl(this.config.env));try{let i=await t.getTransaction(r);return this.createFromTransaction(i)}catch(i){return console.error("Error creating warp from transaction hash",i),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}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"),this.pendingWarp}ensure(r,t){if(!r)throw new Error(`Warp: ${t}`)}};var e=require("@multiversx/sdk-core/out"),y=require("@multiversx/sdk-core/out/utils.codec");var g=class{config;registerCost;constructor(r){this.config=r,this.registerCost=BigInt(0)}async init(){await this.loadRegistryInfo()}createRegisterTransaction(r,t){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 i=t.alias?this.registerCost*BigInt(2):this.registerCost;return this.getFactory().createTransactionForExecute({sender:e.Address.newFromBech32(this.config.userAddress),contract:e.Address.newFromBech32(s.Registry.Contract(this.config.env)),function:"register",gasLimit:BigInt(1e7),nativeTransferAmount:i,arguments:t.alias?[e.BytesValue.fromHex(r),new e.BooleanValue(t.isPublic),e.BytesValue.fromUTF8(t.alias)]:[e.BytesValue.fromHex(r),new e.BooleanValue(t.isPublic)]})}createAliasAssignTransaction(r,t){if(!this.config.userAddress)throw new Error("registry config user address not set");return this.getFactory().createTransactionForExecute({sender:e.Address.newFromBech32(this.config.userAddress),contract:e.Address.newFromBech32(s.Registry.Contract(this.config.env)),function:"assignAlias",gasLimit:BigInt(1e7),arguments:[e.BytesValue.fromUTF8(r),e.BytesValue.fromUTF8(t)]})}async resolveAlias(r){let t=s.Registry.Contract(this.config.env),i=this.getController(),o=i.createQuery({contract:t,function:"resolveAlias",arguments:[e.BytesValue.fromUTF8(r)]}),p=await i.runQuery(o);console.log("resolveAlias res",p);let[a]=i.parseQueryResponse(p);return console.log("resolveAlias txHashRaw",a),(a==null?void 0:a.toString())||null}async loadRegistryInfo(){let r=s.Registry.Contract(this.config.env),t=this.getController(),i=t.createQuery({contract:r,function:"getConfig",arguments:[]}),o=await t.runQuery(i),[p]=t.parseQueryResponse(o),a=BigInt("0x"+(0,y.byteArrayToHex)(p));this.registerCost=a}getFactory(){let r=new e.TransactionsFactoryConfig({chainID:f(this.config.env)});return new e.SmartContractTransactionsFactory({config:r})}getController(){let r=this.config.chainApiUrl||s.Chain.ApiUrl(this.config.env),t=new e.ApiNetworkProvider(r,{timeout:3e4}),i=new e.QueryRunnerAdapter({networkProvider:t});return new e.SmartContractQueriesController({queryRunner:i})}};var W="xwarp",A=":",d=class{constructor(r){this.config=r;this.config=r}build(r,t){return`${this.config.clientUrl||s.DefaultClientUrl(this.config.env)}?${W}=${encodeURIComponent(r)}${A}${encodeURIComponent(t)}`}async detect(r){let o=new URL(r).searchParams.get(W);if(!o)return{match:!1,warp:null};let[p,a]=o.split(A),w=new l(this.config),T=new g(this.config),u=null;if(p==="hash")u=await w.createFromTransactionHash(a);else if(p==="alias"){let v=await T.resolveAlias(a);v&&(u=await w.createFromTransactionHash(v))}return u?{match:!0,warp:u}:{match:!1,warp:null}}};0&&(module.exports={Config,WarpActionExecutor,WarpBuilder,WarpLink,WarpRegistry});
1
+ "use strict";var F=Object.create;var m=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,U=Object.prototype.hasOwnProperty;var B=(e,r)=>{for(var t in r)m(e,t,{get:r[t],enumerable:!0})},C=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of P(r))!U.call(e,o)&&o!==t&&m(e,o,{get:()=>r[o],enumerable:!(n=I(r,o))||n.enumerable});return e};var b=(e,r,t)=>(t=e!=null?F(R(e)):{},C(r||!e||!e.__esModule?m(t,"default",{value:e,enumerable:!0}):t,e)),S=e=>C(m({},"__esModule",{value:!0}),e);var E={};B(E,{Config:()=>s,WarpActionExecutor:()=>f,WarpBuilder:()=>g,WarpLink:()=>d,WarpRegistry:()=>l});module.exports=S(E);var s={ProtocolName:"warp",LatestVersion:"0.1.0",LatestSchemaUrl:"https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/v0.1.0.schema.json",DefaultClientUrl:e=>e==="devnet"?"https://devnet.xwarp.me/to":e==="testnet"?"###Not implemented###":"https://xwarp.me/to",Chain:{ApiUrl:e=>e==="devnet"?"https://devnet-api.multiversx.com":e==="testnet"?"https://testnet-api.multiversx.com":"https://api.multiversx.com"},Registry:{Contract:e=>e==="devnet"?"erd1qqqqqqqqqqqqqpgq8h85eq9l3cp40h5s3ujqshj2x775m2wyl3tsl20ltn":e==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"},AvailableActionInputSources:["field","query"],AvailableActionInputTypes:["text","number","bigint","boolean","address"],AvailableActionInputPositions:["value"]};var f=class{constructor(r){this.config=r;this.config=r}execute(r){throw new Error("not implemented")}};var p=require("@multiversx/sdk-core"),W=b(require("ajv"));var h=e=>e==="devnet"?"D":e==="testnet"?"T":"1",y=()=>`${s.ProtocolName}:${s.LatestVersion}`;var g=class{config;pendingWarp={protocol:y(),name:"",title:"",description:null,preview:"",actions:[]};constructor(r){this.config=r}createInscriptionTransaction(r){if(!this.config.userAddress)throw new Error("warp builder user address not set");let t=new p.TransactionsFactoryConfig({chainID:h(this.config.env)}),n=new p.TransferTransactionsFactory({config:t}),o=JSON.stringify(r);return n.createTransactionForNativeTokenTransfer({sender:p.Address.newFromBech32(this.config.userAddress),receiver:p.Address.newFromBech32(this.config.userAddress),nativeAmount:BigInt(0),data:Buffer.from(o).valueOf()})}createFromRaw(r){return JSON.parse(r)}createFromTransaction(r){return this.createFromRaw(r.data.toString())}async createFromTransactionHash(r){let t=new p.ApiNetworkProvider(this.config.chainApiUrl||s.Chain.ApiUrl(this.config.env));try{let n=await t.getTransaction(r);return this.createFromTransaction(n)}catch(n){return console.error("Error creating warp 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}ensure(r,t){if(!r)throw new Error(`Warp: ${t}`)}async ensureValidSchema(){let r=this.config.schemaUrl||s.LatestSchemaUrl,n=await(await fetch(r)).json(),o=new W.default,a=o.compile(n);if(!a(this.pendingWarp))throw new Error(`Warp schema validation failed: ${o.errorsText(a.errors)}`)}};var i=require("@multiversx/sdk-core/out"),A=require("@multiversx/sdk-core/out/utils.codec");var l=class{config;registerCost;constructor(r){this.config=r,this.registerCost=BigInt(0)}async init(){await this.loadRegistryConfigs()}createRegisterTransaction(r,t){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 n=t?this.registerCost*BigInt(2):this.registerCost;return this.getFactory().createTransactionForExecute({sender:i.Address.newFromBech32(this.config.userAddress),contract:i.Address.newFromBech32(s.Registry.Contract(this.config.env)),function:"register",gasLimit:BigInt(1e7),nativeTransferAmount:n,arguments:t?[i.BytesValue.fromHex(r),i.BytesValue.fromUTF8(t)]:[i.BytesValue.fromHex(r)]})}createAliasAssignTransaction(r,t){if(!this.config.userAddress)throw new Error("registry config user address not set");return this.getFactory().createTransactionForExecute({sender:i.Address.newFromBech32(this.config.userAddress),contract:i.Address.newFromBech32(s.Registry.Contract(this.config.env)),function:"assignAlias",gasLimit:BigInt(1e7),arguments:[i.BytesValue.fromUTF8(r),i.BytesValue.fromUTF8(t)]})}async resolveAlias(r){let t=s.Registry.Contract(this.config.env),n=this.getController(),o=n.createQuery({contract:t,function:"resolveAlias",arguments:[i.BytesValue.fromUTF8(r)]}),a=await n.runQuery(o);console.log("resolveAlias res",a);let[c]=n.parseQueryResponse(a);return console.log("resolveAlias txHashRaw",c),(c==null?void 0:c.toString())||null}async loadRegistryConfigs(){let r=s.Registry.Contract(this.config.env),t=this.getController(),n=t.createQuery({contract:r,function:"getConfig",arguments:[]}),o=await t.runQuery(n),[a]=t.parseQueryResponse(o),c=BigInt("0x"+(0,A.byteArrayToHex)(a));this.registerCost=c}getFactory(){let r=new i.TransactionsFactoryConfig({chainID:h(this.config.env)});return new i.SmartContractTransactionsFactory({config:r})}getController(){let r=this.config.chainApiUrl||s.Chain.ApiUrl(this.config.env),t=new i.ApiNetworkProvider(r,{timeout:3e4}),n=new i.QueryRunnerAdapter({networkProvider:t});return new i.SmartContractQueriesController({queryRunner:n})}};var T="xwarp",q=":",d=class{constructor(r){this.config=r;this.config=r}build(r,t){return`${this.config.clientUrl||s.DefaultClientUrl(this.config.env)}?${T}=${encodeURIComponent(r)}${q}${encodeURIComponent(t)}`}async detect(r){let o=new URL(r).searchParams.get(T);if(!o)return{match:!1,warp:null};let[a,c]=o.split(q),w=new g(this.config),x=new l(this.config),u=null;if(a==="hash")u=await w.createFromTransactionHash(c);else if(a==="alias"){let v=await x.resolveAlias(c);v&&(u=await w.createFromTransactionHash(v))}return u?{match:!0,warp:u}:{match:!1,warp:null}}};0&&(module.exports={Config,WarpActionExecutor,WarpBuilder,WarpLink,WarpRegistry});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var i={ProtocolName:"warp",LatestVersion:"0.1.0",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:["text","number","bigint","boolean","address"],AvailableActionInputPositions:["value"]};var d=class{constructor(r){this.config=r;this.config=r}execute(r){throw new Error("not implemented")}};import{Address as v,ApiNetworkProvider as q,TransactionsFactoryConfig as F,TransferTransactionsFactory as I}from"@multiversx/sdk-core";var l=n=>n==="devnet"?"D":n==="testnet"?"T":"1",w=()=>`${i.ProtocolName}:${i.LatestVersion}`;var g=class{config;pendingWarp={protocol:w(),name:"",title:"",description:null,preview:"",actions:[]};constructor(r){this.config=r}createInscriptionTransaction(r){if(!this.config.userAddress)throw new Error("warp builder user address not set");let t=new F({chainID:l(this.config.env)}),e=new I({config:t}),s=JSON.stringify(r);return e.createTransactionForNativeTokenTransfer({sender:v.newFromBech32(this.config.userAddress),receiver:v.newFromBech32(this.config.userAddress),nativeAmount:BigInt(0),data:Buffer.from(s).valueOf()})}createFromRaw(r){return JSON.parse(r)}createFromTransaction(r){return this.createFromRaw(r.data.toString())}async createFromTransactionHash(r){let t=new q(this.config.chainApiUrl||i.Chain.ApiUrl(this.config.env));try{let e=await t.getTransaction(r);return this.createFromTransaction(e)}catch(e){return console.error("Error creating warp from transaction hash",e),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}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"),this.pendingWarp}ensure(r,t){if(!r)throw new Error(`Warp: ${t}`)}};import{Address as u,ApiNetworkProvider as x,BooleanValue as C,BytesValue as c,QueryRunnerAdapter as P,SmartContractQueriesController as R,SmartContractTransactionsFactory as B,TransactionsFactoryConfig as b}from"@multiversx/sdk-core/out";import{byteArrayToHex as U}from"@multiversx/sdk-core/out/utils.codec";var f=class{config;registerCost;constructor(r){this.config=r,this.registerCost=BigInt(0)}async init(){await this.loadRegistryInfo()}createRegisterTransaction(r,t){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=t.alias?this.registerCost*BigInt(2):this.registerCost;return this.getFactory().createTransactionForExecute({sender:u.newFromBech32(this.config.userAddress),contract:u.newFromBech32(i.Registry.Contract(this.config.env)),function:"register",gasLimit:BigInt(1e7),nativeTransferAmount:e,arguments:t.alias?[c.fromHex(r),new C(t.isPublic),c.fromUTF8(t.alias)]:[c.fromHex(r),new C(t.isPublic)]})}createAliasAssignTransaction(r,t){if(!this.config.userAddress)throw new Error("registry config user address not set");return this.getFactory().createTransactionForExecute({sender:u.newFromBech32(this.config.userAddress),contract:u.newFromBech32(i.Registry.Contract(this.config.env)),function:"assignAlias",gasLimit:BigInt(1e7),arguments:[c.fromUTF8(r),c.fromUTF8(t)]})}async resolveAlias(r){let t=i.Registry.Contract(this.config.env),e=this.getController(),s=e.createQuery({contract:t,function:"resolveAlias",arguments:[c.fromUTF8(r)]}),a=await e.runQuery(s);console.log("resolveAlias res",a);let[o]=e.parseQueryResponse(a);return console.log("resolveAlias txHashRaw",o),(o==null?void 0:o.toString())||null}async loadRegistryInfo(){let r=i.Registry.Contract(this.config.env),t=this.getController(),e=t.createQuery({contract:r,function:"getConfig",arguments:[]}),s=await t.runQuery(e),[a]=t.parseQueryResponse(s),o=BigInt("0x"+U(a));this.registerCost=o}getFactory(){let r=new b({chainID:l(this.config.env)});return new B({config:r})}getController(){let r=this.config.chainApiUrl||i.Chain.ApiUrl(this.config.env),t=new x(r,{timeout:3e4}),e=new P({networkProvider:t});return new R({queryRunner:e})}};var y="xwarp",W=":",A=class{constructor(r){this.config=r;this.config=r}build(r,t){return`${this.config.clientUrl||i.DefaultClientUrl(this.config.env)}?${y}=${encodeURIComponent(r)}${W}${encodeURIComponent(t)}`}async detect(r){let s=new URL(r).searchParams.get(y);if(!s)return{match:!1,warp:null};let[a,o]=s.split(W),m=new g(this.config),T=new f(this.config),p=null;if(a==="hash")p=await m.createFromTransactionHash(o);else if(a==="alias"){let h=await T.resolveAlias(o);h&&(p=await m.createFromTransactionHash(h))}return p?{match:!0,warp:p}:{match:!1,warp:null}}};export{i as Config,d as WarpActionExecutor,g as WarpBuilder,A as WarpLink,f as WarpRegistry};
1
+ var i={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:["text","number","bigint","boolean","address"],AvailableActionInputPositions:["value"]};var d=class{constructor(r){this.config=r;this.config=r}execute(r){throw new Error("not implemented")}};import{Address as v,ApiNetworkProvider as T,TransactionsFactoryConfig as q,TransferTransactionsFactory as x}from"@multiversx/sdk-core";import F from"ajv";var g=n=>n==="devnet"?"D":n==="testnet"?"T":"1",w=()=>`${i.ProtocolName}:${i.LatestVersion}`;var l=class{config;pendingWarp={protocol:w(),name:"",title:"",description:null,preview:"",actions:[]};constructor(r){this.config=r}createInscriptionTransaction(r){if(!this.config.userAddress)throw new Error("warp builder user address not set");let t=new q({chainID:g(this.config.env)}),e=new x({config:t}),o=JSON.stringify(r);return e.createTransactionForNativeTokenTransfer({sender:v.newFromBech32(this.config.userAddress),receiver:v.newFromBech32(this.config.userAddress),nativeAmount:BigInt(0),data:Buffer.from(o).valueOf()})}createFromRaw(r){return JSON.parse(r)}createFromTransaction(r){return this.createFromRaw(r.data.toString())}async createFromTransactionHash(r){let t=new T(this.config.chainApiUrl||i.Chain.ApiUrl(this.config.env));try{let e=await t.getTransaction(r);return this.createFromTransaction(e)}catch(e){return console.error("Error creating warp from transaction hash",e),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}ensure(r,t){if(!r)throw new Error(`Warp: ${t}`)}async ensureValidSchema(){let r=this.config.schemaUrl||i.LatestSchemaUrl,e=await(await fetch(r)).json(),o=new F,s=o.compile(e);if(!s(this.pendingWarp))throw new Error(`Warp schema validation failed: ${o.errorsText(s.errors)}`)}};import{Address as u,ApiNetworkProvider as I,BytesValue as c,QueryRunnerAdapter as P,SmartContractQueriesController as R,SmartContractTransactionsFactory as U,TransactionsFactoryConfig as B}from"@multiversx/sdk-core/out";import{byteArrayToHex as b}from"@multiversx/sdk-core/out/utils.codec";var m=class{config;registerCost;constructor(r){this.config=r,this.registerCost=BigInt(0)}async init(){await this.loadRegistryConfigs()}createRegisterTransaction(r,t){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=t?this.registerCost*BigInt(2):this.registerCost;return this.getFactory().createTransactionForExecute({sender:u.newFromBech32(this.config.userAddress),contract:u.newFromBech32(i.Registry.Contract(this.config.env)),function:"register",gasLimit:BigInt(1e7),nativeTransferAmount:e,arguments:t?[c.fromHex(r),c.fromUTF8(t)]:[c.fromHex(r)]})}createAliasAssignTransaction(r,t){if(!this.config.userAddress)throw new Error("registry config user address not set");return this.getFactory().createTransactionForExecute({sender:u.newFromBech32(this.config.userAddress),contract:u.newFromBech32(i.Registry.Contract(this.config.env)),function:"assignAlias",gasLimit:BigInt(1e7),arguments:[c.fromUTF8(r),c.fromUTF8(t)]})}async resolveAlias(r){let t=i.Registry.Contract(this.config.env),e=this.getController(),o=e.createQuery({contract:t,function:"resolveAlias",arguments:[c.fromUTF8(r)]}),s=await e.runQuery(o);console.log("resolveAlias res",s);let[a]=e.parseQueryResponse(s);return console.log("resolveAlias txHashRaw",a),(a==null?void 0:a.toString())||null}async loadRegistryConfigs(){let r=i.Registry.Contract(this.config.env),t=this.getController(),e=t.createQuery({contract:r,function:"getConfig",arguments:[]}),o=await t.runQuery(e),[s]=t.parseQueryResponse(o),a=BigInt("0x"+b(s));this.registerCost=a}getFactory(){let r=new B({chainID:g(this.config.env)});return new U({config:r})}getController(){let r=this.config.chainApiUrl||i.Chain.ApiUrl(this.config.env),t=new I(r,{timeout:3e4}),e=new P({networkProvider:t});return new R({queryRunner:e})}};var C="xwarp",y=":",W=class{constructor(r){this.config=r;this.config=r}build(r,t){return`${this.config.clientUrl||i.DefaultClientUrl(this.config.env)}?${C}=${encodeURIComponent(r)}${y}${encodeURIComponent(t)}`}async detect(r){let o=new URL(r).searchParams.get(C);if(!o)return{match:!1,warp:null};let[s,a]=o.split(y),h=new l(this.config),A=new m(this.config),p=null;if(s==="hash")p=await h.createFromTransactionHash(a);else if(s==="alias"){let f=await A.resolveAlias(a);f&&(p=await h.createFromTransactionHash(f))}return p?{match:!0,warp:p}:{match:!1,warp:null}}};export{i as Config,d as WarpActionExecutor,l as WarpBuilder,W as WarpLink,m as WarpRegistry};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vleap/warps",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,11 +20,11 @@
20
20
  "@multiversx/sdk-core": "^13.13.1"
21
21
  },
22
22
  "devDependencies": {
23
+ "@multiversx/sdk-core": "^13.13.1",
23
24
  "@types/jest": "^29.5.14",
24
25
  "jest": "^29.7.0",
25
26
  "jest-environment-jsdom": "^29.7.0",
26
27
  "jest-fetch-mock": "^3.0.3",
27
- "@multiversx/sdk-core": "^13.13.1",
28
28
  "react": "^18.3.1",
29
29
  "ts-jest": "^29.2.5",
30
30
  "tsup": "^8.3.5",
@@ -40,5 +40,7 @@
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  },
43
- "dependencies": {}
43
+ "dependencies": {
44
+ "ajv": "^8.17.1"
45
+ }
44
46
  }