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