emblem-vault-sdk 2.9.0 → 2.9.2

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/src/types.ts CHANGED
@@ -27,6 +27,14 @@ export type Collection = {
27
27
  balanceCheckers: string[] | null;
28
28
  tokenIdScheme: string | null;
29
29
  generateVaultBody: Function;
30
+ /**
31
+ * Returns a template ready to send to the create vault API
32
+ *
33
+ * @param {FillCreateVaultTemplateArgs} args - Arguments to fill the template
34
+ * @param {_this: Collection} _this - The collection context
35
+ * @returns {Object} - Filled create vault template
36
+ */
37
+ fillCreateVaultTemplate: (args: FillCreateVaultTemplateArgs, _this: Collection) => Object;
30
38
  generateCreateTemplate: Function;
31
39
  };
32
40
 
@@ -142,3 +150,91 @@ export type Ownership = {
142
150
  }
143
151
 
144
152
  export type CuratedCollectionsResponse = Collection[];
153
+
154
+ // ============================================================================
155
+ // Remote Signer Types (for EmblemVaultClient integration)
156
+ // ============================================================================
157
+
158
+ export type ChainIdentifier = number | 'solana';
159
+
160
+ export type ProgressCallback = (message: string, data?: unknown) => void;
161
+
162
+ export interface MintResult {
163
+ txHash: string;
164
+ tokenId: string;
165
+ chainId: ChainIdentifier;
166
+ }
167
+
168
+ export interface ClaimResult {
169
+ phrase?: string;
170
+ privateKey?: string;
171
+ }
172
+
173
+ export interface RemoteMintSignature {
174
+ _nftAddress: string;
175
+ _price: { hex: string } | string | number;
176
+ _to: string;
177
+ _tokenId: { hex: string } | string | number;
178
+ _nonce: { hex: string } | string | number;
179
+ _signature: string;
180
+ serialNumber: string;
181
+ error?: string;
182
+ }
183
+
184
+ export interface RemoteUnvaultSignature {
185
+ success: boolean;
186
+ _nftAddress: string;
187
+ _tokenId: { hex: string } | string | number;
188
+ _nonce: { hex: string } | string | number;
189
+ _price: { hex: string } | string | number;
190
+ _timestamp: { hex: string } | string | number;
191
+ _signature: string;
192
+ msg?: string;
193
+ err?: string;
194
+ }
195
+
196
+ // ============================================================================
197
+ // EVM Signer Interface (matches emblem-vault-ai-signers EmblemEthersWallet)
198
+ // ============================================================================
199
+
200
+ export interface EvmSigner {
201
+ getAddress(): Promise<string>;
202
+ signMessage(message: string | Uint8Array): Promise<string>;
203
+ sendTransaction(tx: unknown): Promise<{ hash: string; wait(): Promise<unknown> }>;
204
+ setChainId?(chainId: number): void;
205
+ }
206
+
207
+ // ============================================================================
208
+ // EmblemVaultClient Interface - matches emblem-vault-ai-signers
209
+ // ============================================================================
210
+
211
+ export interface EmblemVaultClient {
212
+ toEthersWallet(provider?: unknown): Promise<EvmSigner>;
213
+ }
214
+
215
+ // ============================================================================
216
+ // SDK Context for operations modules
217
+ // ============================================================================
218
+
219
+ export interface SdkContext {
220
+ apiKey: string;
221
+ baseUrl: string;
222
+ v3Url: string;
223
+ sigUrl: string;
224
+ fetchMetadata: (tokenId: string, callback?: ProgressCallback) => Promise<MetaData>;
225
+ requestRemoteKey: (tokenId: string, jwt: unknown, callback?: ProgressCallback) => Promise<unknown>;
226
+ decryptVaultKeys: (tokenId: string, dkeys: unknown, callback?: ProgressCallback) => Promise<ClaimResult>;
227
+ }
228
+
229
+ export interface FillCreateVaultTemplateArgs {
230
+ fromAddress: string,
231
+ toAddress: string,
232
+ targetAsset: {
233
+ name: string,
234
+ image: string,
235
+ description?: string,
236
+ ownedImage?: string,
237
+ projectName?: string
238
+ },
239
+ chainId: number,
240
+ }
package/src/utils.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import CryptoJS from 'crypto-js'
2
- import { MetaData } from "./types";
2
+ import { MetaData, FillCreateVaultTemplateArgs } from "./types";
3
3
  import metadataJson from './curated/metadata.json';
