402mob-merchant-sdk 0.3.0 → 0.3.1
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 +3 -3
- package/dist/index.js +10 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Install from npm:
|
|
|
26
26
|
npm install 402mob-merchant-sdk
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
Version **0.3.1** requires standard 65-byte EIP-191 signatures for enrollment and credential rotation, rejecting malformed or compact 64-byte signatures before submission. It retains resource resolution and seller Work Ticket methods from 0.3.0. See the [npm package](https://www.npmjs.com/package/402mob-merchant-sdk) and [source](https://github.com/gggggggg424242/402mob-merchant-sdk).
|
|
30
30
|
|
|
31
31
|
Requires Node.js 18 or newer. The SDK uses the built-in Fetch API and has no runtime dependencies.
|
|
32
32
|
|
|
@@ -201,7 +201,7 @@ Adds `setDiscoverable(discoverable)`, which calls the authenticated `PUT /v1/age
|
|
|
201
201
|
The source now rejects unreadable or incomplete successful API responses with `MerchantApiError` code `invalid_response`. Challenge fields and zero-USDC instructions are checked before invoking the wallet callback; enrollment and rotation responses must contain a merchant ID and a nonempty API key. An invalid completion response can mean the server already completed the operation: recover access through credential rotation if its one-time key was lost. This validation is included in published 0.1.2. Integrations using 0.1.1 should validate required fields explicitly. Preserve the original challenge and submitted transaction hash when completion is interrupted; rerunning `enrollWithTransaction` creates a fresh challenge and invokes the wallet callback again. A completion error is not permission to submit another proof transaction automatically.
|
|
202
202
|
|
|
203
203
|
|
|
204
|
-
## Work Ticket reads and recovery
|
|
204
|
+
## Work Ticket reads and recovery
|
|
205
205
|
|
|
206
206
|
Buyer agents can call `client.getWorkTicketStatus(ticketId)` without an API key to read state, quote terms, payment references, and result hashes. This public response excludes the buyer wallet, private input, and signed buyer receipt. It does not fetch result bytes or authorize payment.
|
|
207
207
|
|
|
@@ -211,4 +211,4 @@ The supported states are `open`, `claimed`, `quoted`, `accepted`, `paying`, `pai
|
|
|
211
211
|
|
|
212
212
|
SDK requests reject HTTP redirects and never retry automatically. An interrupted mutation may have completed. Read the ticket before repeating a claim or quote; quote and claim creation are not idempotent. Repeating identical result content is supported while retained. For payment recovery through HTTP or MCP, reuse the original checkout key and authorization, including after delivery or a buyer receipt. The SDK does not submit payments.
|
|
213
213
|
|
|
214
|
-
These methods are
|
|
214
|
+
These methods are available from version 0.3.0.
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
function requireEip191Signature(signature) {
|
|
2
|
+
if (!/^0x[0-9a-fA-F]{130}$/.test(signature)) {
|
|
3
|
+
throw new TypeError("signature must be a 65-byte EIP-191 signature encoded as 0x-prefixed hex.");
|
|
4
|
+
}
|
|
5
|
+
return signature;
|
|
6
|
+
}
|
|
1
7
|
export class MerchantApiError extends Error {
|
|
2
8
|
status;
|
|
3
9
|
code;
|
|
@@ -44,7 +50,7 @@ export class MerchantClient {
|
|
|
44
50
|
return this.request("POST", "/v1/merchants/enrollment-challenges", input);
|
|
45
51
|
}
|
|
46
52
|
completeEnrollmentWithSignature(input) {
|
|
47
|
-
return this.request("POST", "/v1/merchants/enrollments", input);
|
|
53
|
+
return this.request("POST", "/v1/merchants/enrollments", { ...input, signature: requireEip191Signature(input.signature) });
|
|
48
54
|
}
|
|
49
55
|
completeEnrollmentWithTransaction(input) {
|
|
50
56
|
return this.request("POST", "/v1/merchants/enrollments/transaction", input);
|
|
@@ -52,7 +58,7 @@ export class MerchantClient {
|
|
|
52
58
|
/** Request a challenge, ask the caller's wallet adapter to sign its exact message, then enroll. */
|
|
53
59
|
async enrollWithSignature(input) {
|
|
54
60
|
const challenge = await this.createEnrollmentChallenge({ wallet: input.wallet, name: input.name });
|
|
55
|
-
const signature = await input.signMessage(challenge.message);
|
|
61
|
+
const signature = requireEip191Signature(await input.signMessage(challenge.message));
|
|
56
62
|
return this.completeEnrollmentWithSignature({
|
|
57
63
|
wallet: input.wallet,
|
|
58
64
|
name: input.name,
|
|
@@ -75,14 +81,14 @@ export class MerchantClient {
|
|
|
75
81
|
return this.request("POST", "/v1/merchants/credential-challenges", { wallet });
|
|
76
82
|
}
|
|
77
83
|
rotateCredentialWithSignature(wallet, challengeId, signature) {
|
|
78
|
-
return this.request("POST", "/v1/merchants/credentials/rotate", { wallet, challengeId, signature });
|
|
84
|
+
return this.request("POST", "/v1/merchants/credentials/rotate", { wallet, challengeId, signature: requireEip191Signature(signature) });
|
|
79
85
|
}
|
|
80
86
|
rotateCredentialWithTransaction(input) {
|
|
81
87
|
return this.request("POST", "/v1/merchants/credentials/rotate-transaction", input);
|
|
82
88
|
}
|
|
83
89
|
async rotateWithSignature(input) {
|
|
84
90
|
const challenge = await this.createCredentialRotationChallenge(input.wallet);
|
|
85
|
-
const signature = await input.signMessage(challenge.message);
|
|
91
|
+
const signature = requireEip191Signature(await input.signMessage(challenge.message));
|
|
86
92
|
return this.rotateCredentialWithSignature(input.wallet, challenge.challengeId, signature);
|
|
87
93
|
}
|
|
88
94
|
async rotateWithTransaction(input) {
|