@vleap/warps 3.0.0-alpha.37 → 3.0.0-alpha.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,68 +1,6 @@
1
1
  import QRCodeStyling from 'qr-code-styling';
2
2
 
3
- declare const CacheTtl: {
4
- OneMinute: number;
5
- OneHour: number;
6
- OneDay: number;
7
- OneWeek: number;
8
- OneMonth: number;
9
- OneYear: number;
10
- };
11
- declare const WarpCacheKey: {
12
- Warp: (env: WarpChainEnv, id: string) => string;
13
- WarpAbi: (env: WarpChainEnv, id: string) => string;
14
- WarpExecutable: (env: WarpChainEnv, id: string, action: number) => string;
15
- RegistryInfo: (env: WarpChainEnv, id: string) => string;
16
- Brand: (env: WarpChainEnv, hash: string) => string;
17
- ChainInfo: (env: WarpChainEnv, chain: WarpChain) => string;
18
- ChainInfos: (env: WarpChainEnv) => string;
19
- };
20
- type CacheType = 'memory' | 'localStorage';
21
- declare class WarpCache {
22
- private strategy;
23
- constructor(type?: CacheType);
24
- private selectStrategy;
25
- set<T>(key: string, value: T, ttl: number): void;
26
- get<T>(key: string): T | null;
27
- forget(key: string): void;
28
- clear(): void;
29
- }
30
-
31
- type WarpChainEnv = 'mainnet' | 'testnet' | 'devnet';
32
- type ProtocolName = 'warp' | 'brand' | 'abi';
33
-
34
3
  type WarpChain = string;
