@idoa/wpis-core 0.1.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/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +12 -0
- package/dist/errors.js.map +1 -0
- package/dist/expiration.d.ts +4 -0
- package/dist/expiration.d.ts.map +1 -0
- package/dist/expiration.js +7 -0
- package/dist/expiration.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/state.d.ts +4 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +18 -0
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/validation.d.ts +6 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +61 -0
- package/dist/validation.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 WPIS contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @idoa/wpis-core
|
|
2
|
+
|
|
3
|
+
Core WPIS types and deterministic intent lifecycle utilities.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i @idoa/wpis-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { validateCreateIntentInput, transitionStatus, type CreateIntentInput } from "@idoa/wpis-core";
|
|
15
|
+
|
|
16
|
+
const input: CreateIntentInput = {
|
|
17
|
+
chainId: "eip155:421614",
|
|
18
|
+
recipient: "0x1111111111111111111111111111111111111111",
|
|
19
|
+
amount: "1000000000000000",
|
|
20
|
+
reference: "example-reference",
|
|
21
|
+
expiresAt: new Date(Date.now() + 15 * 60 * 1000).toISOString(),
|
|
22
|
+
asset: { symbol: "ETH", decimals: 18, type: "native" }
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
validateCreateIntentInput(input);
|
|
26
|
+
const next = transitionStatus("PENDING", "DETECTED");
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
For monorepo development, see the repository root README.
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type WpisErrorCode = "VALIDATION_ERROR" | "RPC_ERROR" | "EXPIRED_ERROR" | "CONFIRMATION_PENDING" | "CHAIN_MISMATCH";
|
|
2
|
+
export declare class WpisError extends Error {
|
|
3
|
+
readonly code: WpisErrorCode;
|
|
4
|
+
constructor(code: WpisErrorCode, message: string);
|
|
5
|
+
}
|
|
6
|
+
export declare function isWpisError(value: unknown): value is WpisError;
|
|
7
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GACrB,kBAAkB,GAClB,WAAW,GACX,eAAe,GACf,sBAAsB,GACtB,gBAAgB,CAAC;AAErB,qBAAa,SAAU,SAAQ,KAAK;IAClC,SAAgB,IAAI,EAAE,aAAa,CAAC;gBAEjB,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM;CAKxD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class WpisError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(code, message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "WpisError";
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function isWpisError(value) {
|
|
10
|
+
return value instanceof WpisError;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClB,IAAI,CAAgB;IAEpC,YAAmB,IAAmB,EAAE,OAAe;QACrD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,KAAK,YAAY,SAAS,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expiration.d.ts","sourceRoot":"","sources":["../src/expiration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,wBAAgB,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,GAAE,IAAiB,GAAG,OAAO,CAE/E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,GAAE,IAAiB,GAAG,OAAO,CAEtF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function isExpired(expiresAtIso, now = new Date()) {
|
|
2
|
+
return new Date(expiresAtIso).getTime() <= now.getTime();
|
|
3
|
+
}
|
|
4
|
+
export function isIntentExpired(intent, now = new Date()) {
|
|
5
|
+
return isExpired(intent.expiresAt, now);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=expiration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expiration.js","sourceRoot":"","sources":["../src/expiration.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,SAAS,CAAC,YAAoB,EAAE,MAAY,IAAI,IAAI,EAAE;IACpE,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAqB,EAAE,MAAY,IAAI,IAAI,EAAE;IAC3E,OAAO,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AAC1C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PaymentStatus } from "./types.js";
|
|
2
|
+
export declare function canTransition(from: PaymentStatus, to: PaymentStatus): boolean;
|
|
3
|
+
export declare function transitionStatus(from: PaymentStatus, to: PaymentStatus): PaymentStatus;
|
|
4
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAUhD,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE,EAAE,aAAa,GAAG,OAAO,CAE7E;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE,EAAE,aAAa,GAAG,aAAa,CAKtF"}
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { WpisError } from "./errors.js";
|
|
2
|
+
const allowedTransitions = {
|
|
3
|
+
PENDING: ["DETECTED", "CONFIRMED", "EXPIRED", "FAILED"],
|
|
4
|
+
DETECTED: ["CONFIRMED", "EXPIRED", "FAILED"],
|
|
5
|
+
CONFIRMED: [],
|
|
6
|
+
EXPIRED: [],
|
|
7
|
+
FAILED: []
|
|
8
|
+
};
|
|
9
|
+
export function canTransition(from, to) {
|
|
10
|
+
return allowedTransitions[from].includes(to);
|
|
11
|
+
}
|
|
12
|
+
export function transitionStatus(from, to) {
|
|
13
|
+
if (!canTransition(from, to)) {
|
|
14
|
+
throw new WpisError("VALIDATION_ERROR", `invalid status transition: ${from} -> ${to}`);
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,MAAM,kBAAkB,GAA2C;IACjE,OAAO,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAC;IACvD,QAAQ,EAAE,CAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAC;IAC5C,SAAS,EAAE,EAAE;IACb,OAAO,EAAE,EAAE;IACX,MAAM,EAAE,EAAE;CACX,CAAC;AAEF,MAAM,UAAU,aAAa,CAAC,IAAmB,EAAE,EAAiB;IAClE,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAmB,EAAE,EAAiB;IACrE,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,SAAS,CAAC,kBAAkB,EAAE,8BAA8B,IAAI,OAAO,EAAE,EAAE,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type PaymentStatus = "PENDING" | "DETECTED" | "CONFIRMED" | "EXPIRED" | "FAILED";
|
|
2
|
+
export type AssetType = "native" | "erc20";
|
|
3
|
+
export interface PaymentAsset {
|
|
4
|
+
symbol: string;
|
|
5
|
+
decimals: number;
|
|
6
|
+
type: AssetType;
|
|
7
|
+
contractAddress?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ConfirmationPolicy {
|
|
10
|
+
minConfirmations: number;
|
|
11
|
+
}
|
|
12
|
+
export interface PaymentIntent {
|
|
13
|
+
id: string;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
expiresAt: string;
|
|
16
|
+
chainId: string;
|
|
17
|
+
asset: PaymentAsset;
|
|
18
|
+
recipient: string;
|
|
19
|
+
amount: string;
|
|
20
|
+
reference: string;
|
|
21
|
+
confirmationPolicy: ConfirmationPolicy;
|
|
22
|
+
status: PaymentStatus;
|
|
23
|
+
}
|
|
24
|
+
export interface CreateIntentInput {
|
|
25
|
+
chainId?: string;
|
|
26
|
+
asset: PaymentAsset;
|
|
27
|
+
recipient: string;
|
|
28
|
+
amount: string;
|
|
29
|
+
reference: string;
|
|
30
|
+
expiresAt: string;
|
|
31
|
+
confirmationPolicy?: ConfirmationPolicy;
|
|
32
|
+
}
|
|
33
|
+
export interface PaymentRequest {
|
|
34
|
+
paymentLink: string;
|
|
35
|
+
qrPayload: string;
|
|
36
|
+
instructions: string[];
|
|
37
|
+
expiresAt: string;
|
|
38
|
+
}
|
|
39
|
+
export interface VerificationResult {
|
|
40
|
+
status: PaymentStatus;
|
|
41
|
+
txHash?: string;
|
|
42
|
+
confirmations?: number;
|
|
43
|
+
reason?: string;
|
|
44
|
+
errorCode?: import("./errors.js").WpisErrorCode;
|
|
45
|
+
}
|
|
46
|
+
export interface ChainAdapter {
|
|
47
|
+
createIntent(input: CreateIntentInput): PaymentIntent;
|
|
48
|
+
buildRequest(intent: PaymentIntent): PaymentRequest;
|
|
49
|
+
verify(intent: PaymentIntent): Promise<VerificationResult>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mapp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EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,aAAa,EAAE,aAAa,CAAC;CACjD;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,aAAa,CAAC;IACtD,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,cAAc,CAAC;IACpD,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAC5D"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CreateIntentInput, PaymentIntent } from "./types.js";
|
|
2
|
+
export declare function isValidEvmAddress(value: string): boolean;
|
|
3
|
+
export declare function isPositiveIntegerString(value: string): boolean;
|
|
4
|
+
export declare function validateCreateIntentInput(input: CreateIntentInput): void;
|
|
5
|
+
export declare function validateIntent(intent: PaymentIntent): void;
|
|
6
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAgB,aAAa,EAAE,MAAM,YAAY,CAAC;AAKjF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAExD;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAK9D;AAmBD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAwBxE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAU1D"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { WpisError } from "./errors.js";
|
|
2
|
+
const EVM_ADDRESS_PATTERN = /^0x[a-fA-F0-9]{40}$/;
|
|
3
|
+
export function isValidEvmAddress(value) {
|
|
4
|
+
return EVM_ADDRESS_PATTERN.test(value);
|
|
5
|
+
}
|
|
6
|
+
export function isPositiveIntegerString(value) {
|
|
7
|
+
if (!/^\d+$/.test(value)) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return BigInt(value) > 0n;
|
|
11
|
+
}
|
|
12
|
+
function validateAsset(asset) {
|
|
13
|
+
if (!asset.symbol.trim()) {
|
|
14
|
+
throw new WpisError("VALIDATION_ERROR", "asset.symbol is required");
|
|
15
|
+
}
|
|
16
|
+
if (asset.decimals < 0 || !Number.isInteger(asset.decimals)) {
|
|
17
|
+
throw new WpisError("VALIDATION_ERROR", "asset.decimals must be a non-negative integer");
|
|
18
|
+
}
|
|
19
|
+
if (asset.type === "erc20") {
|
|
20
|
+
if (!asset.contractAddress) {
|
|
21
|
+
throw new WpisError("VALIDATION_ERROR", "asset.contractAddress is required for erc20 assets");
|
|
22
|
+
}
|
|
23
|
+
if (!isValidEvmAddress(asset.contractAddress)) {
|
|
24
|
+
throw new WpisError("VALIDATION_ERROR", "asset.contractAddress must be a valid EVM address");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function validateCreateIntentInput(input) {
|
|
29
|
+
validateAsset(input.asset);
|
|
30
|
+
if (!input.reference.trim()) {
|
|
31
|
+
throw new WpisError("VALIDATION_ERROR", "reference is required");
|
|
32
|
+
}
|
|
33
|
+
if (!isValidEvmAddress(input.recipient)) {
|
|
34
|
+
throw new WpisError("VALIDATION_ERROR", "recipient must be a valid EVM address");
|
|
35
|
+
}
|
|
36
|
+
if (!isPositiveIntegerString(input.amount)) {
|
|
37
|
+
throw new WpisError("VALIDATION_ERROR", "amount must be a positive integer string in base units");
|
|
38
|
+
}
|
|
39
|
+
const expiresAt = new Date(input.expiresAt);
|
|
40
|
+
if (Number.isNaN(expiresAt.getTime())) {
|
|
41
|
+
throw new WpisError("VALIDATION_ERROR", "expiresAt must be a valid ISO datetime string");
|
|
42
|
+
}
|
|
43
|
+
if (expiresAt.getTime() <= Date.now()) {
|
|
44
|
+
throw new WpisError("VALIDATION_ERROR", "expiresAt must be in the future");
|
|
45
|
+
}
|
|
46
|
+
if (input.confirmationPolicy && input.confirmationPolicy.minConfirmations < 0) {
|
|
47
|
+
throw new WpisError("VALIDATION_ERROR", "confirmationPolicy.minConfirmations must be >= 0");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function validateIntent(intent) {
|
|
51
|
+
validateCreateIntentInput({
|
|
52
|
+
chainId: intent.chainId,
|
|
53
|
+
asset: intent.asset,
|
|
54
|
+
recipient: intent.recipient,
|
|
55
|
+
amount: intent.amount,
|
|
56
|
+
reference: intent.reference,
|
|
57
|
+
expiresAt: intent.expiresAt,
|
|
58
|
+
confirmationPolicy: intent.confirmationPolicy
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAElD,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,OAAO,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,KAAa;IACnD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAC5B,CAAC;AAED,SAAS,aAAa,CAAC,KAAmB;IACxC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QAC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AAC,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,SAAS,CAAC,kBAAkB,EAAE,+CAA+C,CAAC,CAAC;IAC3F,CAAC;IACD,IAAI,SAAS,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,SAAS,CAAC,kBAAkB,EAAE,iCAAiC,CAAC,CAAC;IAC7E,CAAC;IAED,IAAI,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,kBAAkB,CAAC,gBAAgB,GAAG,CAAC,EAAE,CAAC;QAC9E,MAAM,IAAI,SAAS,CAAC,kBAAkB,EAAE,kDAAkD,CAAC,CAAC;IAC9F,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAqB;IAClD,yBAAyB,CAAC;QACxB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;KAC9C,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@idoa/wpis-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Deterministic payment intent primitives for WPIS.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -p tsconfig.json",
|
|
17
|
+
"test": "vitest run"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"wpis",
|
|
28
|
+
"web3",
|
|
29
|
+
"payment-intent",
|
|
30
|
+
"arbitrum",
|
|
31
|
+
"sdk"
|
|
32
|
+
],
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/Mateja3m/wpis.git"
|
|
36
|
+
},
|
|
37
|
+
"author": "Milan Matejic",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
}
|
|
42
|
+
}
|