@velumx/sdk 2.1.0 → 2.2.0
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/VelumXClient.d.ts +12 -3
- package/dist/VelumXClient.js +19 -7
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
- package/src/VelumXClient.ts +21 -8
- package/src/types.ts +7 -2
package/dist/VelumXClient.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { SignedIntent, NetworkConfig } from './types';
|
|
1
|
+
import { SignedIntent, NetworkConfig, SponsorshipOptions } from './types';
|
|
2
2
|
export declare class VelumXClient {
|
|
3
3
|
private config;
|
|
4
4
|
private relayerUrl;
|
|
5
5
|
constructor(config: NetworkConfig);
|
|
6
6
|
/**
|
|
7
|
-
* Get a fee estimation from the
|
|
7
|
+
* Get a fee estimation from the relayer for a specific intent
|
|
8
8
|
*/
|
|
9
9
|
estimateFee(intent: any): Promise<{
|
|
10
10
|
maxFeeUSDCx: string;
|
|
@@ -17,10 +17,19 @@ export declare class VelumXClient {
|
|
|
17
17
|
txid: string;
|
|
18
18
|
status: string;
|
|
19
19
|
}>;
|
|
20
|
+
/**
|
|
21
|
+
* [New Recommended Method] Request sponsorship for a Stacks transaction
|
|
22
|
+
* @param txHex The raw transaction hex
|
|
23
|
+
* @param options Metadata like developer-reported fee and userId
|
|
24
|
+
*/
|
|
25
|
+
sponsor(txHex: string, options?: SponsorshipOptions): Promise<{
|
|
26
|
+
txid: string;
|
|
27
|
+
status: string;
|
|
28
|
+
}>;
|
|
20
29
|
/**
|
|
21
30
|
* Submit a raw Stacks transaction hex for native sponsorship
|
|
22
31
|
*/
|
|
23
|
-
submitRawTransaction(txHex: string): Promise<{
|
|
32
|
+
submitRawTransaction(txHex: string, options?: SponsorshipOptions): Promise<{
|
|
24
33
|
txid: string;
|
|
25
34
|
status: string;
|
|
26
35
|
}>;
|
package/dist/VelumXClient.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VelumXClient = void 0;
|
|
4
4
|
class VelumXClient {
|
|
5
5
|
constructor(config) {
|
|
6
|
-
if (!config.apiKey) {
|
|
6
|
+
if (!config.apiKey && !config.paymasterUrl?.includes('/api/velumx/proxy')) {
|
|
7
7
|
throw new Error("VelumX Client Error: API Key is required. Please obtain your key from the VelumX Developer Dashboard.");
|
|
8
8
|
}
|
|
9
9
|
this.config = config;
|
|
@@ -11,12 +11,12 @@ class VelumXClient {
|
|
|
11
11
|
this.relayerUrl = config.paymasterUrl || 'https://relayer.velumx.com/api/v1';
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Get a fee estimation from the
|
|
14
|
+
* Get a fee estimation from the relayer for a specific intent
|
|
15
15
|
*/
|
|
16
16
|
async estimateFee(intent) {
|
|
17
17
|
try {
|
|
18
18
|
const headers = { 'Content-Type': 'application/json' };
|
|
19
|
-
if (this.config.apiKey) {
|
|
19
|
+
if (this.config.apiKey && this.config.apiKey !== 'proxied') {
|
|
20
20
|
headers['x-api-key'] = this.config.apiKey;
|
|
21
21
|
}
|
|
22
22
|
const response = await fetch(`${this.relayerUrl}/estimate`, {
|
|
@@ -41,7 +41,7 @@ class VelumXClient {
|
|
|
41
41
|
async submitIntent(signedIntent) {
|
|
42
42
|
try {
|
|
43
43
|
const headers = { 'Content-Type': 'application/json' };
|
|
44
|
-
if (this.config.apiKey) {
|
|
44
|
+
if (this.config.apiKey && this.config.apiKey !== 'proxied') {
|
|
45
45
|
headers['x-api-key'] = this.config.apiKey;
|
|
46
46
|
}
|
|
47
47
|
const response = await fetch(`${this.relayerUrl}/sponsor`, {
|
|
@@ -60,19 +60,31 @@ class VelumXClient {
|
|
|
60
60
|
throw error;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* [New Recommended Method] Request sponsorship for a Stacks transaction
|
|
65
|
+
* @param txHex The raw transaction hex
|
|
66
|
+
* @param options Metadata like developer-reported fee and userId
|
|
67
|
+
*/
|
|
68
|
+
async sponsor(txHex, options) {
|
|
69
|
+
return this.submitRawTransaction(txHex, options);
|
|
70
|
+
}
|
|
63
71
|
/**
|
|
64
72
|
* Submit a raw Stacks transaction hex for native sponsorship
|
|
65
73
|
*/
|
|
66
|
-
async submitRawTransaction(txHex) {
|
|
74
|
+
async submitRawTransaction(txHex, options) {
|
|
67
75
|
try {
|
|
68
76
|
const headers = { 'Content-Type': 'application/json' };
|
|
69
|
-
if (this.config.apiKey) {
|
|
77
|
+
if (this.config.apiKey && this.config.apiKey !== 'proxied') {
|
|
70
78
|
headers['x-api-key'] = this.config.apiKey;
|
|
71
79
|
}
|
|
72
80
|
const response = await fetch(`${this.relayerUrl}/broadcast`, {
|
|
73
81
|
method: 'POST',
|
|
74
82
|
headers,
|
|
75
|
-
body: JSON.stringify({
|
|
83
|
+
body: JSON.stringify({
|
|
84
|
+
txHex,
|
|
85
|
+
userId: options?.userId,
|
|
86
|
+
feeAmount: options?.feeAmount
|
|
87
|
+
})
|
|
76
88
|
});
|
|
77
89
|
if (!response.ok) {
|
|
78
90
|
const errData = await response.json().catch(() => ({ error: 'Unknown error' }));
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
package/src/VelumXClient.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { SignedIntent, NetworkConfig } from './types';
|
|
1
|
+
import { SignedIntent, NetworkConfig, SponsorshipOptions } from './types';
|
|
2
2
|
|
|
3
3
|
export class VelumXClient {
|
|
4
4
|
private config: NetworkConfig;
|
|
5
5
|
private relayerUrl: string;
|
|
6
6
|
|
|
7
7
|
constructor(config: NetworkConfig) {
|
|
8
|
-
if (!config.apiKey) {
|
|
8
|
+
if (!config.apiKey && !config.paymasterUrl?.includes('/api/velumx/proxy')) {
|
|
9
9
|
throw new Error("VelumX Client Error: API Key is required. Please obtain your key from the VelumX Developer Dashboard.");
|
|
10
10
|
}
|
|
11
11
|
this.config = config;
|
|
@@ -14,12 +14,12 @@ export class VelumXClient {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Get a fee estimation from the
|
|
17
|
+
* Get a fee estimation from the relayer for a specific intent
|
|
18
18
|
*/
|
|
19
19
|
public async estimateFee(intent: any): Promise<{ maxFeeUSDCx: string, estimatedGas: number }> {
|
|
20
20
|
try {
|
|
21
21
|
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
|
22
|
-
if (this.config.apiKey) {
|
|
22
|
+
if (this.config.apiKey && this.config.apiKey !== 'proxied') {
|
|
23
23
|
headers['x-api-key'] = this.config.apiKey;
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -47,7 +47,7 @@ export class VelumXClient {
|
|
|
47
47
|
public async submitIntent(signedIntent: SignedIntent): Promise<{ txid: string, status: string }> {
|
|
48
48
|
try {
|
|
49
49
|
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
|
50
|
-
if (this.config.apiKey) {
|
|
50
|
+
if (this.config.apiKey && this.config.apiKey !== 'proxied') {
|
|
51
51
|
headers['x-api-key'] = this.config.apiKey;
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -69,20 +69,33 @@ export class VelumXClient {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* [New Recommended Method] Request sponsorship for a Stacks transaction
|
|
74
|
+
* @param txHex The raw transaction hex
|
|
75
|
+
* @param options Metadata like developer-reported fee and userId
|
|
76
|
+
*/
|
|
77
|
+
public async sponsor(txHex: string, options?: SponsorshipOptions): Promise<{ txid: string, status: string }> {
|
|
78
|
+
return this.submitRawTransaction(txHex, options);
|
|
79
|
+
}
|
|
80
|
+
|
|
72
81
|
/**
|
|
73
82
|
* Submit a raw Stacks transaction hex for native sponsorship
|
|
74
83
|
*/
|
|
75
|
-
public async submitRawTransaction(txHex: string): Promise<{ txid: string, status: string }> {
|
|
84
|
+
public async submitRawTransaction(txHex: string, options?: SponsorshipOptions): Promise<{ txid: string, status: string }> {
|
|
76
85
|
try {
|
|
77
86
|
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
|
78
|
-
if (this.config.apiKey) {
|
|
87
|
+
if (this.config.apiKey && this.config.apiKey !== 'proxied') {
|
|
79
88
|
headers['x-api-key'] = this.config.apiKey;
|
|
80
89
|
}
|
|
81
90
|
|
|
82
91
|
const response = await fetch(`${this.relayerUrl}/broadcast`, {
|
|
83
92
|
method: 'POST',
|
|
84
93
|
headers,
|
|
85
|
-
body: JSON.stringify({
|
|
94
|
+
body: JSON.stringify({
|
|
95
|
+
txHex,
|
|
96
|
+
userId: options?.userId,
|
|
97
|
+
feeAmount: options?.feeAmount
|
|
98
|
+
})
|
|
86
99
|
});
|
|
87
100
|
|
|
88
101
|
if (!response.ok) {
|
package/src/types.ts
CHANGED
|
@@ -15,6 +15,11 @@ export interface SignedIntent extends WalletIntent {
|
|
|
15
15
|
export interface NetworkConfig {
|
|
16
16
|
coreApiUrl: string;
|
|
17
17
|
network: 'mainnet' | 'testnet' | 'devnet';
|
|
18
|
-
paymasterUrl?: string; // URL for the
|
|
19
|
-
apiKey?: string; //
|
|
18
|
+
paymasterUrl?: string; // URL for the VelumX relayer service
|
|
19
|
+
apiKey?: string; // VelumX API Key
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SponsorshipOptions {
|
|
23
|
+
userId?: string;
|
|
24
|
+
feeAmount?: string;
|
|
20
25
|
}
|