4
4
  import darkfarmsMetadataJson from './curated/darkfarms-metadata.json';
5
5
  import dot_idMetadataJson from './curated/dot_id.json';
@@ -552,6 +552,40 @@ export function generateTemplate(record: any) {
552
552
 
553
553
  return nameAndImage
554
554
  },
555
+ fillCreateVaultTemplate: (args: FillCreateVaultTemplateArgs, _this: any) => {
556
+ const template = _this.generateCreateTemplate(_this)
557
+
558
+ if (args.fromAddress) {
559
+ template.fromAddress = args.fromAddress
560
+ } else {
561
+ throw new Error("fromAddress is required to create vault")
562
+ }
563
+
564
+ if (args.toAddress) {
565
+ template.toAddress = args.toAddress
566
+ } else {
567
+ throw new Error("toAddress is required to create vault")
568
+ }
569
+
570
+ if (args.chainId) {
571
+ const chainIdAsString = String(args.chainId)
572
+ template.targetContract = {
573
+ name: template.targetContract.name,
574
+ [chainIdAsString]: template.targetContract[chainIdAsString]
575
+ }
576
+ template.chainId = args.chainId
577
+ } else {
578
+ throw new Error("chainId is required to create vault")
579
+ }
580
+
581
+ if (args.targetAsset) {
582
+ Object.assign(template.targetAsset, args.targetAsset)
583
+ } else {
584
+ template.targetAsset = undefined
585
+ }
586
+
587
+ return template
588
+ },
555
589
  generateCreateTemplate: (_this: any) =>{
556
590
  let template = {
557
591
  fromAddress: { type: "user-provided" },
@@ -914,4 +948,9 @@ export async function signPSBT(psbtBase64: any, paymentAddress: any, indexes: nu
914
948
  });
915
949
  }
916
950
 
