@waffo/waffo-node 2.5.0 → 2.6.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/README.md +41 -2
- package/dist/index.d.mts +783 -615
- package/dist/index.d.ts +783 -615
- package/dist/index.js +74 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -92,18 +92,18 @@ var WaffoUnknownStatusError = class _WaffoUnknownStatusError extends Error {
|
|
|
92
92
|
// src/utils/rsa-utils.ts
|
|
93
93
|
var ALGORITHM = "RSA-SHA256";
|
|
94
94
|
var KEY_SIZE = 2048;
|
|
95
|
-
|
|
95
|
+
var PKCS8_PEM_HEADER = "-----BEGIN PRIVATE KEY-----";
|
|
96
|
+
var PEM_HEADER_PREFIX = "-----BEGIN ";
|
|
97
|
+
var INVALID_PRIVATE_KEY_FORMAT_MESSAGE = "Invalid private key format. Please provide an unencrypted PKCS#8 private key.";
|
|
98
|
+
function sign(data, privateKeyInput) {
|
|
96
99
|
try {
|
|
97
|
-
const
|
|
100
|
+
const privateKey = parsePrivateKey(privateKeyInput);
|
|
98
101
|
const signer = crypto.createSign(ALGORITHM);
|
|
99
102
|
signer.update(data, "utf8");
|
|
100
|
-
const signature = signer.sign(
|
|
101
|
-
key: privateKeyBuffer,
|
|
102
|
-
format: "der",
|
|
103
|
-
type: "pkcs8"
|
|
104
|
-
});
|
|
103
|
+
const signature = signer.sign(privateKey);
|
|
105
104
|
return signature.toString("base64");
|
|
106
105
|
} catch (error) {
|
|
106
|
+
if (error instanceof WaffoError) throw error;
|
|
107
107
|
throw new WaffoError(
|
|
108
108
|
WaffoErrorCode.SIGN_FAILED,
|
|
109
109
|
`Failed to sign data: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -137,29 +137,43 @@ function validatePrivateKey(base64PrivateKey) {
|
|
|
137
137
|
);
|
|
138
138
|
}
|
|
139
139
|
try {
|
|
140
|
-
|
|
141
|
-
crypto.createPrivateKey({
|
|
142
|
-
key: keyBuffer,
|
|
143
|
-
format: "der",
|
|
144
|
-
type: "pkcs8"
|
|
145
|
-
});
|
|
140
|
+
parsePrivateKey(base64PrivateKey);
|
|
146
141
|
} catch (error) {
|
|
147
142
|
if (error instanceof WaffoError) throw error;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
143
|
+
throw new WaffoError(
|
|
144
|
+
WaffoErrorCode.INVALID_PRIVATE_KEY,
|
|
145
|
+
INVALID_PRIVATE_KEY_FORMAT_MESSAGE,
|
|
146
|
+
error instanceof Error ? error : void 0
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function parsePrivateKey(privateKeyInput) {
|
|
151
|
+
try {
|
|
152
|
+
const trimmed = privateKeyInput.trim();
|
|
153
|
+
const key = trimmed.startsWith(PKCS8_PEM_HEADER) ? crypto.createPrivateKey(trimmed) : parseDerPrivateKey(trimmed);
|
|
154
|
+
if (key.asymmetricKeyType !== "rsa") {
|
|
155
|
+
throw new Error("private key is not RSA");
|
|
155
156
|
}
|
|
157
|
+
return key;
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (error instanceof WaffoError) throw error;
|
|
156
160
|
throw new WaffoError(
|
|
157
161
|
WaffoErrorCode.INVALID_PRIVATE_KEY,
|
|
158
|
-
|
|
162
|
+
INVALID_PRIVATE_KEY_FORMAT_MESSAGE,
|
|
159
163
|
error instanceof Error ? error : void 0
|
|
160
164
|
);
|
|
161
165
|
}
|
|
162
166
|
}
|
|
167
|
+
function parseDerPrivateKey(trimmedPrivateKey) {
|
|
168
|
+
if (trimmedPrivateKey.startsWith(PEM_HEADER_PREFIX)) {
|
|
169
|
+
throw new Error("unsupported PEM private key");
|
|
170
|
+
}
|
|
171
|
+
return crypto.createPrivateKey({
|
|
172
|
+
key: Buffer.from(trimmedPrivateKey, "base64"),
|
|
173
|
+
format: "der",
|
|
174
|
+
type: "pkcs8"
|
|
175
|
+
});
|
|
176
|
+
}
|
|
163
177
|
function validatePublicKey(base64PublicKey) {
|
|
164
178
|
if (!base64PublicKey || base64PublicKey.trim() === "") {
|
|
165
179
|
throw new WaffoError(
|
|
@@ -441,7 +455,7 @@ var HEADER_SDK_VERSION = "x-sdk-version";
|
|
|
441
455
|
var HEADER_CONTENT_TYPE = "content-type";
|
|
442
456
|
var CONTENT_TYPE_JSON = "application/json";
|
|
443
457
|
var API_VERSION = "1.0.0";
|
|
444
|
-
var SDK_VERSION = "waffo-node/2.
|
|
458
|
+
var SDK_VERSION = "waffo-node/2.6.0";
|
|
445
459
|
var WaffoHttpClient = class {
|
|
446
460
|
baseUrl;
|
|
447
461
|
apiKey;
|
|
@@ -453,6 +467,8 @@ var WaffoHttpClient = class {
|
|
|
453
467
|
logger;
|
|
454
468
|
httpTransport;
|
|
455
469
|
constructor(config) {
|
|
470
|
+
RsaUtils.validatePrivateKey(config.privateKey);
|
|
471
|
+
RsaUtils.validatePublicKey(config.waffoPublicKey);
|
|
456
472
|
this.baseUrl = EnvironmentBaseUrl[config.environment];
|
|
457
473
|
this.apiKey = config.apiKey;
|
|
458
474
|
this.privateKey = config.privateKey;
|
|
@@ -591,7 +607,7 @@ var WaffoHttpClient = class {
|
|
|
591
607
|
isNetworkError(error) {
|
|
592
608
|
if (!(error instanceof Error)) return false;
|
|
593
609
|
const message = error.message.toLowerCase();
|
|
594
|
-
return error.name === "AbortError" || message.includes("timeout") || message.includes("econnrefused") || message.includes("enotfound") || message.includes("network") || message.includes("socket") || message.includes("connection");
|
|
610
|
+
return error.name === "AbortError" || message.includes("timeout") || message.includes("econnrefused") || message.includes("enotfound") || message.includes("fetch failed") || message.includes("network") || message.includes("socket") || message.includes("connection");
|
|
595
611
|
}
|
|
596
612
|
};
|
|
597
613
|
|
|
@@ -1134,6 +1150,26 @@ var PayMethodConfigResource = class _PayMethodConfigResource extends BaseResourc
|
|
|
1134
1150
|
}
|
|
1135
1151
|
};
|
|
1136
1152
|
|
|
1153
|
+
// src/resources/wallet-resource.ts
|
|
1154
|
+
var WalletResource = class _WalletResource extends BaseResource {
|
|
1155
|
+
static PATH_INQUIRY = "/inquiry";
|
|
1156
|
+
/**
|
|
1157
|
+
* Inquires the stablecoin receiving address for an x402 payment.
|
|
1158
|
+
*
|
|
1159
|
+
* @param params - Wallet inquiry parameters
|
|
1160
|
+
* @param options - Optional request options
|
|
1161
|
+
* @returns API response with wallet data
|
|
1162
|
+
* @throws WaffoUnknownStatusError for network errors
|
|
1163
|
+
*/
|
|
1164
|
+
async inquiry(params, options) {
|
|
1165
|
+
return this.httpClient.post(
|
|
1166
|
+
this.getPath(_WalletResource.PATH_INQUIRY),
|
|
1167
|
+
params,
|
|
1168
|
+
options
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
};
|
|
1172
|
+
|
|
1137
1173
|
// src/waffo.ts
|
|
1138
1174
|
var Waffo = class _Waffo {
|
|
1139
1175
|
config;
|
|
@@ -1144,14 +1180,15 @@ var Waffo = class _Waffo {
|
|
|
1144
1180
|
_refund;
|
|
1145
1181
|
_merchantConfig;
|
|
1146
1182
|
_payMethodConfig;
|
|
1183
|
+
_wallet;
|
|
1147
1184
|
/**
|
|
1148
1185
|
* Creates a new Waffo SDK instance.
|
|
1149
1186
|
*
|
|
1150
1187
|
* @param config - SDK configuration
|
|
1151
1188
|
*/
|
|
1152
1189
|
constructor(config) {
|
|
1153
|
-
this.config = config;
|
|
1154
|
-
this.httpClient = new WaffoHttpClient(config);
|
|
1190
|
+
this.config = createWaffoConfig(config);
|
|
1191
|
+
this.httpClient = new WaffoHttpClient(this.config);
|
|
1155
1192
|
}
|
|
1156
1193
|
/**
|
|
1157
1194
|
* Creates a Waffo SDK instance from environment variables.
|
|
@@ -1227,6 +1264,17 @@ var Waffo = class _Waffo {
|
|
|
1227
1264
|
}
|
|
1228
1265
|
return this._payMethodConfig;
|
|
1229
1266
|
}
|
|
1267
|
+
/**
|
|
1268
|
+
* Returns the wallet resource for x402 stablecoin receiving-address inquiry.
|
|
1269
|
+
*
|
|
1270
|
+
* @returns Wallet resource
|
|
1271
|
+
*/
|
|
1272
|
+
wallet() {
|
|
1273
|
+
if (!this._wallet) {
|
|
1274
|
+
this._wallet = new WalletResource(this.httpClient, "/wallet");
|
|
1275
|
+
}
|
|
1276
|
+
return this._wallet;
|
|
1277
|
+
}
|
|
1230
1278
|
/**
|
|
1231
1279
|
* Creates a webhook handler for processing Waffo webhook notifications.
|
|
1232
1280
|
*
|
|
@@ -1270,6 +1318,6 @@ var Waffo = class _Waffo {
|
|
|
1270
1318
|
}
|
|
1271
1319
|
};
|
|
1272
1320
|
|
|
1273
|
-
export { ApiResponse, Environment, EnvironmentBaseUrl, MerchantConfigResource, OrderResource, PayMethodConfigResource, RefundResource, RsaUtils, SubscriptionResource, Waffo, WaffoConfigDefaults, WaffoError, WaffoErrorCode, WaffoHttpClient, WaffoUnknownStatusError, WebhookEventType, WebhookHandler };
|
|
1321
|
+
export { ApiResponse, Environment, EnvironmentBaseUrl, MerchantConfigResource, OrderResource, PayMethodConfigResource, RefundResource, RsaUtils, SubscriptionResource, Waffo, WaffoConfigDefaults, WaffoError, WaffoErrorCode, WaffoHttpClient, WaffoUnknownStatusError, WalletResource, WebhookEventType, WebhookHandler };
|
|
1274
1322
|
//# sourceMappingURL=index.mjs.map
|
|
1275
1323
|
//# sourceMappingURL=index.mjs.map
|