35
- type WarpInitConfig = {
36
- env: WarpChainEnv;
37
- repository: Adapter;
38
- adapters: Adapter[];
39
- preferredChain?: WarpChain;
40
- clientUrl?: string;
41
- currentUrl?: string;
42
- vars?: Record<string, string | number>;
43
- user?: {
44
- wallet?: string;
45
- };
46
- schema?: {
47
- warp?: string;
48
- brand?: string;
49
- };
50
- cache?: {
51
- ttl?: number;
52
- type?: CacheType;
53
- };
54
- registry?: {
55
- contract?: string;
56
- };
57
- index?: {
58
- url?: string;
59
- apiKey?: string;
60
- searchParamName?: string;
61
- };
62
- };
63
- type WarpCacheConfig = {
64
- ttl?: number;
65
- };
66
4
  type WarpChainInfo = {
67
5
  name: WarpChain;
68
6
  displayName: string;
@@ -253,10 +191,10 @@ type WarpBrandMeta = {
253
191
  createdAt: string;
254
192
  };
255
193
 
256
- type InterpolationBag = {
257
- config: WarpInitConfig;
258
- chain: WarpChainInfo;
259
- };
194
+ type WarpCacheType = 'memory' | 'localStorage';
195
+
196
+ type WarpChainEnv = 'mainnet' | 'testnet' | 'devnet';
197
+ type ProtocolName = 'warp' | 'brand' | 'abi';
260
198
 
261
199
  type WarpTrustStatus = 'unverified' | 'verified' | 'blacklisted';
262
200
  type WarpRegistryInfo = {
@@ -292,21 +230,37 @@ type WarpExecutionNextInfo = {
292
230
  type WarpExecutionResults = Record<WarpResultName, any | null>;
293
231
  type WarpExecutionMessages = Record<WarpMessageName, string | null>;
294
232
 
295
- type WarpSearchResult = {
296
- hits: WarpSearchHit[];
233
+ type WarpInitConfig = {
234
+ env: WarpChainEnv;
235
+ repository: Adapter;
236
+ adapters: Adapter[];
237
+ preferredChain?: WarpChain;
238
+ clientUrl?: string;
239
+ currentUrl?: string;
240
+ vars?: Record<string, string | number>;
241
+ user?: {
242
+ wallet?: string;
243
+ };
244
+ schema?: {
245
+ warp?: string;
246
+ brand?: string;
247
+ };
248
+ cache?: {
249
+ ttl?: number;
250
+ type?: WarpCacheType;
251
+ };
252
+ registry?: {
253
+ contract?: string;
254
+ };
255
+ index?: {
256
+ url?: string;
257
+ apiKey?: string;
258
+ searchParamName?: string;
259
+ };
297
260
  };
298
- type WarpSearchHit = {
299
- hash: string;
300
- alias: string;
301
- name: string;
302
- title: string;
303
- description: string;
304
- preview: string;
305
- status: string;
306
- category: string;
307
- featured: boolean;
261
+ type WarpCacheConfig = {
262
+ ttl?: number;
308
263
  };
309
-
310
264
  type Adapter = {
311
265
  chain: WarpChain;
312
266
  builder: AdapterWarpBuilderConstructor;
@@ -379,6 +333,26 @@ interface AdapterWarpRegistry {
379
333
  fetchBrand(hash: string, cache?: WarpCacheConfig): Promise<WarpBrand | null>;
380
334
  }
381
335
 
336
+ type InterpolationBag = {
337
+ config: WarpInitConfig;
338
+ chain: WarpChainInfo;
339
+ };
340
+
341
+ type WarpSearchResult = {
342
+ hits: WarpSearchHit[];
343
+ };
344
+ type WarpSearchHit = {
345
+ hash: string;
346
+ alias: string;
347
+ name: string;
348
+ title: string;
349
+ description: string;
350
+ preview: string;
351
+ status: string;
352
+ category: string;
353
+ featured: boolean;
354
+ };
355
+
382
356
  declare const WarpProtocolVersions: {
383
357
  Warp: string;
384
358
  Brand: string;
@@ -548,6 +522,33 @@ declare class WarpBuilder {
548
522
  private validate;
549
523
  }
550
524
 
525
+ declare const CacheTtl: {
526
+ OneMinute: number;
527
+ OneHour: number;
528
+ OneDay: number;
529
+ OneWeek: number;
530
+ OneMonth: number;
531
+ OneYear: number;
532
+ };
533
+ declare const WarpCacheKey: {
534
+ Warp: (env: WarpChainEnv, id: string) => string;
535
+ WarpAbi: (env: WarpChainEnv, id: string) => string;
536
+ WarpExecutable: (env: WarpChainEnv, id: string, action: number) => string;
537
+ RegistryInfo: (env: WarpChainEnv, id: string) => string;
538
+ Brand: (env: WarpChainEnv, hash: string) => string;
539
+ ChainInfo: (env: WarpChainEnv, chain: WarpChain) => string;
540
+ ChainInfos: (env: WarpChainEnv) => string;
541
+ };
542
+ declare class WarpCache {
543
+ private strategy;
544
+ constructor(type?: WarpCacheType);
545
+ private selectStrategy;
546
+ set<T>(key: string, value: T, ttl: number): void;
547
+ get<T>(key: string): T | null;
548
+ forget(key: string): void;
549
+ clear(): void;
550
+ }
551
+
551
552
  type ExecutionHandlers = {
552
553
  onExecuted?: (result: WarpExecution) => void;
553
554
  };
@@ -658,4 +659,4 @@ declare class WarpValidator {
658
659
  private validateSchema;
659
660
  }
660
661
 
661
- export { type Adapter, type AdapterWarpBuilder, type AdapterWarpBuilderConstructor, type AdapterWarpExecutor, type AdapterWarpExecutorConstructor, type AdapterWarpRegistry, type AdapterWarpRegistryConstructor, type AdapterWarpResults, type AdapterWarpResultsConstructor, type AdapterWarpSerializer, type AdapterWarpSerializerConstructor, type BaseWarpActionInputType, CacheTtl, type CacheType, type InterpolationBag, type KnownToken, KnownTokens, type ProtocolName, type ResolvedInput, type Warp, type WarpAbi, type WarpAbiContents, type WarpAction, type WarpActionIndex, type WarpActionInput, type WarpActionInputModifier, type WarpActionInputPosition, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, type WarpAdapterGenericRemoteTransaction, type WarpAdapterGenericTransaction, type WarpAdapterGenericType, type WarpAdapterGenericValue, type WarpBrand, WarpBrandBuilder, type WarpBrandColors, type WarpBrandCta, type WarpBrandMeta, type WarpBrandUrls, WarpBuilder, WarpCache, type WarpCacheConfig, WarpCacheKey, type WarpChain, type WarpChainEnv, type WarpChainInfo, type WarpCollectAction, WarpConfig, WarpConstants, type WarpContract, type WarpContractAction, type WarpContractVerification, type WarpExecutable, type WarpExecution, type WarpExecutionMessages, type WarpExecutionNextInfo, type WarpExecutionResults, WarpExecutor, WarpFactory, type WarpIdType, WarpIndex, type WarpInitConfig, WarpInputTypes, WarpInterpolator, type WarpLinkAction, WarpLinkBuilder, WarpLinkDetecter, WarpLogger, type WarpMessageName, type WarpMeta, type WarpNativeValue, WarpProtocolVersions, type WarpQueryAction, type WarpRegistryConfigInfo, type WarpRegistryInfo, type WarpResultName, type WarpResulutionPath, type WarpSearchHit, type WarpSearchResult, WarpSerializer, type WarpTransferAction, type WarpTrustStatus, WarpUtils, WarpValidator, type WarpVarPlaceholder, address, applyResultsToMessages, biguint, boolean, evaluateResultsCommon, extractCollectResults, extractIdentifierInfoFromUrl, findKnownTokenById, getChainExplorerUrl, getLatestProtocolIdentifier, getMainChainInfo, getNextInfo, getWarpActionByIndex, getWarpInfoFromIdentifier, hex, parseResultsOutIndex, replacePlaceholders, shiftBigintBy, string, toPreviewText, toTypedChainInfo, u16, u32, u64, u8 };
662
+ export { type Adapter, type AdapterWarpBuilder, type AdapterWarpBuilderConstructor, type AdapterWarpExecutor, type AdapterWarpExecutorConstructor, type AdapterWarpRegistry, type AdapterWarpRegistryConstructor, type AdapterWarpResults, type AdapterWarpResultsConstructor, type AdapterWarpSerializer, type AdapterWarpSerializerConstructor, type BaseWarpActionInputType, CacheTtl, type InterpolationBag, type KnownToken, KnownTokens, type ProtocolName, type ResolvedInput, type Warp, type WarpAbi, type WarpAbiContents, type WarpAction, type WarpActionIndex, type WarpActionInput, type WarpActionInputModifier, type WarpActionInputPosition, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, type WarpAdapterGenericRemoteTransaction, type WarpAdapterGenericTransaction, type WarpAdapterGenericType, type WarpAdapterGenericValue, type WarpBrand, WarpBrandBuilder, type WarpBrandColors, type WarpBrandCta, type WarpBrandMeta, type WarpBrandUrls, WarpBuilder, WarpCache, type WarpCacheConfig, WarpCacheKey, type WarpChain, type WarpChainEnv, type WarpChainInfo, type WarpCollectAction, WarpConfig, WarpConstants, type WarpContract, type WarpContractAction, type WarpContractVerification, type WarpExecutable, type WarpExecution, type WarpExecutionMessages, type WarpExecutionNextInfo, type WarpExecutionResults, WarpExecutor, WarpFactory, type WarpIdType, WarpIndex, type WarpInitConfig, WarpInputTypes, WarpInterpolator, type WarpLinkAction, WarpLinkBuilder, WarpLinkDetecter, WarpLogger, type WarpMessageName, type WarpMeta, type WarpNativeValue, WarpProtocolVersions, type WarpQueryAction, type WarpRegistryConfigInfo, type WarpRegistryInfo, type WarpResultName, type WarpResulutionPath, type WarpSearchHit, type WarpSearchResult, WarpSerializer, type WarpTransferAction, type WarpTrustStatus, WarpUtils, WarpValidator, type WarpVarPlaceholder, address, applyResultsToMessages, biguint, boolean, evaluateResultsCommon, extractCollectResults, extractIdentifierInfoFromUrl, findKnownTokenById, getChainExplorerUrl, getLatestProtocolIdentifier, getMainChainInfo, getNextInfo, getWarpActionByIndex, getWarpInfoFromIdentifier, hex, parseResultsOutIndex, replacePlaceholders, shiftBigintBy, string, toPreviewText, toTypedChainInfo, u16, u32, u64, u8 };
package/dist/index.d.ts CHANGED
@@ -1,68 +1,6 @@
1
1
  import QRCodeStyling from 'qr-code-styling';
2
2
 
3
- declare const CacheTtl: {
4
- OneMinute: number;
5
- OneHour: number;
6
- OneDay: number;
7
- OneWeek: number;
8
- OneMonth: number;
9
- OneYear: number;
10
- };
11
- declare const WarpCacheKey: {
12
- Warp: (env: WarpChainEnv, id: string) => string;
13
- WarpAbi: (env: WarpChainEnv, id: string) => string;
14
- WarpExecutable: (env: WarpChainEnv, id: string, action: number) => string;
15
- RegistryInfo: (env: WarpChainEnv, id: string) => string;
16
- Brand: (env: WarpChainEnv, hash: string) => string;
17
- ChainInfo: (env: WarpChainEnv, chain: WarpChain) => string;
18
- ChainInfos: (env: WarpChainEnv) => string;
19
- };
20
- type CacheType = 'memory' | 'localStorage';
21
- declare class WarpCache {
22
- private strategy;
23
- constructor(type?: CacheType);
24
- private selectStrategy;
25
- set<T>(key: string, value: T, ttl: number): void;
26
- get<T>(key: string): T | null;
27
- forget(key: string): void;
28
- clear(): void;
29
- }
30
-
31
- type WarpChainEnv = 'mainnet' | 'testnet' | 'devnet';
32
- type ProtocolName = 'warp' | 'brand' | 'abi';
33
-
34
3
  type WarpChain = string;
35
- type WarpInitConfig = {
36
- env: WarpChainEnv;
37
- repository: Adapter;
38
- adapters: Adapter[];
39
- preferredChain?: WarpChain;
40
- clientUrl?: string;
41
- currentUrl?: string;
42
- vars?: Record<string, string | number>;
43
- user?: {
44
- wallet?: string;
45
- };
46
- schema?: {
47
- warp?: string;
48
- brand?: string;
49
- };
50
- cache?: {
51
- ttl?: number;
52
- type?: CacheType;
53
- };
54
- registry?: {
55
- contract?: string;
56
- };
57
- index?: {
58
- url?: string;
59
- apiKey?: string;
60
- searchParamName?: string;
61
- };
62
- };
63
- type WarpCacheConfig = {
64
- ttl?: number;
65
- };
66
4
  type WarpChainInfo = {
67
5
  name: WarpChain;
68
6
  displayName: string;
@@ -253,10 +191,10 @@ type WarpBrandMeta = {
253
191
  createdAt: string;
254
192
  };
255
193
 
256
- type InterpolationBag = {
257
- config: WarpInitConfig;
258
- chain: WarpChainInfo;
259
- };
194
+ type WarpCacheType = 'memory' | 'localStorage';
195
+
196
+ type WarpChainEnv = 'mainnet' | 'testnet' | 'devnet';
197
+ type ProtocolName = 'warp' | 'brand' | 'abi';
260
198
 
261
199
  type WarpTrustStatus = 'unverified' | 'verified' | 'blacklisted';
262
200
  type WarpRegistryInfo = {
@@ -292,21 +230,37 @@ type WarpExecutionNextInfo = {
292
230
  type WarpExecutionResults = Record<WarpResultName, any | null>;
293
231
  type WarpExecutionMessages = Record<WarpMessageName, string | null>;
294
232
 
295
- type WarpSearchResult = {
296
- hits: WarpSearchHit[];
233
+ type WarpInitConfig = {
234
+ env: WarpChainEnv;
235
+ repository: Adapter;
236
+ adapters: Adapter[];
237
+ preferredChain?: WarpChain;
238
+ clientUrl?: string;
239
+ currentUrl?: string;
240
+ vars?: Record<string, string | number>;
241
+ user?: {
242
+ wallet?: string;
243
+ };
244
+ schema?: {
245
+ warp?: string;
246
+ brand?: string;
247
+ };
248
+ cache?: {
249
+ ttl?: number;
250
+ type?: WarpCacheType;
251
+ };
252
+ registry?: {
253
+ contract?: string;
254
+ };
255
+ index?: {
256
+ url?: string;
257
+ apiKey?: string;
258
+ searchParamName?: string;
259
+ };
297
260
  };
298
- type WarpSearchHit = {
299
- hash: string;
300
- alias: string;
301
- name: string;
302
- title: string;
303
- description: string;
304
- preview: string;
305
- status: string;
306
- category: string;
307
- featured: boolean;
261
+ type WarpCacheConfig = {
262
+ ttl?: number;
308
263
  };
309
-
310
264
  type Adapter = {
311
265
  chain: WarpChain;
312
266
  builder: AdapterWarpBuilderConstructor;
@@ -379,6 +333,26 @@ interface AdapterWarpRegistry {
379
333
  fetchBrand(hash: string, cache?: WarpCacheConfig): Promise<WarpBrand | null>;
380
334
  }
381
335
 
336
+ type InterpolationBag = {
337
+ config: WarpInitConfig;
338
+ chain: WarpChainInfo;
339
+ };
340
+
341
+ type WarpSearchResult = {
342
+ hits: WarpSearchHit[];
343
+ };
344
+ type WarpSearchHit = {
345
+ hash: string;
346
+ alias: string;
347
+ name: string;
348
+ title: string;
349
+ description: string;
350
+ preview: string;
351
+ status: string;
352
+ category: string;
353
+ featured: boolean;
354
+ };
355
+
382
356
  declare const WarpProtocolVersions: {
383
357
  Warp: string;
384
358
  Brand: string;
@@ -548,6 +522,33 @@ declare class WarpBuilder {
548
522
  private validate;
549
523
  }
550
524
 
525
+ declare const CacheTtl: {
526
+ OneMinute: number;
527
+ OneHour: number;
528
+ OneDay: number;
529
+ OneWeek: number;
530
+ OneMonth: number;
531
+ OneYear: number;
532
+ };
533
+ declare const WarpCacheKey: {
534
+ Warp: (env: WarpChainEnv, id: string) => string;
535
+ WarpAbi: (env: WarpChainEnv, id: string) => string;
536
+ WarpExecutable: (env: WarpChainEnv, id: string, action: number) => string;
537
+ RegistryInfo: (env: WarpChainEnv, id: string) => string;
538
+ Brand: (env: WarpChainEnv, hash: string) => string;
539
+ ChainInfo: (env: WarpChainEnv, chain: WarpChain) => string;
540
+ ChainInfos: (env: WarpChainEnv) => string;
541
+ };
542
+ declare class WarpCache {
543
+ private strategy;
544
+ constructor(type?: WarpCacheType);
545
+ private selectStrategy;
546
+ set<T>(key: string, value: T, ttl: number): void;
547
+ get<T>(key: string): T | null;
548
+ forget(key: string): void;
549
+ clear(): void;
550
+ }
551
+
551
552
  type ExecutionHandlers = {
552
553
  onExecuted?: (result: WarpExecution) => void;
553
554
  };
@@ -658,4 +659,4 @@ declare class WarpValidator {
658
659
  private validateSchema;
659
660
  }
660
661
 
661
- export { type Adapter, type AdapterWarpBuilder, type AdapterWarpBuilderConstructor, type AdapterWarpExecutor, type AdapterWarpExecutorConstructor, type AdapterWarpRegistry, type AdapterWarpRegistryConstructor, type AdapterWarpResults, type AdapterWarpResultsConstructor, type AdapterWarpSerializer, type AdapterWarpSerializerConstructor, type BaseWarpActionInputType, CacheTtl, type CacheType, type InterpolationBag, type KnownToken, KnownTokens, type ProtocolName, type ResolvedInput, type Warp, type WarpAbi, type WarpAbiContents, type WarpAction, type WarpActionIndex, type WarpActionInput, type WarpActionInputModifier, type WarpActionInputPosition, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, type WarpAdapterGenericRemoteTransaction, type WarpAdapterGenericTransaction, type WarpAdapterGenericType, type WarpAdapterGenericValue, type WarpBrand, WarpBrandBuilder, type WarpBrandColors, type WarpBrandCta, type WarpBrandMeta, type WarpBrandUrls, WarpBuilder, WarpCache, type WarpCacheConfig, WarpCacheKey, type WarpChain, type WarpChainEnv, type WarpChainInfo, type WarpCollectAction, WarpConfig, WarpConstants, type WarpContract, type WarpContractAction, type WarpContractVerification, type WarpExecutable, type WarpExecution, type WarpExecutionMessages, type WarpExecutionNextInfo, type WarpExecutionResults, WarpExecutor, WarpFactory, type WarpIdType, WarpIndex, type WarpInitConfig, WarpInputTypes, WarpInterpolator, type WarpLinkAction, WarpLinkBuilder, WarpLinkDetecter, WarpLogger, type WarpMessageName, type WarpMeta, type WarpNativeValue, WarpProtocolVersions, type WarpQueryAction, type WarpRegistryConfigInfo, type WarpRegistryInfo, type WarpResultName, type WarpResulutionPath, type WarpSearchHit, type WarpSearchResult, WarpSerializer, type WarpTransferAction, type WarpTrustStatus, WarpUtils, WarpValidator, type WarpVarPlaceholder, address, applyResultsToMessages, biguint, boolean, evaluateResultsCommon, extractCollectResults, extractIdentifierInfoFromUrl, findKnownTokenById, getChainExplorerUrl, getLatestProtocolIdentifier, getMainChainInfo, getNextInfo, getWarpActionByIndex, getWarpInfoFromIdentifier, hex, parseResultsOutIndex, replacePlaceholders, shiftBigintBy, string, toPreviewText, toTypedChainInfo, u16, u32, u64, u8 };
662
+ export { type Adapter, type AdapterWarpBuilder, type AdapterWarpBuilderConstructor, type AdapterWarpExecutor, type AdapterWarpExecutorConstructor, type AdapterWarpRegistry, type AdapterWarpRegistryConstructor, type AdapterWarpResults, type AdapterWarpResultsConstructor, type AdapterWarpSerializer, type AdapterWarpSerializerConstructor, type BaseWarpActionInputType, CacheTtl, type InterpolationBag, type KnownToken, KnownTokens, type ProtocolName, type ResolvedInput, type Warp, type WarpAbi, type WarpAbiContents, type WarpAction, type WarpActionIndex, type WarpActionInput, type WarpActionInputModifier, type WarpActionInputPosition, type WarpActionInputSource, type WarpActionInputType, type WarpActionType, type WarpAdapterGenericRemoteTransaction, type WarpAdapterGenericTransaction, type WarpAdapterGenericType, type WarpAdapterGenericValue, type WarpBrand, WarpBrandBuilder, type WarpBrandColors, type WarpBrandCta, type WarpBrandMeta, type WarpBrandUrls, WarpBuilder, WarpCache, type WarpCacheConfig, WarpCacheKey, type WarpChain, type WarpChainEnv, type WarpChainInfo, type WarpCollectAction, WarpConfig, WarpConstants, type WarpContract, type WarpContractAction, type WarpContractVerification, type WarpExecutable, type WarpExecution, type WarpExecutionMessages, type WarpExecutionNextInfo, type WarpExecutionResults, WarpExecutor, WarpFactory, type WarpIdType, WarpIndex, type WarpInitConfig, WarpInputTypes, WarpInterpolator, type WarpLinkAction, WarpLinkBuilder, WarpLinkDetecter, WarpLogger, type WarpMessageName, type WarpMeta, type WarpNativeValue, WarpProtocolVersions, type WarpQueryAction, type WarpRegistryConfigInfo, type WarpRegistryInfo, type WarpResultName, type WarpResulutionPath, type WarpSearchHit, type WarpSearchResult, WarpSerializer, type WarpTransferAction, type WarpTrustStatus, WarpUtils, WarpValidator, type WarpVarPlaceholder, address, applyResultsToMessages, biguint, boolean, evaluateResultsCommon, extractCollectResults, extractIdentifierInfoFromUrl, findKnownTokenById, getChainExplorerUrl, getLatestProtocolIdentifier, getMainChainInfo, getNextInfo, getWarpActionByIndex, getWarpInfoFromIdentifier, hex, parseResultsOutIndex, replacePlaceholders, shiftBigintBy, string, toPreviewText, toTypedChainInfo, u16, u32, u64, u8 };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import"./chunk-3SAEGOMQ.mjs";var c={HttpProtocolPrefix:"http",IdentifierParamName:"warp",IdentifierParamSeparator:":",IdentifierType:{Alias:"alias",Hash:"hash"},Source:{UserWallet:"user:wallet"},Globals:{UserWallet:{Placeholder:"USER_WALLET",Accessor:i=>i.config.user?.wallet},ChainApiUrl:{Placeholder:"CHAIN_API",Accessor:i=>i.chain.apiUrl},ChainExplorerUrl:{Placeholder:"CHAIN_EXPLORER",Accessor:i=>i.chain.explorerUrl}},Vars:{Query:"query",Env:"env"},ArgParamsSeparator:":",ArgCompositeSeparator:"|",Transform:{Prefix:"transform:"}},w={Option:"option",Optional:"optional",List:"list",Variadic:"variadic",Composite:"composite",String:"string",U8:"u8",U16:"u16",U32:"u32",U64:"u64",Biguint:"biguint",Boolean:"boolean",Address:"address",Hex:"hex"};var R={Warp:"3.0.0",Brand:"0.1.0",Abi:"0.1.0"},h={LatestWarpSchemaUrl:`https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/v${R.Warp}.schema.json`,LatestBrandSchemaUrl:`https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/brand/v${R.Brand}.schema.json`,DefaultClientUrl:i=>i==="devnet"?"https://devnet.usewarp.to":i==="testnet"?"https://testnet.usewarp.to":"https://usewarp.to",SuperClientUrls:["https://usewarp.to","https://testnet.usewarp.to","https://devnet.usewarp.to"],MainChain:{Name:"multiversx",DisplayName:"MultiversX",ApiUrl:i=>i==="devnet"?"https://devnet-api.multiversx.com":i==="testnet"?"https://testnet-api.multiversx.com":"https://api.multiversx.com",ExplorerUrl:i=>i==="devnet"?"https://devnet-explorer.multiversx.com":i==="testnet"?"https://testnet-explorer.multiversx.com":"https://explorer.multiversx.com",BlockTime:i=>6e3,AddressHrp:"erd",ChainId:i=>i==="devnet"?"D":i==="testnet"?"T":"1",NativeToken:"EGLD"},Registry:{Contract:i=>i==="devnet"?"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36":i==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"},AvailableActionInputSources:["field","query",c.Source.UserWallet],AvailableActionInputTypes:["string","uint8","uint16","uint32","uint64","biguint","boolean","address"],AvailableActionInputPositions:["receiver","value","transfer","arg:1","arg:2","arg:3","arg:4","arg:5","arg:6","arg:7","arg:8","arg:9","arg:10","data","ignore"]};var N=i=>({name:h.MainChain.Name,displayName:h.MainChain.DisplayName,chainId:h.MainChain.ChainId(i.env),blockTime:h.MainChain.BlockTime(i.env),addressHrp:h.MainChain.AddressHrp,apiUrl:h.MainChain.ApiUrl(i.env),explorerUrl:h.MainChain.ExplorerUrl(i.env),nativeToken:h.MainChain.NativeToken}),vt=(i,t)=>i.explorerUrl+(t?"/"+t:""),O=i=>{if(i==="warp")return`warp:${R.Warp}`;if(i==="brand")return`brand:${R.Brand}`;if(i==="abi")return`abi:${R.Abi}`;throw new Error(`getLatestProtocolIdentifier: Invalid protocol name: ${i}`)},E=(i,t)=>i?.actions[t-1],It=i=>({name:i.name.toString(),displayName:i.display_name.toString(),chainId:i.chain_id.toString(),blockTime:i.block_time.toNumber(),addressHrp:i.address_hrp.toString(),apiUrl:i.api_url.toString(),explorerUrl:i.explorer_url.toString(),nativeToken:i.native_token.toString()}),M=(i,t)=>{let r=i.toString(),[e,n=""]=r.split("."),a=Math.abs(t);if(t>0)return BigInt(e+n.padEnd(a,"0"));if(t<0){let s=e+n;if(a>=s.length)return 0n;let o=s.slice(0,-a)||"0";return BigInt(o)}else return r.includes(".")?BigInt(r.split(".")[0]):BigInt(r)},Q=(i,t=100)=>{if(!i)return"";let r=i.replace(/<\/?(h[1-6])[^>]*>/gi," - ").replace(/<\/?(p|div|ul|ol|li|br|hr)[^>]*>/gi," ").replace(/<[^>]+>/g,"").replace(/\s+/g," ").trim();return r=r.startsWith("- ")?r.slice(2):r,r=r.length>t?r.substring(0,r.lastIndexOf(" ",t))+"...":r,r},G=(i,t)=>i.replace(/\{\{([^}]+)\}\}/g,(r,e)=>t[e]||""),_=(i,t)=>{let r=Object.entries(i.messages||{}).map(([e,n])=>[e,G(n,t)]);return Object.fromEntries(r)};var S=i=>{let t=decodeURIComponent(i);if(t.includes(c.IdentifierParamSeparator)){let[e,n]=t.split(c.IdentifierParamSeparator),a=n.split("?")[0];return{type:e,identifier:n,identifierBase:a}}let r=t.split("?")[0];return r.length===64?{type:c.IdentifierType.Hash,identifier:t,identifierBase:r}:{type:c.IdentifierType.Alias,identifier:t,identifierBase:r}},V=i=>{let t=new URL(i),r=h.SuperClientUrls.includes(t.origin),e=t.searchParams.get(c.IdentifierParamName),n=r&&!e?t.pathname.split("/")[1]:e;if(!n)return null;let a=decodeURIComponent(n);return S(a)};import at from"qr-code-styling";var k=class{constructor(t){this.config=t;this.config=t}isValid(t){return t.startsWith(c.HttpProtocolPrefix)?!!V(t):!1}build(t,r){let e=this.config.clientUrl||h.DefaultClientUrl(this.config.env),n=t===c.IdentifierType.Alias?encodeURIComponent(r):encodeURIComponent(t+c.IdentifierParamSeparator+r);return h.SuperClientUrls.includes(e)?`${e}/${n}`:`${e}?${c.IdentifierParamName}=${n}`}buildFromPrefixedIdentifier(t){let r=S(t);return r?this.build(r.type,r.identifierBase):""}generateQrCode(t,r,e=512,n="white",a="black",s="#23F7DD"){let o=this.build(t,r);return new at({type:"svg",width:e,height:e,data:String(o),margin:16,qrOptions:{typeNumber:0,mode:"Byte",errorCorrectionLevel:"Q"},backgroundOptions:{color:n},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(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>`})}};var st="https://",X=(i,t,r,e)=>{let n=t.actions?.[r]?.next||t.next||null;if(!n)return null;if(n.startsWith(st))return[{identifier:null,url:n}];let[a,s]=n.split("?");if(!s)return[{identifier:a,url:z(a,i)}];let o=s.match(/{{([^}]+)\[\](\.[^}]+)?}}/g)||[];if(o.length===0){let f=G(s,{...t.vars,...e}),g=f?`${a}?${f}`:a;return[{identifier:g,url:z(g,i)}]}let l=o[0];if(!l)return[];let p=l.match(/{{([^[]+)\[\]/),u=p?p[1]:null;if(!u||e[u]===void 0)return[];let W=Array.isArray(e[u])?e[u]:[e[u]];if(W.length===0)return[];let d=o.filter(f=>f.includes(`{{${u}[]`)).map(f=>{let g=f.match(/\[\](\.[^}]+)?}}/),x=g&&g[1]||"";return{placeholder:f,field:x?x.slice(1):"",regex:new RegExp(f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g")}});return W.map(f=>{let g=s;for(let{regex:m,field:y}of d){let T=y?ot(f,y):f;if(T==null)return null;g=g.replace(m,T)}if(g.includes("{{")||g.includes("}}"))return null;let x=g?`${a}?${g}`:a;return{identifier:x,url:z(x,i)}}).filter(f=>f!==null)},z=(i,t)=>{let[r,e]=i.split("?"),n=S(r)||{type:"alias",identifier:r,identifierBase:r},s=new k(t).build(n.type,n.identifierBase);if(!e)return s;let o=new URL(s);return new URLSearchParams(e).forEach((l,p)=>o.searchParams.set(p,l)),o.toString().replace(/\/\?/,"?")},ot=(i,t)=>t.split(".").reduce((r,e)=>r?.[e],i);var P=class P{static info(...t){P.isTestEnv||console.info(...t)}static warn(...t){P.isTestEnv||console.warn(...t)}static error(...t){P.isTestEnv||console.error(...t)}};P.isTestEnv=typeof process<"u"&&process.env.JEST_WORKER_ID!==void 0;var v=P;var A=class{nativeToString(t,r){return`${t}:${r?.toString()??""}`}stringToNative(t){let r=t.split(c.ArgParamsSeparator),e=r[0],n=r.slice(1).join(c.ArgParamsSeparator);if(e==="null")return[e,null];if(e==="option"){let[a,s]=n.split(c.ArgParamsSeparator);return[`option:${a}`,s||null]}else if(e==="optional"){let[a,s]=n.split(c.ArgParamsSeparator);return[`optional:${a}`,s||null]}else if(e==="list"){let a=n.split(c.ArgParamsSeparator),s=a.slice(0,-1).join(c.ArgParamsSeparator),o=a[a.length-1],p=(o?o.split(","):[]).map(u=>this.stringToNative(`${s}:${u}`)[1]);return[`list:${s}`,p]}else if(e==="variadic"){let a=n.split(c.ArgParamsSeparator),s=a.slice(0,-1).join(c.ArgParamsSeparator),o=a[a.length-1],p=(o?o.split(","):[]).map(u=>this.stringToNative(`${s}:${u}`)[1]);return[`variadic:${s}`,p]}else if(e.startsWith("composite")){let a=e.match(/\(([^)]+)\)/)?.[1]?.split(c.ArgCompositeSeparator),o=n.split(c.ArgCompositeSeparator).map((l,p)=>this.stringToNative(`${a[p]}:${l}`)[1]);return[e,o]}else{if(e==="string")return[e,n];if(e==="uint8"||e==="uint16"||e==="uint32")return[e,Number(n)];if(e==="uint64"||e==="biguint")return[e,BigInt(n||0)];if(e==="bool")return[e,n==="true"];if(e==="address")return[e,n];if(e==="token")return[e,n];if(e==="hex")return[e,n];if(e==="codemeta")return[e,n];if(e==="esdt"){let[a,s,o]=n.split(c.ArgCompositeSeparator);return[e,`${a}|${s}|${o}`]}}throw new Error(`WarpArgSerializer (stringToNative): Unsupported input type: ${e}`)}};var Y=async(i,t,r,e)=>{let n=[],a={};for(let[s,o]of Object.entries(i.results||{})){if(o.startsWith(c.Transform.Prefix))continue;let l=ut(o);if(l!==null&&l!==r){a[s]=null;continue}let[p,...u]=o.split("."),W=(d,I)=>I.reduce((f,g)=>f&&f[g]!==void 0?f[g]:null,d);if(p==="out"||p.startsWith("out[")){let d=u.length===0?t?.data||t:W(t,u);n.push(d),a[s]=d}else a[s]=o}return{values:n,results:await pt(i,a,r,e)}},pt=async(i,t,r,e)=>{if(!i.results)return t;let n={...t};return n=lt(n,i,r,e),n=await ct(i,n),n},lt=(i,t,r,e)=>{let n={...i},a=E(t,r)?.inputs||[],s=new A;for(let[o,l]of Object.entries(n))if(typeof l=="string"&&l.startsWith("input.")){let p=l.split(".")[1],u=a.findIndex(d=>d.as===p||d.name===p),W=u!==-1?e[u]?.value:null;n[o]=W?s.stringToNative(W)[1]:null}return n},ct=async(i,t)=>{if(!i.results)return t;let r={...t},e=Object.entries(i.results).filter(([,n])=>n.startsWith(c.Transform.Prefix)).map(([n,a])=>({key:n,code:a.substring(c.Transform.Prefix.length)}));for(let{key:n,code:a}of e)try{let s;typeof window>"u"?s=(await import("./runInVm-BFUZVHHD.mjs")).runInVm:s=(await import("./runInVm-5YQ766M3.mjs")).runInVm,r[n]=await s(a,r)}catch(s){v.error(`Transform error for result '${n}':`,s),r[n]=null}return r},ut=i=>{if(i==="out")return 1;let t=i.match(/^out\[(\d+)\]/);return t?parseInt(t[1],10):(i.startsWith("out.")||i.startsWith("event."),null)};var dt=[{id:"EGLD",name:"eGold",decimals:18},{id:"EGLD-000000",name:"eGold",decimals:18},{id:"VIBE-000000",name:"VIBE",decimals:18}],Kt=i=>dt.find(t=>t.id===i)||null;var ir=i=>`${w.String}:${i}`,ar=i=>`${w.U8}:${i}`,sr=i=>`${w.U16}:${i}`,or=i=>`${w.U32}:${i}`,pr=i=>`${w.U64}:${i}`,lr=i=>`${w.Biguint}:${i}`,cr=i=>`${w.Boolean}:${i}`,ur=i=>`${w.Address}:${i}`,dr=i=>`${w.Hex}:${i}`;import ft from"ajv";var Z=class{constructor(t){this.pendingBrand={protocol:O("brand"),name:"",description:"",logo:""};this.config=t}async createFromRaw(t,r=!0){let e=JSON.parse(t);return r&&await this.ensureValidSchema(e),e}setName(t){return this.pendingBrand.name=t,this}setDescription(t){return this.pendingBrand.description=t,this}setLogo(t){return this.pendingBrand.logo=t,this}setUrls(t){return this.pendingBrand.urls=t,this}setColors(t){return this.pendingBrand.colors=t,this}setCta(t){return this.pendingBrand.cta=t,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(t,r){if(!t)throw new Error(`Warp: ${r}`)}async ensureValidSchema(t){let r=this.config.schema?.brand||h.LatestBrandSchemaUrl,n=await(await fetch(r)).json(),a=new ft,s=a.compile(n);if(!s(t))throw new Error(`BrandBuilder: schema validation failed: ${a.errorsText(s.errors)}`)}};import gt from"ajv";var j=class{constructor(t){this.config=t;this.config=t}async validate(t){let r=[];return r.push(...this.validateMaxOneValuePosition(t)),r.push(...this.validateVariableNamesAndResultNamesUppercase(t)),r.push(...this.validateAbiIsSetIfApplicable(t)),r.push(...await this.validateSchema(t)),{valid:r.length===0,errors:r}}validateMaxOneValuePosition(t){return t.actions.filter(e=>e.inputs?e.inputs.some(n=>n.position==="value"):!1).length>1?["Only one value position action is allowed"]:[]}validateVariableNamesAndResultNamesUppercase(t){let r=[],e=(n,a)=>{n&&Object.keys(n).forEach(s=>{s!==s.toUpperCase()&&r.push(`${a} name '${s}' must be uppercase`)})};return e(t.vars,"Variable"),e(t.results,"Result"),r}validateAbiIsSetIfApplicable(t){let r=t.actions.some(s=>s.type==="contract"),e=t.actions.some(s=>s.type==="query");if(!r&&!e)return[];let n=t.actions.some(s=>s.abi),a=Object.values(t.results||{}).some(s=>s.startsWith("out.")||s.startsWith("event."));return t.results&&!n&&a?["ABI is required when results are present for contract or query actions"]:[]}async validateSchema(t){try{let r=this.config.schema?.warp||h.LatestWarpSchemaUrl,n=await(await fetch(r)).json(),a=new gt({strict:!1}),s=a.compile(n);return s(t)?[]:[`Schema validation failed: ${a.errorsText(s.errors)}`]}catch(r){return[`Schema validation failed: ${r instanceof Error?r.message:String(r)}`]}}};var tt=class{constructor(t){this.pendingWarp={protocol:O("warp"),name:"",title:"",description:null,preview:"",actions:[]};this.config=t,this.adapterBuilder=new t.repository.builder(t)}createInscriptionTransaction(t){return this.adapterBuilder.createInscriptionTransaction(t)}async createFromTransaction(t,r=!1){return this.adapterBuilder.createFromTransaction(t,r)}async createFromTransactionHash(t,r){return this.adapterBuilder.createFromTransactionHash(t,r)}async createFromRaw(t,r=!0){let e=JSON.parse(t);return r&&await this.validate(e),e}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.validate(this.pendingWarp),this.pendingWarp}getDescriptionPreview(t,r=100){return Q(t,r)}ensure(t,r){if(!t)throw new Error(r)}async validate(t){let e=await new j(this.config).validate(t);if(!e.valid)throw new Error(e.errors.join(`
2
- `))}};var q=class{constructor(t="warp-cache"){this.prefix=t}getKey(t){return`${this.prefix}:${t}`}get(t){try{let r=localStorage.getItem(this.getKey(t));if(!r)return null;let e=JSON.parse(r);return Date.now()>e.expiresAt?(localStorage.removeItem(this.getKey(t)),null):e.value}catch{return null}}set(t,r,e){let n={value:r,expiresAt:Date.now()+e*1e3};localStorage.setItem(this.getKey(t),JSON.stringify(n))}forget(t){localStorage.removeItem(this.getKey(t))}clear(){for(let t=0;t<localStorage.length;t++){let r=localStorage.key(t);r?.startsWith(this.prefix)&&localStorage.removeItem(r)}}};var b=class b{get(t){let r=b.cache.get(t);return r?Date.now()>r.expiresAt?(b.cache.delete(t),null):r.value:null}set(t,r,e){let n=Date.now()+e*1e3;b.cache.set(t,{value:r,expiresAt:n})}forget(t){b.cache.delete(t)}clear(){b.cache.clear()}};b.cache=new Map;var L=b;var F={OneMinute:60,OneHour:60*60,OneDay:60*60*24,OneWeek:60*60*24*7,OneMonth:60*60*24*30,OneYear:60*60*24*365},rt={Warp:(i,t)=>`warp:${i}:${t}`,WarpAbi:(i,t)=>`warp-abi:${i}:${t}`,WarpExecutable:(i,t,r)=>`warp-exec:${i}:${t}:${r}`,RegistryInfo:(i,t)=>`registry-info:${i}:${t}`,Brand:(i,t)=>`brand:${i}:${t}`,ChainInfo:(i,t)=>`chain:${i}:${t}`,ChainInfos:i=>`chains:${i}`},D=class{constructor(t){this.strategy=this.selectStrategy(t)}selectStrategy(t){return t==="localStorage"?new q:t==="memory"?new L:typeof window<"u"&&window.localStorage?new q:new L}set(t,r,e){this.strategy.set(t,r,e)}get(t){return this.strategy.get(t)}forget(t){this.strategy.forget(t)}clear(){this.strategy.clear()}};var B=class{static async getChainInfoForAction(t,r,e){if(e){let n=await this.tryGetChainFromInputs(t,r,e);if(n)return n}return this.getDefaultChainInfo(t,r)}static async tryGetChainFromInputs(t,r,e){let n=r.inputs?.findIndex(u=>u.position==="chain");if(n===-1||n===void 0)return null;let a=e[n];if(!a)throw new Error("WarpUtils: Chain input not found");let o=new A().stringToNative(a)[1],p=await new t.repository.registry(t).getChainInfo(o);if(!p)throw new Error(`WarpUtils: Chain info not found for ${o}`);return p}static async getDefaultChainInfo(t,r){if(!r.chain)return N(t);let n=await new t.repository.registry(t).getChainInfo(r.chain,{ttl:F.OneWeek});if(!n)throw new Error(`WarpUtils: Chain info not found for ${r.chain}`);return n}};var H=class{constructor(t){if(!t.currentUrl)throw new Error("WarpFactory: currentUrl config not set");this.config=t,this.url=new URL(t.currentUrl),this.serializer=new A,this.cache=new D(t.cache?.type)}async createExecutable(t,r,e){let n=E(t,r);if(!n)throw new Error("WarpFactory: Action not found");let a=await B.getChainInfoForAction(this.config,n,e),s=await this.getResolvedInputs(a,n,e),o=this.getModifiedInputs(s),l=o.find(C=>C.input.position==="receiver")?.value,p="address"in n?n.address:null,u=l?.split(":")[1]||p;if(!u)throw new Error("WarpActionExecutor: Destination/Receiver not provided");let W=u,d=this.getPreparedArgs(n,o),I=o.find(C=>C.input.position==="value")?.value||null,f="value"in n?n.value:null,g=BigInt(I?.split(":")[1]||f||0),x=o.filter(C=>C.input.position==="transfer"&&C.value).map(C=>C.value),y=[...("transfers"in n?n.transfers:[])||[],...x||[]],T=o.find(C=>C.input.position==="data")?.value,U="data"in n?n.data||"":null,J={warp:t,chain:a,action:r,destination:W,args:d,value:g,transfers:y,data:T||U||null,resolvedInputs:o};return this.cache.set(rt.WarpExecutable(this.config.env,t.meta?.hash||"",r),J.resolvedInputs,F.OneWeek),J}determineAction(t,r){let e=t.actions.filter(s=>s.type!=="link"),n=this.config.preferredChain?.toLowerCase(),a=1;if(n){let s=e.findIndex(o=>o.chain?.toLowerCase()===n);s!==-1&&(a=s)}return[E(t,a),a]}async getResolvedInputs(t,r,e){let n=r.inputs||[],a=await Promise.all(e.map(o=>this.preprocessInput(t,o))),s=(o,l)=>{if(o.source==="query"){let p=this.url.searchParams.get(o.name);return p?this.serializer.nativeToString(o.type,p):null}else return o.source===c.Source.UserWallet?this.config.user?.wallet?this.serializer.nativeToString("address",this.config.user.wallet):null:a[l]||null};return n.map((o,l)=>{let p=s(o,l);return{input:o,value:p||(o.default!==void 0?this.serializer.nativeToString(o.type,o.default):null)}})}getModifiedInputs(t){return t.map((r,e)=>{if(r.input.modifier?.startsWith("scale:")){let[,n]=r.input.modifier.split(":");if(isNaN(Number(n))){let a=Number(t.find(l=>l.input.name===n)?.value?.split(":")[1]);if(!a)throw new Error(`WarpActionExecutor: Exponent value not found for input ${n}`);let s=r.value?.split(":")[1];if(!s)throw new Error("WarpActionExecutor: Scalable value not found");let o=M(s,+a);return{...r,value:`${r.input.type}:${o}`}}else{let a=r.value?.split(":")[1];if(!a)throw new Error("WarpActionExecutor: Scalable value not found");let s=M(a,+n);return{...r,value:`${r.input.type}:${s}`}}}else return r})}async preprocessInput(t,r){try{let[e,n]=r.split(c.ArgParamsSeparator,2),a=this.config.adapters.find(o=>o.chain===t.name)?.executor,s=a?new a(this.config):null;return s?s.preprocessInput(t,r,e,n):r}catch{return r}}getPreparedArgs(t,r){let e="args"in t?t.args||[]:[];return r.forEach(({input:n,value:a})=>{if(!a||!n.position?.startsWith("arg:"))return;let s=Number(n.position.split(":")[1])-1;e.splice(s,0,a)}),e}};var $=class{constructor(t){this.config=t;this.registry=new this.config.repository.registry(this.config)}async apply(t,r){let e=this.applyVars(t,r);return await this.applyGlobals(t,e)}async applyGlobals(t,r){let e={...r};return e.actions=await Promise.all(e.actions.map(async n=>await this.applyActionGlobals(n))),e=await this.applyRootGlobals(e,t),e}applyVars(t,r){if(!r?.vars)return r;let e=JSON.stringify(r),n=(a,s)=>{e=e.replace(new RegExp(`{{${a.toUpperCase()}}}`,"g"),s.toString())};return Object.entries(r.vars).forEach(([a,s])=>{if(typeof s!="string")n(a,s);else if(s.startsWith(`${c.Vars.Query}:`)){if(!t.currentUrl)throw new Error("WarpUtils: currentUrl config is required to prepare vars");let o=s.split(`${c.Vars.Query}:`)[1],l=new URLSearchParams(t.currentUrl.split("?")[1]).get(o);l&&n(a,l)}else if(s.startsWith(`${c.Vars.Env}:`)){let o=s.split(`${c.Vars.Env}:`)[1],l=t.vars?.[o];l&&n(a,l)}else s===c.Source.UserWallet&&t.user?.wallet?n(a,t.user.wallet):n(a,s)}),JSON.parse(e)}async applyRootGlobals(t,r){let e=JSON.stringify(t),n={config:r,chain:N(r)};return Object.values(c.Globals).forEach(a=>{let s=a.Accessor(n);s!=null&&(e=e.replace(new RegExp(`{{${a.Placeholder}}}`,"g"),s.toString()))}),JSON.parse(e)}async applyActionGlobals(t){let r=t.chain?await this.registry.getChainInfo(t.chain):N(this.config);if(!r)throw new Error(`Chain info not found for ${t.chain}`);let e=JSON.stringify(t),n={config:this.config,chain:r};return Object.values(c.Globals).forEach(a=>{let s=a.Accessor(n);s!=null&&(e=e.replace(new RegExp(`{{${a.Placeholder}}}`,"g"),s.toString()))}),JSON.parse(e)}};var et=class{constructor(t,r){this.config=t,this.factory=new H(t),this.handlers=r}async execute(t,r){let[e,n]=this.factory.determineAction(t,r),a=await this.factory.createExecutable(t,n,r);if(e.type==="collect"){let u=await this.executeCollect(t,n,r);return this.handlers?.onExecuted?.(u),[null,null]}let s=a.chain.name.toLowerCase(),o=this.config.adapters.find(u=>u.chain.toLowerCase()===s);if(!o)throw new Error(`No adapter registered for chain: ${s}`);return[await new o.executor(this.config).createTransaction(a),a.chain]}async evaluateResults(t,r,e){let n=this.config.adapters.find(o=>o.chain.toLowerCase()===r.name.toLowerCase());if(!n)throw new Error(`No adapter registered for chain: ${r.name}`);let s=await new n.results(this.config).getTransactionExecutionResults(t,1,e);this.handlers?.onExecuted?.(s)}async executeCollect(t,r,e,n){let a=E(t,r);if(!a)throw new Error("WarpActionExecutor: Action not found");let s=await B.getChainInfoForAction(this.config,a),l=await new $(this.config).apply(this.config,t),p=await this.factory.getResolvedInputs(s,a,e),u=this.factory.getModifiedInputs(p),W=this.factory.serializer,d=m=>{if(!m.value)return null;let y=W.stringToNative(m.value)[1];return m.input.type==="biguint"?y.toString():m.input.type==="esdt"?{}:y},I=new Headers;I.set("Content-Type","application/json"),I.set("Accept","application/json"),Object.entries(a.destination.headers||{}).forEach(([m,y])=>{I.set(m,y)});let f=Object.fromEntries(u.map(m=>[m.input.as||m.input.name,d(m)])),g=a.destination.method||"GET",x=g==="GET"?void 0:JSON.stringify({...f,...n});v.info("Executing collect",{url:a.destination.url,method:g,headers:I,body:x});try{let m=await fetch(a.destination.url,{method:g,headers:I,body:x}),y=await m.json(),{values:T,results:U}=await Y(l,y,r,u),K=X(this.config,l,r,U);return{success:m.ok,warp:l,action:r,user:this.config.user?.wallet||null,txHash:null,next:K,values:T,results:{...U,_DATA:y},messages:_(l,U)}}catch(m){return v.error("WarpActionExecutor: Error executing collect",m),{success:!1,warp:l,action:r,user:this.config.user?.wallet||null,txHash:null,next:null,values:[],results:{_DATA:m},messages:{}}}}};var nt=class{constructor(t){this.config=t}async search(t,r,e){if(!this.config.index?.url)throw new Error("WarpIndex: Index URL is not set");try{let n=await fetch(this.config.index?.url,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.index?.apiKey}`,...e},body:JSON.stringify({[this.config.index?.searchParamName||"search"]:t,...r})});if(!n.ok)throw new Error(`WarpIndex: search failed with status ${n.status}`);return(await n.json()).hits}catch(n){throw v.error("WarpIndex: Error searching for warps: ",n),n}}};var it=class{constructor(t){this.config=t;this.registry=new this.config.repository.registry(this.config),this.builder=new this.config.repository.builder(this.config)}isValid(t){return t.startsWith(c.HttpProtocolPrefix)?!!V(t):!1}async detectFromHtml(t){if(!t.length)return{match:!1,results:[]};let n=[...t.matchAll(/https?:\/\/[^\s"'<>]+/gi)].map(p=>p[0]).filter(p=>this.isValid(p)).map(p=>this.detect(p)),s=(await Promise.all(n)).filter(p=>p.match),o=s.length>0,l=s.map(p=>({url:p.url,warp:p.warp}));return{match:o,results:l}}async detect(t,r){let e={match:!1,url:t,warp:null,registryInfo:null,brand:null},n=t.startsWith(c.HttpProtocolPrefix)?V(t):S(t);if(!n)return e;try{let{type:a,identifierBase:s}=n,o=null,l=null,p=null;if(a==="hash"){o=await this.builder.createFromTransactionHash(s,r);let d=await this.registry.getInfoByHash(s,r);l=d.registryInfo,p=d.brand}else if(a==="alias"){let d=await this.registry.getInfoByAlias(s,r);l=d.registryInfo,p=d.brand,d.registryInfo&&(o=await this.builder.createFromTransactionHash(d.registryInfo.hash,r))}let u=new $(this.config),W=o?await u.apply(this.config,o):null;return W?{match:!0,url:t,warp:W,registryInfo:l,brand:p}:e}catch(a){return v.error("Error detecting warp link",a),e}}};export{F as CacheTtl,dt as KnownTokens,Z as WarpBrandBuilder,tt as WarpBuilder,D as WarpCache,rt as WarpCacheKey,h as WarpConfig,c as WarpConstants,et as WarpExecutor,H as WarpFactory,nt as WarpIndex,w as WarpInputTypes,$ as WarpInterpolator,k as WarpLinkBuilder,it as WarpLinkDetecter,v as WarpLogger,R as WarpProtocolVersions,A as WarpSerializer,B as WarpUtils,j as WarpValidator,ur as address,_ as applyResultsToMessages,lr as biguint,cr as boolean,pt as evaluateResultsCommon,Y as extractCollectResults,V as extractIdentifierInfoFromUrl,Kt as findKnownTokenById,vt as getChainExplorerUrl,O as getLatestProtocolIdentifier,N as getMainChainInfo,X as getNextInfo,E as getWarpActionByIndex,S as getWarpInfoFromIdentifier,dr as hex,ut as parseResultsOutIndex,G as replacePlaceholders,M as shiftBigintBy,ir as string,Q as toPreviewText,It as toTypedChainInfo,sr as u16,or as u32,pr as u64,ar as u8};
1
+ import"./chunk-3SAEGOMQ.mjs";var c={HttpProtocolPrefix:"http",IdentifierParamName:"warp",IdentifierParamSeparator:":",IdentifierType:{Alias:"alias",Hash:"hash"},Source:{UserWallet:"user:wallet"},Globals:{UserWallet:{Placeholder:"USER_WALLET",Accessor:i=>i.config.user?.wallet},ChainApiUrl:{Placeholder:"CHAIN_API",Accessor:i=>i.chain.apiUrl},ChainExplorerUrl:{Placeholder:"CHAIN_EXPLORER",Accessor:i=>i.chain.explorerUrl}},Vars:{Query:"query",Env:"env"},ArgParamsSeparator:":",ArgCompositeSeparator:"|",Transform:{Prefix:"transform:"}},w={Option:"option",Optional:"optional",List:"list",Variadic:"variadic",Composite:"composite",String:"string",U8:"u8",U16:"u16",U32:"u32",U64:"u64",Biguint:"biguint",Boolean:"boolean",Address:"address",Hex:"hex"};var R={Warp:"3.0.0",Brand:"0.1.0",Abi:"0.1.0"},m={LatestWarpSchemaUrl:`https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/v${R.Warp}.schema.json`,LatestBrandSchemaUrl:`https://raw.githubusercontent.com/vLeapGroup/warps-specs/refs/heads/main/schemas/brand/v${R.Brand}.schema.json`,DefaultClientUrl:i=>i==="devnet"?"https://devnet.usewarp.to":i==="testnet"?"https://testnet.usewarp.to":"https://usewarp.to",SuperClientUrls:["https://usewarp.to","https://testnet.usewarp.to","https://devnet.usewarp.to"],MainChain:{Name:"multiversx",DisplayName:"MultiversX",ApiUrl:i=>i==="devnet"?"https://devnet-api.multiversx.com":i==="testnet"?"https://testnet-api.multiversx.com":"https://api.multiversx.com",ExplorerUrl:i=>i==="devnet"?"https://devnet-explorer.multiversx.com":i==="testnet"?"https://testnet-explorer.multiversx.com":"https://explorer.multiversx.com",BlockTime:i=>6e3,AddressHrp:"erd",ChainId:i=>i==="devnet"?"D":i==="testnet"?"T":"1",NativeToken:"EGLD"},Registry:{Contract:i=>i==="devnet"?"erd1qqqqqqqqqqqqqpgqje2f99vr6r7sk54thg03c9suzcvwr4nfl3tsfkdl36":i==="testnet"?"####":"erd1qqqqqqqqqqqqqpgq3mrpj3u6q7tejv6d7eqhnyd27n9v5c5tl3ts08mffe"},AvailableActionInputSources:["field","query",c.Source.UserWallet],AvailableActionInputTypes:["string","uint8","uint16","uint32","uint64","biguint","boolean","address"],AvailableActionInputPositions:["receiver","value","transfer","arg:1","arg:2","arg:3","arg:4","arg:5","arg:6","arg:7","arg:8","arg:9","arg:10","data","ignore"]};var N=i=>({name:m.MainChain.Name,displayName:m.MainChain.DisplayName,chainId:m.MainChain.ChainId(i.env),blockTime:m.MainChain.BlockTime(i.env),addressHrp:m.MainChain.AddressHrp,apiUrl:m.MainChain.ApiUrl(i.env),explorerUrl:m.MainChain.ExplorerUrl(i.env),nativeToken:m.MainChain.NativeToken}),vt=(i,t)=>i.explorerUrl+(t?"/"+t:""),O=i=>{if(i==="warp")return`warp:${R.Warp}`;if(i==="brand")return`brand:${R.Brand}`;if(i==="abi")return`abi:${R.Abi}`;throw new Error(`getLatestProtocolIdentifier: Invalid protocol name: ${i}`)},E=(i,t)=>i?.actions[t-1],It=i=>({name:i.name.toString(),displayName:i.display_name.toString(),chainId:i.chain_id.toString(),blockTime:i.block_time.toNumber(),addressHrp:i.address_hrp.toString(),apiUrl:i.api_url.toString(),explorerUrl:i.explorer_url.toString(),nativeToken:i.native_token.toString()}),M=(i,t)=>{let r=i.toString(),[e,n=""]=r.split("."),a=Math.abs(t);if(t>0)return BigInt(e+n.padEnd(a,"0"));if(t<0){let s=e+n;if(a>=s.length)return 0n;let o=s.slice(0,-a)||"0";return BigInt(o)}else return r.includes(".")?BigInt(r.split(".")[0]):BigInt(r)},Q=(i,t=100)=>{if(!i)return"";let r=i.replace(/<\/?(h[1-6])[^>]*>/gi," - ").replace(/<\/?(p|div|ul|ol|li|br|hr)[^>]*>/gi," ").replace(/<[^>]+>/g,"").replace(/\s+/g," ").trim();return r=r.startsWith("- ")?r.slice(2):r,r=r.length>t?r.substring(0,r.lastIndexOf(" ",t))+"...":r,r},G=(i,t)=>i.replace(/\{\{([^}]+)\}\}/g,(r,e)=>t[e]||""),_=(i,t)=>{let r=Object.entries(i.messages||{}).map(([e,n])=>[e,G(n,t)]);return Object.fromEntries(r)};var S=i=>{let t=decodeURIComponent(i);if(t.includes(c.IdentifierParamSeparator)){let[e,n]=t.split(c.IdentifierParamSeparator),a=n.split("?")[0];return{type:e,identifier:n,identifierBase:a}}let r=t.split("?")[0];return r.length===64?{type:c.IdentifierType.Hash,identifier:t,identifierBase:r}:{type:c.IdentifierType.Alias,identifier:t,identifierBase:r}},V=i=>{let t=new URL(i),r=m.SuperClientUrls.includes(t.origin),e=t.searchParams.get(c.IdentifierParamName),n=r&&!e?t.pathname.split("/")[1]:e;if(!n)return null;let a=decodeURIComponent(n);return S(a)};import at from"qr-code-styling";var k=class{constructor(t){this.config=t;this.config=t}isValid(t){return t.startsWith(c.HttpProtocolPrefix)?!!V(t):!1}build(t,r){let e=this.config.clientUrl||m.DefaultClientUrl(this.config.env),n=t===c.IdentifierType.Alias?encodeURIComponent(r):encodeURIComponent(t+c.IdentifierParamSeparator+r);return m.SuperClientUrls.includes(e)?`${e}/${n}`:`${e}?${c.IdentifierParamName}=${n}`}buildFromPrefixedIdentifier(t){let r=S(t);return r?this.build(r.type,r.identifierBase):""}generateQrCode(t,r,e=512,n="white",a="black",s="#23F7DD"){let o=this.build(t,r);return new at({type:"svg",width:e,height:e,data:String(o),margin:16,qrOptions:{typeNumber:0,mode:"Byte",errorCorrectionLevel:"Q"},backgroundOptions:{color:n},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(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>`})}};var st="https://",X=(i,t,r,e)=>{let n=t.actions?.[r]?.next||t.next||null;if(!n)return null;if(n.startsWith(st))return[{identifier:null,url:n}];let[a,s]=n.split("?");if(!s)return[{identifier:a,url:z(a,i)}];let o=s.match(/{{([^}]+)\[\](\.[^}]+)?}}/g)||[];if(o.length===0){let f=G(s,{...t.vars,...e}),g=f?`${a}?${f}`:a;return[{identifier:g,url:z(g,i)}]}let l=o[0];if(!l)return[];let p=l.match(/{{([^[]+)\[\]/),u=p?p[1]:null;if(!u||e[u]===void 0)return[];let W=Array.isArray(e[u])?e[u]:[e[u]];if(W.length===0)return[];let d=o.filter(f=>f.includes(`{{${u}[]`)).map(f=>{let g=f.match(/\[\](\.[^}]+)?}}/),x=g&&g[1]||"";return{placeholder:f,field:x?x.slice(1):"",regex:new RegExp(f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g")}});return W.map(f=>{let g=s;for(let{regex:h,field:y}of d){let T=y?ot(f,y):f;if(T==null)return null;g=g.replace(h,T)}if(g.includes("{{")||g.includes("}}"))return null;let x=g?`${a}?${g}`:a;return{identifier:x,url:z(x,i)}}).filter(f=>f!==null)},z=(i,t)=>{let[r,e]=i.split("?"),n=S(r)||{type:"alias",identifier:r,identifierBase:r},s=new k(t).build(n.type,n.identifierBase);if(!e)return s;let o=new URL(s);return new URLSearchParams(e).forEach((l,p)=>o.searchParams.set(p,l)),o.toString().replace(/\/\?/,"?")},ot=(i,t)=>t.split(".").reduce((r,e)=>r?.[e],i);var P=class P{static info(...t){P.isTestEnv||console.info(...t)}static warn(...t){P.isTestEnv||console.warn(...t)}static error(...t){P.isTestEnv||console.error(...t)}};P.isTestEnv=typeof process<"u"&&process.env.JEST_WORKER_ID!==void 0;var v=P;var A=class{nativeToString(t,r){return`${t}:${r?.toString()??""}`}stringToNative(t){let r=t.split(c.ArgParamsSeparator),e=r[0],n=r.slice(1).join(c.ArgParamsSeparator);if(e==="null")return[e,null];if(e==="option"){let[a,s]=n.split(c.ArgParamsSeparator);return[`option:${a}`,s||null]}else if(e==="optional"){let[a,s]=n.split(c.ArgParamsSeparator);return[`optional:${a}`,s||null]}else if(e==="list"){let a=n.split(c.ArgParamsSeparator),s=a.slice(0,-1).join(c.ArgParamsSeparator),o=a[a.length-1],p=(o?o.split(","):[]).map(u=>this.stringToNative(`${s}:${u}`)[1]);return[`list:${s}`,p]}else if(e==="variadic"){let a=n.split(c.ArgParamsSeparator),s=a.slice(0,-1).join(c.ArgParamsSeparator),o=a[a.length-1],p=(o?o.split(","):[]).map(u=>this.stringToNative(`${s}:${u}`)[1]);return[`variadic:${s}`,p]}else if(e.startsWith("composite")){let a=e.match(/\(([^)]+)\)/)?.[1]?.split(c.ArgCompositeSeparator),o=n.split(c.ArgCompositeSeparator).map((l,p)=>this.stringToNative(`${a[p]}:${l}`)[1]);return[e,o]}else{if(e==="string")return[e,n];if(e==="uint8"||e==="uint16"||e==="uint32")return[e,Number(n)];if(e==="uint64"||e==="biguint")return[e,BigInt(n||0)];if(e==="bool")return[e,n==="true"];if(e==="address")return[e,n];if(e==="token")return[e,n];if(e==="hex")return[e,n];if(e==="codemeta")return[e,n];if(e==="esdt"){let[a,s,o]=n.split(c.ArgCompositeSeparator);return[e,`${a}|${s}|${o}`]}}throw new Error(`WarpArgSerializer (stringToNative): Unsupported input type: ${e}`)}};var Y=async(i,t,r,e)=>{let n=[],a={};for(let[s,o]of Object.entries(i.results||{})){if(o.startsWith(c.Transform.Prefix))continue;let l=ut(o);if(l!==null&&l!==r){a[s]=null;continue}let[p,...u]=o.split("."),W=(d,I)=>I.reduce((f,g)=>f&&f[g]!==void 0?f[g]:null,d);if(p==="out"||p.startsWith("out[")){let d=u.length===0?t?.data||t:W(t,u);n.push(d),a[s]=d}else a[s]=o}return{values:n,results:await pt(i,a,r,e)}},pt=async(i,t,r,e)=>{if(!i.results)return t;let n={...t};return n=lt(n,i,r,e),n=await ct(i,n),n},lt=(i,t,r,e)=>{let n={...i},a=E(t,r)?.inputs||[],s=new A;for(let[o,l]of Object.entries(n))if(typeof l=="string"&&l.startsWith("input.")){let p=l.split(".")[1],u=a.findIndex(d=>d.as===p||d.name===p),W=u!==-1?e[u]?.value:null;n[o]=W?s.stringToNative(W)[1]:null}return n},ct=async(i,t)=>{if(!i.results)return t;let r={...t},e=Object.entries(i.results).filter(([,n])=>n.startsWith(c.Transform.Prefix)).map(([n,a])=>({key:n,code:a.substring(c.Transform.Prefix.length)}));for(let{key:n,code:a}of e)try{let s;typeof window>"u"?s=(await import("./runInVm-BFUZVHHD.mjs")).runInVm:s=(await import("./runInVm-5YQ766M3.mjs")).runInVm,r[n]=await s(a,r)}catch(s){v.error(`Transform error for result '${n}':`,s),r[n]=null}return r},ut=i=>{if(i==="out")return 1;let t=i.match(/^out\[(\d+)\]/);return t?parseInt(t[1],10):(i.startsWith("out.")||i.startsWith("event."),null)};var dt=[{id:"EGLD",name:"eGold",decimals:18},{id:"EGLD-000000",name:"eGold",decimals:18},{id:"VIBE-000000",name:"VIBE",decimals:18}],Kt=i=>dt.find(t=>t.id===i)||null;var ar=i=>`${w.String}:${i}`,sr=i=>`${w.U8}:${i}`,or=i=>`${w.U16}:${i}`,pr=i=>`${w.U32}:${i}`,lr=i=>`${w.U64}:${i}`,cr=i=>`${w.Biguint}:${i}`,ur=i=>`${w.Boolean}:${i}`,dr=i=>`${w.Address}:${i}`,fr=i=>`${w.Hex}:${i}`;import ft from"ajv";var Z=class{constructor(t){this.pendingBrand={protocol:O("brand"),name:"",description:"",logo:""};this.config=t}async createFromRaw(t,r=!0){let e=JSON.parse(t);return r&&await this.ensureValidSchema(e),e}setName(t){return this.pendingBrand.name=t,this}setDescription(t){return this.pendingBrand.description=t,this}setLogo(t){return this.pendingBrand.logo=t,this}setUrls(t){return this.pendingBrand.urls=t,this}setColors(t){return this.pendingBrand.colors=t,this}setCta(t){return this.pendingBrand.cta=t,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(t,r){if(!t)throw new Error(`Warp: ${r}`)}async ensureValidSchema(t){let r=this.config.schema?.brand||m.LatestBrandSchemaUrl,n=await(await fetch(r)).json(),a=new ft,s=a.compile(n);if(!s(t))throw new Error(`BrandBuilder: schema validation failed: ${a.errorsText(s.errors)}`)}};import gt from"ajv";var j=class{constructor(t){this.config=t;this.config=t}async validate(t){let r=[];return r.push(...this.validateMaxOneValuePosition(t)),r.push(...this.validateVariableNamesAndResultNamesUppercase(t)),r.push(...this.validateAbiIsSetIfApplicable(t)),r.push(...await this.validateSchema(t)),{valid:r.length===0,errors:r}}validateMaxOneValuePosition(t){return t.actions.filter(e=>e.inputs?e.inputs.some(n=>n.position==="value"):!1).length>1?["Only one value position action is allowed"]:[]}validateVariableNamesAndResultNamesUppercase(t){let r=[],e=(n,a)=>{n&&Object.keys(n).forEach(s=>{s!==s.toUpperCase()&&r.push(`${a} name '${s}' must be uppercase`)})};return e(t.vars,"Variable"),e(t.results,"Result"),r}validateAbiIsSetIfApplicable(t){let r=t.actions.some(s=>s.type==="contract"),e=t.actions.some(s=>s.type==="query");if(!r&&!e)return[];let n=t.actions.some(s=>s.abi),a=Object.values(t.results||{}).some(s=>s.startsWith("out.")||s.startsWith("event."));return t.results&&!n&&a?["ABI is required when results are present for contract or query actions"]:[]}async validateSchema(t){try{let r=this.config.schema?.warp||m.LatestWarpSchemaUrl,n=await(await fetch(r)).json(),a=new gt({strict:!1}),s=a.compile(n);return s(t)?[]:[`Schema validation failed: ${a.errorsText(s.errors)}`]}catch(r){return[`Schema validation failed: ${r instanceof Error?r.message:String(r)}`]}}};var tt=class{constructor(t){this.pendingWarp={protocol:O("warp"),name:"",title:"",description:null,preview:"",actions:[]};this.config=t,this.adapterBuilder=new t.repository.builder(t)}createInscriptionTransaction(t){return this.adapterBuilder.createInscriptionTransaction(t)}async createFromTransaction(t,r=!1){return this.adapterBuilder.createFromTransaction(t,r)}async createFromTransactionHash(t,r){return this.adapterBuilder.createFromTransactionHash(t,r)}async createFromRaw(t,r=!0){let e=JSON.parse(t);return r&&await this.validate(e),e}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.validate(this.pendingWarp),this.pendingWarp}getDescriptionPreview(t,r=100){return Q(t,r)}ensure(t,r){if(!t)throw new Error(r)}async validate(t){let e=await new j(this.config).validate(t);if(!e.valid)throw new Error(e.errors.join(`
2
+ `))}};var q=class{constructor(t="warp-cache"){this.prefix=t}getKey(t){return`${this.prefix}:${t}`}get(t){try{let r=localStorage.getItem(this.getKey(t));if(!r)return null;let e=JSON.parse(r);return Date.now()>e.expiresAt?(localStorage.removeItem(this.getKey(t)),null):e.value}catch{return null}}set(t,r,e){let n={value:r,expiresAt:Date.now()+e*1e3};localStorage.setItem(this.getKey(t),JSON.stringify(n))}forget(t){localStorage.removeItem(this.getKey(t))}clear(){for(let t=0;t<localStorage.length;t++){let r=localStorage.key(t);r?.startsWith(this.prefix)&&localStorage.removeItem(r)}}};var b=class b{get(t){let r=b.cache.get(t);return r?Date.now()>r.expiresAt?(b.cache.delete(t),null):r.value:null}set(t,r,e){let n=Date.now()+e*1e3;b.cache.set(t,{value:r,expiresAt:n})}forget(t){b.cache.delete(t)}clear(){b.cache.clear()}};b.cache=new Map;var L=b;var F={OneMinute:60,OneHour:60*60,OneDay:60*60*24,OneWeek:60*60*24*7,OneMonth:60*60*24*30,OneYear:60*60*24*365},rt={Warp:(i,t)=>`warp:${i}:${t}`,WarpAbi:(i,t)=>`warp-abi:${i}:${t}`,WarpExecutable:(i,t,r)=>`warp-exec:${i}:${t}:${r}`,RegistryInfo:(i,t)=>`registry-info:${i}:${t}`,Brand:(i,t)=>`brand:${i}:${t}`,ChainInfo:(i,t)=>`chain:${i}:${t}`,ChainInfos:i=>`chains:${i}`},D=class{constructor(t){this.strategy=this.selectStrategy(t)}selectStrategy(t){return t==="localStorage"?new q:t==="memory"?new L:typeof window<"u"&&window.localStorage?new q:new L}set(t,r,e){this.strategy.set(t,r,e)}get(t){return this.strategy.get(t)}forget(t){this.strategy.forget(t)}clear(){this.strategy.clear()}};var B=class{static async getChainInfoForAction(t,r,e){if(e){let n=await this.tryGetChainFromInputs(t,r,e);if(n)return n}return this.getDefaultChainInfo(t,r)}static async tryGetChainFromInputs(t,r,e){let n=r.inputs?.findIndex(u=>u.position==="chain");if(n===-1||n===void 0)return null;let a=e[n];if(!a)throw new Error("WarpUtils: Chain input not found");let o=new A().stringToNative(a)[1],p=await new t.repository.registry(t).getChainInfo(o);if(!p)throw new Error(`WarpUtils: Chain info not found for ${o}`);return p}static async getDefaultChainInfo(t,r){if(!r.chain)return N(t);let n=await new t.repository.registry(t).getChainInfo(r.chain,{ttl:F.OneWeek});if(!n)throw new Error(`WarpUtils: Chain info not found for ${r.chain}`);return n}};var H=class{constructor(t){if(!t.currentUrl)throw new Error("WarpFactory: currentUrl config not set");this.config=t,this.url=new URL(t.currentUrl),this.serializer=new A,this.cache=new D(t.cache?.type)}async createExecutable(t,r,e){let n=E(t,r);if(!n)throw new Error("WarpFactory: Action not found");let a=await B.getChainInfoForAction(this.config,n,e),s=await this.getResolvedInputs(a,n,e),o=this.getModifiedInputs(s),l=o.find(C=>C.input.position==="receiver")?.value,p="address"in n?n.address:null,u=l?.split(":")[1]||p;if(!u)throw new Error("WarpActionExecutor: Destination/Receiver not provided");let W=u,d=this.getPreparedArgs(n,o),I=o.find(C=>C.input.position==="value")?.value||null,f="value"in n?n.value:null,g=BigInt(I?.split(":")[1]||f||0),x=o.filter(C=>C.input.position==="transfer"&&C.value).map(C=>C.value),y=[...("transfers"in n?n.transfers:[])||[],...x||[]],T=o.find(C=>C.input.position==="data")?.value,U="data"in n?n.data||"":null,J={warp:t,chain:a,action:r,destination:W,args:d,value:g,transfers:y,data:T||U||null,resolvedInputs:o};return this.cache.set(rt.WarpExecutable(this.config.env,t.meta?.hash||"",r),J.resolvedInputs,F.OneWeek),J}determineAction(t,r){let e=t.actions.filter(s=>s.type!=="link"),n=this.config.preferredChain?.toLowerCase(),a=1;if(n){let s=e.findIndex(o=>o.chain?.toLowerCase()===n);s!==-1&&(a=s)}return[E(t,a),a]}async getResolvedInputs(t,r,e){let n=r.inputs||[],a=await Promise.all(e.map(o=>this.preprocessInput(t,o))),s=(o,l)=>{if(o.source==="query"){let p=this.url.searchParams.get(o.name);return p?this.serializer.nativeToString(o.type,p):null}else return o.source===c.Source.UserWallet?this.config.user?.wallet?this.serializer.nativeToString("address",this.config.user.wallet):null:a[l]||null};return n.map((o,l)=>{let p=s(o,l);return{input:o,value:p||(o.default!==void 0?this.serializer.nativeToString(o.type,o.default):null)}})}getModifiedInputs(t){return t.map((r,e)=>{if(r.input.modifier?.startsWith("scale:")){let[,n]=r.input.modifier.split(":");if(isNaN(Number(n))){let a=Number(t.find(l=>l.input.name===n)?.value?.split(":")[1]);if(!a)throw new Error(`WarpActionExecutor: Exponent value not found for input ${n}`);let s=r.value?.split(":")[1];if(!s)throw new Error("WarpActionExecutor: Scalable value not found");let o=M(s,+a);return{...r,value:`${r.input.type}:${o}`}}else{let a=r.value?.split(":")[1];if(!a)throw new Error("WarpActionExecutor: Scalable value not found");let s=M(a,+n);return{...r,value:`${r.input.type}:${s}`}}}else return r})}async preprocessInput(t,r){try{let[e,n]=r.split(c.ArgParamsSeparator,2),a=this.config.adapters.find(o=>o.chain===t.name)?.executor,s=a?new a(this.config):null;return s?s.preprocessInput(t,r,e,n):r}catch{return r}}getPreparedArgs(t,r){let e="args"in t?t.args||[]:[];return r.forEach(({input:n,value:a})=>{if(!a||!n.position?.startsWith("arg:"))return;let s=Number(n.position.split(":")[1])-1;e.splice(s,0,a)}),e}};var $=class{constructor(t){this.config=t;this.registry=new this.config.repository.registry(this.config)}async apply(t,r){let e=this.applyVars(t,r);return await this.applyGlobals(t,e)}async applyGlobals(t,r){let e={...r};return e.actions=await Promise.all(e.actions.map(async n=>await this.applyActionGlobals(n))),e=await this.applyRootGlobals(e,t),e}applyVars(t,r){if(!r?.vars)return r;let e=JSON.stringify(r),n=(a,s)=>{e=e.replace(new RegExp(`{{${a.toUpperCase()}}}`,"g"),s.toString())};return Object.entries(r.vars).forEach(([a,s])=>{if(typeof s!="string")n(a,s);else if(s.startsWith(`${c.Vars.Query}:`)){if(!t.currentUrl)throw new Error("WarpUtils: currentUrl config is required to prepare vars");let o=s.split(`${c.Vars.Query}:`)[1],l=new URLSearchParams(t.currentUrl.split("?")[1]).get(o);l&&n(a,l)}else if(s.startsWith(`${c.Vars.Env}:`)){let o=s.split(`${c.Vars.Env}:`)[1],l=t.vars?.[o];l&&n(a,l)}else s===c.Source.UserWallet&&t.user?.wallet?n(a,t.user.wallet):n(a,s)}),JSON.parse(e)}async applyRootGlobals(t,r){let e=JSON.stringify(t),n={config:r,chain:N(r)};return Object.values(c.Globals).forEach(a=>{let s=a.Accessor(n);s!=null&&(e=e.replace(new RegExp(`{{${a.Placeholder}}}`,"g"),s.toString()))}),JSON.parse(e)}async applyActionGlobals(t){let r=t.chain?await this.registry.getChainInfo(t.chain):N(this.config);if(!r)throw new Error(`Chain info not found for ${t.chain}`);let e=JSON.stringify(t),n={config:this.config,chain:r};return Object.values(c.Globals).forEach(a=>{let s=a.Accessor(n);s!=null&&(e=e.replace(new RegExp(`{{${a.Placeholder}}}`,"g"),s.toString()))}),JSON.parse(e)}};var et=class{constructor(t,r){this.config=t,this.factory=new H(t),this.handlers=r}async execute(t,r){let[e,n]=this.factory.determineAction(t,r),a=await this.factory.createExecutable(t,n,r);if(e.type==="collect"){let u=await this.executeCollect(t,n,r);return this.handlers?.onExecuted?.(u),[null,null]}let s=a.chain.name.toLowerCase(),o=this.config.adapters.find(u=>u.chain.toLowerCase()===s);if(!o)throw new Error(`No adapter registered for chain: ${s}`);return[await new o.executor(this.config).createTransaction(a),a.chain]}async evaluateResults(t,r,e){let n=this.config.adapters.find(o=>o.chain.toLowerCase()===r.name.toLowerCase());if(!n)throw new Error(`No adapter registered for chain: ${r.name}`);let s=await new n.results(this.config).getTransactionExecutionResults(t,1,e);this.handlers?.onExecuted?.(s)}async executeCollect(t,r,e,n){let a=E(t,r);if(!a)throw new Error("WarpActionExecutor: Action not found");let s=await B.getChainInfoForAction(this.config,a),l=await new $(this.config).apply(this.config,t),p=await this.factory.getResolvedInputs(s,a,e),u=this.factory.getModifiedInputs(p),W=this.factory.serializer,d=h=>{if(!h.value)return null;let y=W.stringToNative(h.value)[1];return h.input.type==="biguint"?y.toString():h.input.type==="esdt"?{}:y},I=new Headers;I.set("Content-Type","application/json"),I.set("Accept","application/json"),Object.entries(a.destination.headers||{}).forEach(([h,y])=>{I.set(h,y)});let f=Object.fromEntries(u.map(h=>[h.input.as||h.input.name,d(h)])),g=a.destination.method||"GET",x=g==="GET"?void 0:JSON.stringify({...f,...n});v.info("Executing collect",{url:a.destination.url,method:g,headers:I,body:x});try{let h=await fetch(a.destination.url,{method:g,headers:I,body:x}),y=await h.json(),{values:T,results:U}=await Y(l,y,r,u),K=X(this.config,l,r,U);return{success:h.ok,warp:l,action:r,user:this.config.user?.wallet||null,txHash:null,next:K,values:T,results:{...U,_DATA:y},messages:_(l,U)}}catch(h){return v.error("WarpActionExecutor: Error executing collect",h),{success:!1,warp:l,action:r,user:this.config.user?.wallet||null,txHash:null,next:null,values:[],results:{_DATA:h},messages:{}}}}};var nt=class{constructor(t){this.config=t}async search(t,r,e){if(!this.config.index?.url)throw new Error("WarpIndex: Index URL is not set");try{let n=await fetch(this.config.index?.url,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.index?.apiKey}`,...e},body:JSON.stringify({[this.config.index?.searchParamName||"search"]:t,...r})});if(!n.ok)throw new Error(`WarpIndex: search failed with status ${n.status}`);return(await n.json()).hits}catch(n){throw v.error("WarpIndex: Error searching for warps: ",n),n}}};var it=class{constructor(t){this.config=t;this.registry=new this.config.repository.registry(this.config),this.builder=new this.config.repository.builder(this.config)}isValid(t){return t.startsWith(c.HttpProtocolPrefix)?!!V(t):!1}async detectFromHtml(t){if(!t.length)return{match:!1,results:[]};let n=[...t.matchAll(/https?:\/\/[^\s"'<>]+/gi)].map(p=>p[0]).filter(p=>this.isValid(p)).map(p=>this.detect(p)),s=(await Promise.all(n)).filter(p=>p.match),o=s.length>0,l=s.map(p=>({url:p.url,warp:p.warp}));return{match:o,results:l}}async detect(t,r){let e={match:!1,url:t,warp:null,registryInfo:null,brand:null},n=t.startsWith(c.HttpProtocolPrefix)?V(t):S(t);if(!n)return e;try{let{type:a,identifierBase:s}=n,o=null,l=null,p=null;if(a==="hash"){o=await this.builder.createFromTransactionHash(s,r);let d=await this.registry.getInfoByHash(s,r);l=d.registryInfo,p=d.brand}else if(a==="alias"){let d=await this.registry.getInfoByAlias(s,r);l=d.registryInfo,p=d.brand,d.registryInfo&&(o=await this.builder.createFromTransactionHash(d.registryInfo.hash,r))}let u=new $(this.config),W=o?await u.apply(this.config,o):null;return W?{match:!0,url:t,warp:W,registryInfo:l,brand:p}:e}catch(a){return v.error("Error detecting warp link",a),e}}};export{F as CacheTtl,dt as KnownTokens,Z as WarpBrandBuilder,tt as WarpBuilder,D as WarpCache,rt as WarpCacheKey,m as WarpConfig,c as WarpConstants,et as WarpExecutor,H as WarpFactory,nt as WarpIndex,w as WarpInputTypes,$ as WarpInterpolator,k as WarpLinkBuilder,it as WarpLinkDetecter,v as WarpLogger,R as WarpProtocolVersions,A as WarpSerializer,B as WarpUtils,j as WarpValidator,dr as address,_ as applyResultsToMessages,cr as biguint,ur as boolean,pt as evaluateResultsCommon,Y as extractCollectResults,V as extractIdentifierInfoFromUrl,Kt as findKnownTokenById,vt as getChainExplorerUrl,O as getLatestProtocolIdentifier,N as getMainChainInfo,X as getNextInfo,E as getWarpActionByIndex,S as getWarpInfoFromIdentifier,fr as hex,ut as parseResultsOutIndex,G as replacePlaceholders,M as shiftBigintBy,ar as string,Q as toPreviewText,It as toTypedChainInfo,or as u16,pr as u32,lr as u64,sr as u8};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vleap/warps",
3
- "version": "3.0.0-alpha.37",
3
+ "version": "3.0.0-alpha.39",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",