917
-
951
+ export function parseBigIntValue(value: unknown): bigint {
952
+ if (typeof value === 'object' && value !== null && 'hex' in value) {
953
+ return BigInt((value as { hex: string }).hex);
954
+ }
955
+ return BigInt(String(value));
956
+ }
@@ -0,0 +1,89 @@
1
+ import { ChainConfig, SUPPORTED_CHAINS } from "./constants";
2
+
3
+ export function isV2Vault(metadata: { targetContract?: { name?: string } }): boolean {
4
+ return Boolean(metadata.targetContract?.name);
5
+ }
6
+
7
+ export function requiresOnChainUnvault(metadata: { status?: string; sealed?: boolean; live?: boolean }): boolean {
8
+ return metadata.status === 'unclaimed' && !metadata.sealed && Boolean(metadata.live);
9
+ }
10
+
11
+ /**
12
+ * Get the claim identifier for signing claim messages.
13
+ * This MUST match VaultActions.vue's getSerialNumber() logic:
14
+ * - ERC1155: use targetContract.serialNumber
15
+ * - ERC721a: use tokenId
16
+ * - Legacy: use tokenId
17
+ */
18
+ export function getClaimIdentifier(metadata: {
19
+ ownershipInfo?: {
20
+ serialNumber?: string;
21
+ category?: string;
22
+ };
23
+ tokenId?: string;
24
+ targetContract?: {
25
+ serialNumber?: string;
26
+ collectionType?: string;
27
+ tokenId?: string;
28
+ };
29
+ }): string {
30
+ const { targetContract, ownershipInfo, tokenId } = metadata;
31
+
32
+ // If no targetContract, fallback to tokenId
33
+ if (!targetContract) {
34
+ return tokenId || '';
35
+ }
36
+
37
+ // ERC1155: use serialNumber
38
+ if (
39
+ targetContract.collectionType === 'ERC1155' ||
40
+ ownershipInfo?.category === 'erc1155'
41
+ ) {
42
+ return targetContract.serialNumber || tokenId || '';
43
+ }
44
+
45
+ // ERC721a: use tokenId (NOT serialNumber!)
46
+ if (
47
+ targetContract.collectionType === 'ERC721a' ||
48
+ ownershipInfo?.category === 'erc721a'
49
+ ) {
50
+ return tokenId || '';
51
+ }
52
+
53
+ // Default: use targetContract.tokenId or tokenId
54
+ return targetContract.tokenId || tokenId || '';
55
+ }
56
+
57
+ export function getHandlerContractAddress(chainId: number): string {
58
+ const config = getChainConfig(chainId);
59
+ if (!config.handlerContract) {
60
+ throw new Error(`No handler contract configured for chain ${chainId}`);
61
+ }
62
+ return config.handlerContract;
63
+ }
64
+
65
+ export function getUnvaultingContractAddress(chainId: number): string {
66
+ const config = getChainConfig(chainId);
67
+ if (!config.unvaultingContract) {
68
+ throw new Error(`No unvaulting contract configured for chain ${chainId}`);
69
+ }
70
+ return config.unvaultingContract;
71
+ }
72
+
73
+ export function getChainConfig(chainId: number | string): ChainConfig {
74
+ const config = SUPPORTED_CHAINS[chainId];
75
+ if (!config) {
76
+ const supportedList = Object.entries(SUPPORTED_CHAINS)
77
+ .map(([id, cfg]) => `${cfg.name} (${id})`)
78
+ .join(', ');
79
+ throw new Error(
80
+ `Unsupported chain: ${chainId}. Supported chains: ${supportedList}`
81
+ );
82
+ }
83
+ return config;
84
+ }
85
+
86
+ export function isEvmChain(chainId: number | string): boolean {
87
+ const config = SUPPORTED_CHAINS[chainId];
88
+ return config?.type === 'evm';
89
+ }
@@ -0,0 +1,17 @@
1
+ export declare const ETHEREUM_MAINNET_CHAIN_ID = 1;
2
+ export declare const POLYGON_MAINNET_CHAIN_ID = 137;
3
+ export declare const SOLANA_CHAIN_IDENTIFIER = "solana";
4
+ export type ChainType = 'evm' | 'solana';
5
+ export interface ChainConfig {
6
+ type: ChainType;
7
+ name: string;
8
+ handlerContract?: string;
9
+ unvaultingContract?: string;
10
+ }
11
+ export declare const SUPPORTED_CHAINS: Record<number | string, ChainConfig>;
12
+ export declare const HANDLER_CONTRACT_ADDRESS = "0x23859b51117dbFBcdEf5b757028B18d7759a4460";
13
+ export declare const UNVAULTING_DIAMOND_ADDRESS = "0x214C964bBd3640971E111d3a994CbB89b296a9ad";
14
+ export declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
15
+ export declare const EMBLEM_API_V2 = "https://v2.emblemvault.io";
16
+ export declare const EMBLEM_API_2 = "https://api2.emblemvault.io";
17
+ export declare const TORUS_SIGNER_API = "https://tor-us-signer-coval.vercel.app";
package/types/derive.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  declare global {
3
2
  interface Window {
4
3
  bitcoin: any;
@@ -0,0 +1,4 @@
1
+ import type { EmblemVaultClient, ProgressCallback, MintResult, ClaimResult, MetaData, SdkContext } from './types';
2
+ export declare function performMintEvm(ctx: SdkContext, client: EmblemVaultClient, tokenId: string, chainId: number, callback?: ProgressCallback): Promise<MintResult>;
3
+ export declare function performClaimEvm(ctx: SdkContext, client: EmblemVaultClient, tokenId: string, chainId: number, metadata: MetaData, claimIdentifier: string, vaultIsV2: boolean, needsOnChainUnvault: boolean, callback?: ProgressCallback): Promise<ClaimResult>;
4
+ export declare function deleteVaultEvm(client: EmblemVaultClient, tokenId: string, chainId: number, callback?: ProgressCallback): Promise<boolean>;
package/types/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BigNumber } from '@ethersproject/bignumber';
2
- import { Collection, CuratedCollectionsResponse, MetaData, Ownership, Vault } from './types';
2
+ import type { Collection, CuratedCollectionsResponse, MetaData, Ownership, Vault, ProgressCallback, MintResult, ClaimResult, EmblemVaultClient } from './types';
3
3
  declare class EmblemVaultSDK {
4
4
  private apiKey;
5
5
  private baseUrl;
@@ -45,6 +45,10 @@ declare class EmblemVaultSDK {
45
45
  refreshLegacyOwnership(web3: any, address: string): Promise<void>;
46
46
  checkLiveliness(tokenId: string, chainId?: number): Promise<any>;
47
47
  checkLivelinessBulk(tokenIds: string[], chainId?: number): Promise<any[]>;
48
+ private getSdkContext;
49
+ performMintChainWithClient(client: EmblemVaultClient, tokenId: string, chainId?: number | 'solana', callback?: ProgressCallback): Promise<MintResult>;
50
+ performClaimChainWithClient(client: EmblemVaultClient, tokenId: string, chainId?: number | 'solana', callback?: ProgressCallback): Promise<ClaimResult>;
51
+ deleteVaultWithClient(client: EmblemVaultClient, tokenId: string, chainId?: number | 'solana', callback?: ProgressCallback): Promise<boolean>;
48
52
  sweepVaultUsingPhrase(phrase: string, satsPerByte?: number, broadcast?: boolean): Promise<unknown>;
49
53
  }
50
54
  declare global {
@@ -0,0 +1,4 @@
1
+ export declare function buildMintMessage(tokenId: string): string;
2
+ export declare function buildClaimMessage(identifier: string, isV2Vault: boolean): string;
3
+ export declare function buildUnvaultMessage(identifier: string): string;
4
+ export declare function buildDeleteMessage(tokenId: string): string;
package/types/types.d.ts CHANGED
@@ -26,6 +26,14 @@ export type Collection = {
26
26
  balanceCheckers: string[] | null;
27
27
  tokenIdScheme: string | null;
28
28
  generateVaultBody: Function;
29
+ /**
30
+ * Returns a template ready to send to the create vault API
31
+ *
32
+ * @param {FillCreateVaultTemplateArgs} args - Arguments to fill the template
33
+ * @param {_this: Collection} _this - The collection context
34
+ * @returns {Object} - Filled create vault template
35
+ */
36
+ fillCreateVaultTemplate: (args: FillCreateVaultTemplateArgs, _this: Collection) => Object;
29
37
  generateCreateTemplate: Function;
30
38
  };
31
39
  export interface MetaData {
@@ -133,3 +141,82 @@ export type Ownership = {
133
141
  network: string;
134
142
  };
135
143
  export type CuratedCollectionsResponse = Collection[];
144
+ export type ChainIdentifier = number | 'solana';
145
+ export type ProgressCallback = (message: string, data?: unknown) => void;
146
+ export interface MintResult {
147
+ txHash: string;
148
+ tokenId: string;
149
+ chainId: ChainIdentifier;
150
+ }
151
+ export interface ClaimResult {
152
+ phrase?: string;
153
+ privateKey?: string;
154
+ }
155
+ export interface RemoteMintSignature {
156
+ _nftAddress: string;
157
+ _price: {
158
+ hex: string;
159
+ } | string | number;
160
+ _to: string;
161
+ _tokenId: {
162
+ hex: string;
163
+ } | string | number;
164
+ _nonce: {
165
+ hex: string;
166
+ } | string | number;
167
+ _signature: string;
168
+ serialNumber: string;
169
+ error?: string;
170
+ }
171
+ export interface RemoteUnvaultSignature {
172
+ success: boolean;
173
+ _nftAddress: string;
174
+ _tokenId: {
175
+ hex: string;
176
+ } | string | number;
177
+ _nonce: {
178
+ hex: string;
179
+ } | string | number;
180
+ _price: {
181
+ hex: string;
182
+ } | string | number;
183
+ _timestamp: {
184
+ hex: string;
185
+ } | string | number;
186
+ _signature: string;
187
+ msg?: string;
188
+ err?: string;
189
+ }
190
+ export interface EvmSigner {
191
+ getAddress(): Promise<string>;
192
+ signMessage(message: string | Uint8Array): Promise<string>;
193
+ sendTransaction(tx: unknown): Promise<{
194
+ hash: string;
195
+ wait(): Promise<unknown>;
196
+ }>;
197
+ setChainId?(chainId: number): void;
198
+ }
199
+ export interface EmblemVaultClient {
200
+ toEthersWallet(provider?: unknown): Promise<EvmSigner>;
201
+ }
202
+ export interface SdkContext {
203
+ apiKey: string;
204
+ baseUrl: string;
205
+ v3Url: string;
206
+ sigUrl: string;
207
+ fetchMetadata: (tokenId: string, callback?: ProgressCallback) => Promise<MetaData>;
208
+ requestRemoteKey: (tokenId: string, jwt: unknown, callback?: ProgressCallback) => Promise<unknown>;
209
+ decryptVaultKeys: (tokenId: string, dkeys: unknown, callback?: ProgressCallback) => Promise<ClaimResult>;
210
+ }
211
+ export interface FillCreateVaultTemplateArgs {
212
+ fromAddress: string;
213
+ toAddress: string;
214
+ targetAsset: {
215
+ name: string;
216
+ image: string;
217
+ description?: string;
218
+ ownedImage?: string;
219
+ projectName?: string;
220
+ };
221
+ chainId: number;
222
+ }
package/types/utils.d.ts CHANGED
@@ -40,4 +40,5 @@ interface SatsConnectAddress {
40
40
  }
41
41
  export declare function getSatsConnectAddress(): Promise<SatsConnectAddress>;
42
42
  export declare function signPSBT(psbtBase64: any, paymentAddress: any, indexes: number[], broadcast?: boolean): Promise<unknown>;
43
+ export declare function parseBigIntValue(value: unknown): bigint;
43
44
  export {};
@@ -0,0 +1,34 @@
1
+ import { ChainConfig } from "./constants";
2
+ export declare function isV2Vault(metadata: {
3
+ targetContract?: {
4
+ name?: string;
5
+ };
6
+ }): boolean;
7
+ export declare function requiresOnChainUnvault(metadata: {
8
+ status?: string;
9
+ sealed?: boolean;
10
+ live?: boolean;
11
+ }): boolean;
12
+ /**
13
+ * Get the claim identifier for signing claim messages.
14
+ * This MUST match VaultActions.vue's getSerialNumber() logic:
15
+ * - ERC1155: use targetContract.serialNumber
16
+ * - ERC721a: use tokenId
17
+ * - Legacy: use tokenId
18
+ */
19
+ export declare function getClaimIdentifier(metadata: {
20
+ ownershipInfo?: {
21
+ serialNumber?: string;
22
+ category?: string;
23
+ };
24
+ tokenId?: string;
25
+ targetContract?: {
26
+ serialNumber?: string;
27
+ collectionType?: string;
28
+ tokenId?: string;
29
+ };
30
+ }): string;
31
+ export declare function getHandlerContractAddress(chainId: number): string;
32
+ export declare function getUnvaultingContractAddress(chainId: number): string;
33
+ export declare function getChainConfig(chainId: number | string): ChainConfig;
34
+ export declare function isEvmChain(chainId: number | string): boolean;
@@ -668164,7 +668164,7 @@
668164
668164
  "lastPrice": 1314.8618656640904
668165
668165
  },
668166
668166
  "projectProtocol": "Counterparty",
668167
- "video": "https://arweave.net/Fb7BMNWJQwNCrRxdw_dbMC01t6iSVUytBtg5LziOOlI/2o51ir_video.mp4\\"
668167
+ "video": "https://arweave.net/Fb7BMNWJQwNCrRxdw_dbMC01t6iSVUytBtg5LziOOlI/2o51ir_video.mp4"
668168
668168
  },
668169
668169
  "DGAPEPE": {
668170
668170
  "image": "https://raw.githubusercontent.com/EmblemCompany/vaultImages/master/collection/fake-rares/DGAPEPE.gif",
@@ -668143,7 +668143,7 @@
668143
668143
  "price": 1040.9323103174047,
668144
668144
  "lastPrice": 1314.8618656640904
668145
668145
  },
668146
- "video": "https://arweave.net/Fb7BMNWJQwNCrRxdw_dbMC01t6iSVUytBtg5LziOOlI/2o51ir_video.mp4\\",
668146
+ "video": "https://arweave.net/Fb7BMNWJQwNCrRxdw_dbMC01t6iSVUytBtg5LziOOlI/2o51ir_video.mp4",
668147
668147
  "projectProtocol": "Counterparty"
668148
668148
  },
668149
668149
  "DGAPEPE": {