@vleap/warps 0.0.31 → 0.0.33
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 +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -9,6 +9,14 @@ type WarpConfig = {
|
|
|
9
9
|
chainApiUrl?: string;
|
|
10
10
|
schemaUrl?: string;
|
|
11
11
|
};
|
|
12
|
+
type TrustStatus = 'unverified' | 'verified' | 'blacklisted';
|
|
13
|
+
type WarpInfo = {
|
|
14
|
+
hash: string;
|
|
15
|
+
alias: string | null;
|
|
16
|
+
trust: TrustStatus;
|
|
17
|
+
creator: string;
|
|
18
|
+
createdAt: number;
|
|
19
|
+
};
|
|
12
20
|
type WarpIdType = 'hash' | 'alias';
|
|
13
21
|
type Warp = {
|
|
14
22
|
protocol: string;
|
|
@@ -117,10 +125,10 @@ declare class WarpRegistry {
|
|
|
117
125
|
init(): Promise<void>;
|
|
118
126
|
createRegisterTransaction(txHash: string, alias?: string | null): Transaction;
|
|
119
127
|
createAliasAssignTransaction(txHash: string, alias: string): Transaction;
|
|
120
|
-
|
|
128
|
+
getInfoByAlias(alias: string): Promise<WarpInfo | null>;
|
|
121
129
|
private loadRegistryConfigs;
|
|
122
130
|
private getFactory;
|
|
123
131
|
private getController;
|
|
124
132
|
}
|
|
125
133
|
|
|
126
|
-
export { type ChainEnv, Config, type Warp, type WarpAction, type WarpActionExecutionResult, WarpActionExecutor, type WarpActionInput, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpConfig, type WarpContractAction, type WarpIdType, WarpLink, type WarpLinkAction, WarpRegistry };
|
|
134
|
+
export { type ChainEnv, Config, type TrustStatus, type Warp, type WarpAction, type WarpActionExecutionResult, WarpActionExecutor, type WarpActionInput, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpConfig, type WarpContractAction, type WarpIdType, type WarpInfo, WarpLink, type WarpLinkAction, WarpRegistry };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,14 @@ type WarpConfig = {
|
|
|
9
9
|
chainApiUrl?: string;
|
|
10
10
|
schemaUrl?: string;
|
|
11
11
|
};
|
|
12
|
+
type TrustStatus = 'unverified' | 'verified' | 'blacklisted';
|
|
13
|
+
type WarpInfo = {
|
|
14
|
+
hash: string;
|
|
15
|
+
alias: string | null;
|
|
16
|
+
trust: TrustStatus;
|
|
17
|
+
creator: string;
|
|
18
|
+
createdAt: number;
|
|
19
|
+
};
|
|
12
20
|
type WarpIdType = 'hash' | 'alias';
|
|
13
21
|
type Warp = {
|
|
14
22
|
protocol: string;
|
|
@@ -117,10 +125,10 @@ declare class WarpRegistry {
|
|
|
117
125
|
init(): Promise<void>;
|
|
118
126
|
createRegisterTransaction(txHash: string, alias?: string | null): Transaction;
|
|
119
127
|
createAliasAssignTransaction(txHash: string, alias: string): Transaction;
|
|
120
|
-
|
|
128
|
+
getInfoByAlias(alias: string): Promise<WarpInfo | null>;
|
|
121
129
|
private loadRegistryConfigs;
|
|
122
130
|
private getFactory;
|
|
123
131
|
private getController;
|
|
124
132
|
}
|
|
125
133
|
|
|
126
|
-
export { type ChainEnv, Config, type Warp, type WarpAction, type WarpActionExecutionResult, WarpActionExecutor, type WarpActionInput, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpConfig, type WarpContractAction, type WarpIdType, WarpLink, type WarpLinkAction, WarpRegistry };
|
|
134
|
+
export { type ChainEnv, Config, type TrustStatus, type Warp, type WarpAction, type WarpActionExecutionResult, WarpActionExecutor, type WarpActionInput, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, WarpBuilder, type WarpConfig, type WarpContractAction, type WarpIdType, type WarpInfo, WarpLink, type WarpLinkAction, WarpRegistry };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var B=Object.create;var g=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var S=(r,t)=>{for(var e in t)g(r,e,{get:t[e],enumerable:!0})},W=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of F(t))!P.call(r,o)&&o!==e&&g(r,o,{get:()=>t[o],enumerable:!(i=R(t,o))||i.enumerable});return r};var E=(r,t,e)=>(e=r!=null?B(U(r)):{},W(t||!r||!r.__esModule?g(e,"default",{value:r,enumerable:!0}):e,r)),N=r=>W(g({},"__esModule",{value:!0}),r);var k={};S(k,{Config:()=>s,WarpActionExecutor:()=>d,WarpBuilder:()=>u,WarpLink:()=>w,WarpRegistry:()=>l});module.exports=N(k);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:r=>r==="devnet"?"https://devnet.xwarp.me/to":r==="testnet"?"###Not implemented###":"https://xwarp.me/to",Chain:{ApiUrl:r=>r==="devnet"?"https://devnet-api.multiversx.com":r==="testnet"?"https://testnet-api.multiversx.com":"https://api.multiversx.com"},Registry:{Contract:r=>r==="devnet"?"erd1qqqqqqqqqqqqqpgq8h85eq9l3cp40h5s3ujqshj2x775m2wyl3tsl20ltn":r==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"},AvailableActionInputSources:["field","query"],AvailableActionInputTypes:["text","number","bigint","boolean","address"],AvailableActionInputPositions:["value"]};var d=class{constructor(t){this.config=t;this.config=t}execute(t){throw new Error("not implemented")}};var c=require("@multiversx/sdk-core"),b=E(require("ajv"));var f=r=>r==="devnet"?"D":r==="testnet"?"T":"1",A=()=>`${s.ProtocolName}:${s.LatestVersion}`,T=r=>{var t;return{hash:r.hash.toString("hex"),alias:((t=r.alias)==null?void 0:t.toString())||null,trust:r.trust.toString(),creator:r.creator.toString(),createdAt:r.createdAt.toNumber()}};var u=class{config;pendingWarp={protocol:A(),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 e=new c.TransactionsFactoryConfig({chainID:f(this.config.env)}),i=new c.TransferTransactionsFactory({config:e}),o=JSON.stringify(t);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(t){return JSON.parse(t)}createFromTransaction(t){return this.createFromRaw(t.data.toString())}async createFromTransactionHash(t){let e=new c.ApiNetworkProvider(this.config.chainApiUrl||s.Chain.ApiUrl(this.config.env));try{let i=await e.getTransaction(t);return this.createFromTransaction(i)}catch(i){return console.error("Error creating warp from transaction hash",i),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}ensure(t,e){if(!t)throw new Error(`Warp: ${e}`)}async ensureValidSchema(){let t=this.config.schemaUrl||s.LatestSchemaUrl,i=await(await fetch(t)).json(),o=new b.default,a=o.compile(i);if(!a(this.pendingWarp))throw new Error(`Warp schema validation failed: ${o.errorsText(a.errors)}`)}};var n=require("@multiversx/sdk-core/out"),I=require("@multiversx/sdk-core/out/utils.codec");var y={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:"register",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias_opt",type:"optional<bytes>",multi_arg:!0}],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"}]}],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 l=class{config;registerCost;constructor(t){this.config=t,this.registerCost=BigInt(0)}async init(){await this.loadRegistryConfigs()}createRegisterTransaction(t,e){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=e?this.registerCost*BigInt(2):this.registerCost;return this.getFactory().createTransactionForExecute({sender:n.Address.newFromBech32(this.config.userAddress),contract:n.Address.newFromBech32(s.Registry.Contract(this.config.env)),function:"register",gasLimit:BigInt(1e7),nativeTransferAmount:i,arguments:e?[n.BytesValue.fromHex(t),n.BytesValue.fromUTF8(e)]:[n.BytesValue.fromHex(t)]})}createAliasAssignTransaction(t,e){if(!this.config.userAddress)throw new Error("registry config user address not set");return this.getFactory().createTransactionForExecute({sender:n.Address.newFromBech32(this.config.userAddress),contract:n.Address.newFromBech32(s.Registry.Contract(this.config.env)),function:"assignAlias",gasLimit:BigInt(1e7),arguments:[n.BytesValue.fromUTF8(t),n.BytesValue.fromUTF8(e)]})}async getInfoByAlias(t){let e=s.Registry.Contract(this.config.env),i=this.getController(),o=i.createQuery({contract:e,function:"getInfoByAlias",arguments:[n.BytesValue.fromUTF8(t)]}),a=await i.runQuery(o),[p]=i.parseQueryResponse(a);return console.log("getInfoByAlias parsed",p),p?T(p):null}async loadRegistryConfigs(){let t=s.Registry.Contract(this.config.env),e=this.getController(),i=e.createQuery({contract:t,function:"getConfig",arguments:[]}),o=await e.runQuery(i),[a]=e.parseQueryResponse(o);console.log("loadRegistryConfigs registerCostRaw",a);let p=BigInt("0x"+(0,I.byteArrayToHex)(a));this.registerCost=p}getFactory(){let t=new n.TransactionsFactoryConfig({chainID:f(this.config.env)}),e=n.AbiRegistry.create(y);return new n.SmartContractTransactionsFactory({config:t,abi:e})}getController(){let t=this.config.chainApiUrl||s.Chain.ApiUrl(this.config.env),e=new n.ApiNetworkProvider(t,{timeout:3e4}),i=new n.QueryRunnerAdapter({networkProvider:e}),o=n.AbiRegistry.create(y);return new n.SmartContractQueriesController({queryRunner:i,abi:o})}};var q="xwarp",h=":",w=class{constructor(t){this.config=t;this.config=t}build(t,e){return`${this.config.clientUrl||s.DefaultClientUrl(this.config.env)}?${q}=${encodeURIComponent(t)}${h}${encodeURIComponent(e)}`}async detect(t){let o=new URL(t).searchParams.get(q);if(!o)return{match:!1,warp:null};let[a,p]=o.includes(h)?o.split(h):o.split(encodeURIComponent(h)),C=new u(this.config),x=new l(this.config),m=null;if(a==="hash")m=await C.createFromTransactionHash(p);else if(a==="alias"){let v=await x.getInfoByAlias(p);v&&(m=await C.createFromTransactionHash(v.hash))}return m?{match:!0,warp:m}:{match:!1,warp:null}}};0&&(module.exports={Config,WarpActionExecutor,WarpBuilder,WarpLink,WarpRegistry});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var o={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 w=class{constructor(t){this.config=t;this.config=t}execute(t){throw new Error("not implemented")}};import{Address as W,ApiNetworkProvider as q,TransactionsFactoryConfig as x,TransferTransactionsFactory as B}from"@multiversx/sdk-core";import R from"ajv";var u=e=>e==="devnet"?"D":e==="testnet"?"T":"1",C=()=>`${o.ProtocolName}:${o.LatestVersion}`,v=e=>{var t;return{hash:e.hash.toString("hex"),alias:((t=e.alias)==null?void 0:t.toString())||null,trust:e.trust.toString(),creator:e.creator.toString(),createdAt:e.createdAt.toNumber()}};var l=class{config;pendingWarp={protocol:C(),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 x({chainID:u(this.config.env)}),n=new B({config:r}),i=JSON.stringify(t);return n.createTransactionForNativeTokenTransfer({sender:W.newFromBech32(this.config.userAddress),receiver:W.newFromBech32(this.config.userAddress),nativeAmount:BigInt(0),data:Buffer.from(i).valueOf()})}createFromRaw(t){return JSON.parse(t)}createFromTransaction(t){return this.createFromRaw(t.data.toString())}async createFromTransactionHash(t){let r=new q(this.config.chainApiUrl||o.Chain.ApiUrl(this.config.env));try{let n=await r.getTransaction(t);return this.createFromTransaction(n)}catch(n){return console.error("Error creating warp from transaction hash",n),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}ensure(t,r){if(!t)throw new Error(`Warp: ${r}`)}async ensureValidSchema(){let t=this.config.schemaUrl||o.LatestSchemaUrl,n=await(await fetch(t)).json(),i=new R,s=i.compile(n);if(!s(this.pendingWarp))throw new Error(`Warp schema validation failed: ${i.errorsText(s.errors)}`)}};import{AbiRegistry as A,Address as m,ApiNetworkProvider as U,BytesValue as c,QueryRunnerAdapter as P,SmartContractQueriesController as S,SmartContractTransactionsFactory as E,TransactionsFactoryConfig as N}from"@multiversx/sdk-core/out";import{byteArrayToHex as j}from"@multiversx/sdk-core/out/utils.codec";var h={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:"register",mutability:"mutable",payableInTokens:["EGLD"],inputs:[{name:"hash",type:"bytes"},{name:"alias_opt",type:"optional<bytes>",multi_arg:!0}],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"}]}],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 g=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 n=r?this.registerCost*BigInt(2):this.registerCost;return this.getFactory().createTransactionForExecute({sender:m.newFromBech32(this.config.userAddress),contract:m.newFromBech32(o.Registry.Contract(this.config.env)),function:"register",gasLimit:BigInt(1e7),nativeTransferAmount:n,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:m.newFromBech32(this.config.userAddress),contract:m.newFromBech32(o.Registry.Contract(this.config.env)),function:"assignAlias",gasLimit:BigInt(1e7),arguments:[c.fromUTF8(t),c.fromUTF8(r)]})}async getInfoByAlias(t){let r=o.Registry.Contract(this.config.env),n=this.getController(),i=n.createQuery({contract:r,function:"getInfoByAlias",arguments:[c.fromUTF8(t)]}),s=await n.runQuery(i),[a]=n.parseQueryResponse(s);return console.log("getInfoByAlias parsed",a),a?v(a):null}async loadRegistryConfigs(){let t=o.Registry.Contract(this.config.env),r=this.getController(),n=r.createQuery({contract:t,function:"getConfig",arguments:[]}),i=await r.runQuery(n),[s]=r.parseQueryResponse(i);console.log("loadRegistryConfigs registerCostRaw",s);let a=BigInt("0x"+j(s));this.registerCost=a}getFactory(){let t=new N({chainID:u(this.config.env)}),r=A.create(h);return new E({config:t,abi:r})}getController(){let t=this.config.chainApiUrl||o.Chain.ApiUrl(this.config.env),r=new U(t,{timeout:3e4}),n=new P({networkProvider:r}),i=A.create(h);return new S({queryRunner:n,abi:i})}};var T="xwarp",f=":",b=class{constructor(t){this.config=t;this.config=t}build(t,r){return`${this.config.clientUrl||o.DefaultClientUrl(this.config.env)}?${T}=${encodeURIComponent(t)}${f}${encodeURIComponent(r)}`}async detect(t){let i=new URL(t).searchParams.get(T);if(!i)return{match:!1,warp:null};let[s,a]=i.includes(f)?i.split(f):i.split(encodeURIComponent(f)),d=new l(this.config),I=new g(this.config),p=null;if(s==="hash")p=await d.createFromTransactionHash(a);else if(s==="alias"){let y=await I.getInfoByAlias(a);y&&(p=await d.createFromTransactionHash(y.hash))}return p?{match:!0,warp:p}:{match:!1,warp:null}}};export{o as Config,w as WarpActionExecutor,l as WarpBuilder,b as WarpLink,g as WarpRegistry};
|