@idos-network/kwil-infra 1.2.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/README.md +46 -1
  3. package/dist/actions/index.d.mts +2 -2
  4. package/dist/actions/index.mjs +1 -1370
  5. package/dist/actions/index.mjs.map +1 -1
  6. package/dist/facesign/index.d.mts +1 -1
  7. package/dist/facesign/index.mjs +1 -2
  8. package/dist/{facesign-signer-ADd4EASX.d.mts → facesign-signer-5I8juA7p.d.mts} +2 -1
  9. package/dist/facesign-signer-5I8juA7p.d.mts.map +1 -0
  10. package/dist/facesign-signer-z5T312uQ.mjs +2 -0
  11. package/dist/facesign-signer-z5T312uQ.mjs.map +1 -0
  12. package/dist/{index-UFgWkjYP.d.mts → index-Bqz6trCk.d.mts} +273 -187
  13. package/dist/index-Bqz6trCk.d.mts.map +1 -0
  14. package/dist/index.d.mts +2 -2
  15. package/dist/index.mjs +1 -415
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/signature-verification/index.d.mts +3 -5
  18. package/dist/signature-verification/index.d.mts.map +1 -1
  19. package/dist/signature-verification/index.mjs +1 -139
  20. package/dist/signature-verification/index.mjs.map +1 -1
  21. package/dist/xrp/utils.d.mts +165 -57
  22. package/dist/xrp/utils.d.mts.map +1 -1
  23. package/dist/xrp/utils.mjs +1 -104
  24. package/dist/xrp/utils.mjs.map +1 -1
  25. package/dist/xrpl-credentials/index.d.mts +162 -153
  26. package/dist/xrpl-credentials/index.d.mts.map +1 -1
  27. package/dist/xrpl-credentials/index.mjs +1 -223
  28. package/dist/xrpl-credentials/index.mjs.map +1 -1
  29. package/package.json +17 -12
  30. package/src/actions/actions.test.ts +189 -0
  31. package/src/actions/actions.ts +368 -467
  32. package/src/actions/index.ts +38 -0
  33. package/src/create-kgw-authenticated-fetch.test.ts +377 -0
  34. package/src/create-kgw-authenticated-fetch.ts +321 -0
  35. package/src/create-kwil-client.ts +33 -10
  36. package/src/create-kwil-signer.test.ts +80 -0
  37. package/src/create-kwil-signer.ts +31 -5
  38. package/src/facesign/facesign-signer.test.ts +77 -0
  39. package/src/facesign/facesign-signer.ts +50 -2
  40. package/src/index.ts +2 -0
  41. package/src/mm-token/create-mm-token-kwil-signer.test.ts +148 -0
  42. package/src/mm-token/create-mm-token-kwil-signer.ts +166 -0
  43. package/src/near/create-near-wallet-kwil-signer.ts +1 -1
  44. package/src/signature-verification/index.test.ts +18 -0
  45. package/src/signature-verification/index.ts +7 -1
  46. package/src/wait-for-kwil-tx.test.ts +92 -0
  47. package/src/wait-for-kwil-tx.ts +111 -0
  48. package/tsdown.config.ts +1 -0
  49. package/vitest.config.ts +4 -0
  50. package/.turbo/turbo-build.log +0 -47
  51. package/.turbo/turbo-test.log +0 -126
  52. package/.turbo/turbo-typecheck.log +0 -5
  53. package/dist/facesign-signer-ADd4EASX.d.mts.map +0 -1
  54. package/dist/facesign-signer-BY9Nti9F.mjs +0 -244
  55. package/dist/facesign-signer-BY9Nti9F.mjs.map +0 -1
  56. package/dist/index-UFgWkjYP.d.mts.map +0 -1
@@ -1,179 +1,188 @@
1
- import * as _$xrpl from "xrpl";
2
1
  import { TxResponse, Wallet } from "xrpl";
3
-
4
2
  //#region src/xrpl-credentials/accept.d.ts
5
3
  /**
6
- * Payload structure for XRPL CredentialAccept transaction
7
- *
8
- * This type defines the required fields for creating a credential acceptance
9
- * transaction on the XRP Ledger. The CredentialType field is automatically
10
- * encoded as a hex string from the UTF-8 representation of the credential type.
11
- */
12
- type CredentialAcceptPayload = {
13
- /** Transaction type identifier - must be "CredentialAccept" */TransactionType: "CredentialAccept"; /** The issuer's XRPL address who created the Credential object */
14
- Issuer: string; /** The account's XRPL address who is receiving the credential */
15
- Account: string; /** The type of credential being accepted (encoded as hex string) */
4
+ * Payload structure for XRPL CredentialAccept transaction
5
+ *
6
+ * This type defines the required fields for creating a credential acceptance
7
+ * transaction on the XRP Ledger. The CredentialType field is automatically
8
+ * encoded as a hex string from the UTF-8 representation of the credential type.
9
+ */
10
+ export type CredentialAcceptPayload = {
11
+ /** Transaction type identifier - must be "CredentialAccept" */
12
+ TransactionType: "CredentialAccept";
13
+ /** The issuer's XRPL address who created the Credential object */
14
+ Issuer: string;
15
+ /** The account's XRPL address who is receiving the credential */
16
+ Account: string;
17
+ /** The type of credential being accepted (encoded as hex string) */
16
18
  CredentialType: string;
17
19
  };
18
20
  /**
19
- * Creates a credential acceptance payload for XRPL transactions
20
- *
21
- * This function constructs a properly formatted payload for credential acceptance
22
- * transactions. The credential type is automatically encoded from UTF-8 to hex
23
- * format as required by XRPL specifications.
24
- *
25
- * @param issuerAddress - The XRPL address of the credential issuer
26
- * @param accountAddress - The XRPL address of the account accepting the credential
27
- * @param credentialType - The human-readable idOS credential type (e.g., "KYC")
28
- * @returns A properly formatted CredentialAcceptPayload object
29
- *
30
- * @example
31
- * ```typescript
32
- * const payload = OriginalCredentialAcceptPayload(
33
- * "rIssuerAddress123...",
34
- * "rAccountAddress456...",
35
- * "KYC"
36
- * );
37
- * // Result: {
38
- * // TransactionType: "CredentialAccept",
39
- * // Issuer: "rIssuerAddress123...",
40
- * // Account: "rAccountAddress456...",
41
- * // CredentialType: "4B5943" // Hex encoded "KYC"
42
- * // }
43
- * ```
44
- */
45
- declare function OriginalCredentialAcceptPayload(issuerAddress: string, accountAddress: string, credentialType: string): CredentialAcceptPayload;
21
+ * Creates a credential acceptance payload for XRPL transactions
22
+ *
23
+ * This function constructs a properly formatted payload for credential acceptance
24
+ * transactions. The credential type is automatically encoded from UTF-8 to hex
25
+ * format as required by XRPL specifications.
26
+ *
27
+ * @param issuerAddress - The XRPL address of the credential issuer
28
+ * @param accountAddress - The XRPL address of the account accepting the credential
29
+ * @param credentialType - The human-readable idOS credential type (e.g., "KYC")
30
+ * @returns A properly formatted CredentialAcceptPayload object
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const payload = OriginalCredentialAcceptPayload(
35
+ * "rIssuerAddress123...",
36
+ * "rAccountAddress456...",
37
+ * "KYC"
38
+ * );
39
+ * // Result: {
40
+ * // TransactionType: "CredentialAccept",
41
+ * // Issuer: "rIssuerAddress123...",
42
+ * // Account: "rAccountAddress456...",
43
+ * // CredentialType: "4B5943" // Hex encoded "KYC"
44
+ * // }
45
+ * ```
46
+ */
47
+ export declare function OriginalCredentialAcceptPayload(issuerAddress: string, accountAddress: string, credentialType: string): CredentialAcceptPayload;
46
48
  /**
47
- * Creates a copy credential acceptance payload for XRPL transactions
48
- *
49
- * This function constructs a payload for accepting a copy of an existing credential
50
- * with additional metadata including the original issuer and a timelock period.
51
- * The CredentialType field is encoded as a composite string containing:
52
- * - "AG-" prefix (indicating copy credential)
53
- * - Original credential type
54
- * - Original issuer address
55
- * - Timelock period in years
56
- *
57
- * @param copyCredentialIssuerAddress - The XRPL address of the issuer created a XRPL Credential object related to idOS credential copy
58
- * @param accountAddress - The XRPL address of the account accepting the credential copy
59
- * @param originalCredentialIssuerAddress - The XRPL address of the issuer created a XRPL Credential object related to idOS original credential
60
- * @param credentialType - The human-readable idOScredential type (e.g., "KYC")
61
- * @param timelockYears - The number of years for the timelock period (must be non-negative integer)
62
- * @returns A properly formatted CredentialAcceptPayload object for copy credentials
63
- * @throws {Error} When timelockYears is not a non-negative integer
64
- *
65
- * @example
66
- * ```typescript
67
- * const payload = await CopyCredentialAcceptPayload(
68
- * "rCopyIssuerAddress123...",
69
- * "rAccountAddress456...",
70
- * "rOriginalIssuerAddress789...",
71
- * "KYC",
72
- * 2
73
- * );
74
- * // Result: {
75
- * // TransactionType: "CredentialAccept",
76
- * // Issuer: "rCopyIssuerAddress123...",
77
- * // Account: "rAccountAddress456...",
78
- * // CredentialType: "41472D4B59432D..." // Hex encoded "AG-KYC-{originalIssuer}-2Y"
79
- * // }
80
- * ```
81
- */
82
- declare function CopyCredentialAcceptPayload(copyCredentialIssuerAddress: string, accountAddress: string, originalCredentialIssuerAddress: string, credentialType: string, timelockYears: number): Promise<CredentialAcceptPayload>;
49
+ * Creates a copy credential acceptance payload for XRPL transactions
50
+ *
51
+ * This function constructs a payload for accepting a copy of an existing credential
52
+ * with additional metadata including the original issuer and a timelock period.
53
+ * The CredentialType field is encoded as a composite string containing:
54
+ * - "AG-" prefix (indicating copy credential)
55
+ * - Original credential type
56
+ * - Original issuer address
57
+ * - Timelock period in years
58
+ *
59
+ * @param copyCredentialIssuerAddress - The XRPL address of the issuer created a XRPL Credential object related to idOS credential copy
60
+ * @param accountAddress - The XRPL address of the account accepting the credential copy
61
+ * @param originalCredentialIssuerAddress - The XRPL address of the issuer created a XRPL Credential object related to idOS original credential
62
+ * @param credentialType - The human-readable idOScredential type (e.g., "KYC")
63
+ * @param timelockYears - The number of years for the timelock period (must be non-negative integer)
64
+ * @returns A properly formatted CredentialAcceptPayload object for copy credentials
65
+ * @throws {Error} When timelockYears is not a non-negative integer
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const payload = await CopyCredentialAcceptPayload(
70
+ * "rCopyIssuerAddress123...",
71
+ * "rAccountAddress456...",
72
+ * "rOriginalIssuerAddress789...",
73
+ * "KYC",
74
+ * 2
75
+ * );
76
+ * // Result: {
77
+ * // TransactionType: "CredentialAccept",
78
+ * // Issuer: "rCopyIssuerAddress123...",
79
+ * // Account: "rAccountAddress456...",
80
+ * // CredentialType: "41472D4B59432D..." // Hex encoded "AG-KYC-{originalIssuer}-2Y"
81
+ * // }
82
+ * ```
83
+ */
84
+ export declare function CopyCredentialAcceptPayload(copyCredentialIssuerAddress: string, accountAddress: string, originalCredentialIssuerAddress: string, credentialType: string, timelockYears: number): Promise<CredentialAcceptPayload>;
83
85
  //#endregion
84
86
  //#region src/xrpl-credentials/create.d.ts
85
87
  /**
86
- * Parameters for creating an original credential on XRPL
87
- */
88
- type CreateCredentialForOriginalParams = {
89
- /** Unique identifier for the idOS credential, like `741a9caf-ec53-42c7-aed6-519950dcded5` */credId: string; /** Type/category of the credential, like `KYC` */
90
- credType: string; /** XRPL address of the user receiving the credential, like `rPT1Sjq2YGrBMTttX4GZHjKu9dyf6bpAYe` */
88
+ * Parameters for creating an original credential on XRPL
89
+ */
90
+ export type CreateCredentialForOriginalParams = {
91
+ /** Unique identifier for the idOS credential, like `741a9caf-ec53-42c7-aed6-519950dcded5` */
92
+ credId: string;
93
+ /** Type/category of the credential, like `KYC` */
94
+ credType: string;
95
+ /** XRPL address of the user receiving the credential, like `rPT1Sjq2YGrBMTttX4GZHjKu9dyf6bpAYe` */
91
96
  userAddress: string;
92
97
  };
93
98
  /**
94
- * Parameters for creating a time-locked copy credential on XRPL
95
- */
96
- type CreateCredentialForCopyParams = {
97
- /** Unique identifier for the idOS credential */credId: string; /** Type/category of the credential */
98
- credType: string; /** XRPL address of the user receiving the credential */
99
- userAddress: string; /** Number of years to lock the credential (must be non-negative integer) */
100
- timelockYears: number; /** XRPL address of the original credential issuer */
99
+ * Parameters for creating a time-locked copy credential on XRPL
100
+ */
101
+ export type CreateCredentialForCopyParams = {
102
+ /** Unique identifier for the idOS credential */
103
+ credId: string;
104
+ /** Type/category of the credential */
105
+ credType: string;
106
+ /** XRPL address of the user receiving the credential */
107
+ userAddress: string;
108
+ /** Number of years to lock the credential (must be non-negative integer) */
109
+ timelockYears: number;
110
+ /** XRPL address of the original credential issuer */
101
111
  origCredIssuerAddress: string;
102
112
  };
103
113
  /**
104
- * Service class for creating credentials on the XRPL blockchain
105
- *
106
- * This service provides methods to create both original and copy credentials
107
- * on the XRPL. It handles connection management, transaction submission,
108
- * and proper encoding of credential data according to XRPL specifications.
109
- *
110
- * @example
111
- * ```typescript
112
- * const wallet = Wallet.fromSeed("s...");
113
- * const xrplService = await XrplCredentialsCreate.init("wss://s.devnet.rippletest.net:51233", wallet);
114
- *
115
- * // Create original credential
116
- * await xrplService.createCredentialForOriginal({
117
- * credId: "741a9caf-ec53-42c7-aed6-519950dcded5",
118
- * credType: "KYC",
119
- * userAddress: "rPT1Sjq2YGrBMTttX4GZHjKu9dyf6bpAYe"
120
- * });
121
- * ```
122
- */
123
- declare class XrplCredentialsCreate {
114
+ * Service class for creating credentials on the XRPL blockchain
115
+ *
116
+ * This service provides methods to create both original and copy credentials
117
+ * on the XRPL. It handles connection management, transaction submission,
118
+ * and proper encoding of credential data according to XRPL specifications.
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const wallet = Wallet.fromSeed("s...");
123
+ * const xrplService = await XrplCredentialsCreate.init("wss://s.devnet.rippletest.net:51233", wallet);
124
+ *
125
+ * // Create original credential
126
+ * await xrplService.createCredentialForOriginal({
127
+ * credId: "741a9caf-ec53-42c7-aed6-519950dcded5",
128
+ * credType: "KYC",
129
+ * userAddress: "rPT1Sjq2YGrBMTttX4GZHjKu9dyf6bpAYe"
130
+ * });
131
+ * ```
132
+ */
133
+ export declare class XrplCredentialsCreate {
124
134
  #private;
125
- constructor(nodeUrl: string, wallet: Wallet, xrpl: typeof _$xrpl);
135
+ constructor(nodeUrl: string, wallet: Wallet, xrpl: typeof import("xrpl"));
126
136
  /**
127
- * Creates a new XRPL credentials service instance.
128
- *
129
- * @param nodeUrl - The WebSocket URL of the XRPL node to connect to
130
- * @param wallet - The XRPL wallet to use for signing transactions
131
- */
137
+ * Creates a new XRPL credentials service instance.
138
+ *
139
+ * @param nodeUrl - The WebSocket URL of the XRPL node to connect to
140
+ * @param wallet - The XRPL wallet to use for signing transactions
141
+ */
132
142
  static init(nodeUrl: string, wallet: Wallet): Promise<XrplCredentialsCreate>;
133
143
  /**
134
- * Creates a credential on the XRPL that reflects an idOS original credential.
135
- *
136
- * This method creates a new credential with the specified type and assigns it to the given user.
137
- * The credential type is encoded as a hex string, and the credential ID is encoded as a hex URI.
138
- *
139
- * @param params - Parameters for creating the original credential
140
- * @returns Promise resolving to the XRPL transaction result
141
- *
142
- * @example
143
- * ```typescript
144
- * await xrplService.createCredentialForOriginal({
145
- * credId: "741a9caf-ec53-42c7-aed6-519950dcded5",
146
- * credType: "KYC",
147
- * userAddress: "rPT1Sjq2YGrBMTttX4GZHjKu9dyf6bpAYe"
148
- * });
149
- * ```
150
- */
144
+ * Creates a credential on the XRPL that reflects an idOS original credential.
145
+ *
146
+ * This method creates a new credential with the specified type and assigns it to the given user.
147
+ * The credential type is encoded as a hex string, and the credential ID is encoded as a hex URI.
148
+ *
149
+ * @param params - Parameters for creating the original credential
150
+ * @returns Promise resolving to the XRPL transaction result
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * await xrplService.createCredentialForOriginal({
155
+ * credId: "741a9caf-ec53-42c7-aed6-519950dcded5",
156
+ * credType: "KYC",
157
+ * userAddress: "rPT1Sjq2YGrBMTttX4GZHjKu9dyf6bpAYe"
158
+ * });
159
+ * ```
160
+ */
151
161
  createCredentialForOriginal(params: CreateCredentialForOriginalParams): Promise<TxResponse>;
152
162
  /**
153
- * Creates a time-locked credential copy on the XRPL.
154
- *
155
- * This method creates a Credential object in XRPL that reflects an idOS credential copy.
156
- * The credential type includes metadata about the original issuer and time-lock duration.
157
- * The composite credential type follows the format: "AG-{type}-{originalIssuer}-{timelock}Y"
158
- *
159
- * @param params - Parameters for creating the time-locked credential copy
160
- * @returns Promise resolving to the XRPL transaction result
161
- *
162
- * @throws {Error} When timelockYears is not a non-negative integer
163
- *
164
- * @example
165
- * ```typescript
166
- * const result = await xrplService.createCredentialForCopy({
167
- * credId: "741a9caf-ec53-42c7-aed6-519950dcded5",
168
- * credType: "KYC",
169
- * userAddress: "rPT1Sjq2YGrBMTttX4GZHjKu9dyf6bpAYe",
170
- * timelockYears: 5,
171
- * origCredIssuerAddress: "rU9C67bZ3ZvjXaJYwYqMqjMq1o4ZbwK3YN"
172
- * });
173
- * ```
174
- */
163
+ * Creates a time-locked credential copy on the XRPL.
164
+ *
165
+ * This method creates a Credential object in XRPL that reflects an idOS credential copy.
166
+ * The credential type includes metadata about the original issuer and time-lock duration.
167
+ * The composite credential type follows the format: "AG-{type}-{originalIssuer}-{timelock}Y"
168
+ *
169
+ * @param params - Parameters for creating the time-locked credential copy
170
+ * @returns Promise resolving to the XRPL transaction result
171
+ *
172
+ * @throws {Error} When timelockYears is not a non-negative integer
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * const result = await xrplService.createCredentialForCopy({
177
+ * credId: "741a9caf-ec53-42c7-aed6-519950dcded5",
178
+ * credType: "KYC",
179
+ * userAddress: "rPT1Sjq2YGrBMTttX4GZHjKu9dyf6bpAYe",
180
+ * timelockYears: 5,
181
+ * origCredIssuerAddress: "rU9C67bZ3ZvjXaJYwYqMqjMq1o4ZbwK3YN"
182
+ * });
183
+ * ```
184
+ */
175
185
  createCredentialForCopy(params: CreateCredentialForCopyParams): Promise<TxResponse>;
176
186
  }
177
187
  //#endregion
178
- export { CopyCredentialAcceptPayload, CreateCredentialForCopyParams, CreateCredentialForOriginalParams, CredentialAcceptPayload, OriginalCredentialAcceptPayload, XrplCredentialsCreate };
179
188
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/xrpl-credentials/accept.ts","../../src/xrpl-credentials/create.ts"],"mappings":";;;;;;;;AASA;;;KAAY,uBAAA;iEAEV,eAAA;EAEA,MAAA;EAEA,OAAA,UAgCF;EA9BE,cAAA;AAAA;;;;;;;;AAmFF;;;;;;;;;;;;;;;;AC7FA;;;;iBDwCgB,+BAAA,CACd,aAAA,UACA,cAAA,UACA,cAAA,WACC,uBAAA;;;;;AChCH;;;;;;;;;;;AAiCA;;;;;;;;;;;;;;;;;;;;;iBDgDsB,2BAAA,CACpB,2BAAA,UACA,cAAA,UACA,+BAAA,UACA,cAAA,UACA,aAAA,WACC,OAAA,CAAQ,uBAAA;;;;;;KCnGC,iCAAA;EDEA,6FCAV,MAAA,UDAU;ECEV,QAAA;EAEA,WAAA;AAAA;;;ADkCF;KC5BY,6BAAA;kDAEV,MAAA;EAEA,QAAA;EAEA,WAAA;EAEA,aAAA,UDyEF;ECvEE,qBAAA;AAAA;;;;;;;;;;;;;;AAtBF;;;;;;;cA6Ca,qBAAA;EAAA;EAKX,WAAA,CAAY,OAAA,UAAiB,MAAA,EAAQ,MAAA,EAAQ,IAAA,SAAR,MAAA;EAtC3B;;;;;;EAAA,OAkDG,IAAA,CAAK,OAAA,UAAiB,MAAA,EAAQ,MAAA,GAAS,OAAA,CAAQ,qBAAA;;;;AAjB9D;;;;;;;;;;;;;;;EAiDE,2BAAA,CACE,MAAA,EAAQ,iCAAA,GACP,OAAA,CAAQ,UAAA;;;;;;;;;;;;;;;;;;;;;;;;EAmDX,uBAAA,CAA8B,MAAA,EAAQ,6BAAA,GAAgC,OAAA,CAAQ,UAAA;AAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/xrpl-credentials/accept.ts","../../src/xrpl-credentials/create.ts"],"mappings":";;;;;;;;;YASY;;EAEV;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8Bc,gCACd,uBACA,wBACA,yBACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAiDmB,4BACpB,qCACA,wBACA,yCACA,wBACA,wBACC,QAAQ;;;;;;YCnGC;;EAEV;;EAEA;;EAEA;;;;;YAMU;;EAEV;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;;;;;;;;;;qBAuBW;;EAKX,YAAY,iBAAiB,QAAQ,QAAQ;;;;;;;SAYhC,KAAK,iBAAiB,QAAQ,SAAS,QAAQ;;;;;;;;;;;;;;;;;;;EAgC5D,4BACE,QAAQ,oCACP,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;EAmDX,wBAA8B,QAAQ,gCAAgC,QAAQ"}
@@ -1,224 +1,2 @@
1
- import { hexEncode, utf8Encode } from "@idos-network/utils/codecs";
2
- //#region src/xrpl-credentials/accept.ts
3
- /**
4
- * Creates a credential acceptance payload for XRPL transactions
5
- *
6
- * This function constructs a properly formatted payload for credential acceptance
7
- * transactions. The credential type is automatically encoded from UTF-8 to hex
8
- * format as required by XRPL specifications.
9
- *
10
- * @param issuerAddress - The XRPL address of the credential issuer
11
- * @param accountAddress - The XRPL address of the account accepting the credential
12
- * @param credentialType - The human-readable idOS credential type (e.g., "KYC")
13
- * @returns A properly formatted CredentialAcceptPayload object
14
- *
15
- * @example
16
- * ```typescript
17
- * const payload = OriginalCredentialAcceptPayload(
18
- * "rIssuerAddress123...",
19
- * "rAccountAddress456...",
20
- * "KYC"
21
- * );
22
- * // Result: {
23
- * // TransactionType: "CredentialAccept",
24
- * // Issuer: "rIssuerAddress123...",
25
- * // Account: "rAccountAddress456...",
26
- * // CredentialType: "4B5943" // Hex encoded "KYC"
27
- * // }
28
- * ```
29
- */
30
- function OriginalCredentialAcceptPayload(issuerAddress, accountAddress, credentialType) {
31
- return {
32
- TransactionType: "CredentialAccept",
33
- Issuer: issuerAddress,
34
- Account: accountAddress,
35
- CredentialType: hexEncode(utf8Encode(credentialType))
36
- };
37
- }
38
- /**
39
- * Creates a copy credential acceptance payload for XRPL transactions
40
- *
41
- * This function constructs a payload for accepting a copy of an existing credential
42
- * with additional metadata including the original issuer and a timelock period.
43
- * The CredentialType field is encoded as a composite string containing:
44
- * - "AG-" prefix (indicating copy credential)
45
- * - Original credential type
46
- * - Original issuer address
47
- * - Timelock period in years
48
- *
49
- * @param copyCredentialIssuerAddress - The XRPL address of the issuer created a XRPL Credential object related to idOS credential copy
50
- * @param accountAddress - The XRPL address of the account accepting the credential copy
51
- * @param originalCredentialIssuerAddress - The XRPL address of the issuer created a XRPL Credential object related to idOS original credential
52
- * @param credentialType - The human-readable idOScredential type (e.g., "KYC")
53
- * @param timelockYears - The number of years for the timelock period (must be non-negative integer)
54
- * @returns A properly formatted CredentialAcceptPayload object for copy credentials
55
- * @throws {Error} When timelockYears is not a non-negative integer
56
- *
57
- * @example
58
- * ```typescript
59
- * const payload = await CopyCredentialAcceptPayload(
60
- * "rCopyIssuerAddress123...",
61
- * "rAccountAddress456...",
62
- * "rOriginalIssuerAddress789...",
63
- * "KYC",
64
- * 2
65
- * );
66
- * // Result: {
67
- * // TransactionType: "CredentialAccept",
68
- * // Issuer: "rCopyIssuerAddress123...",
69
- * // Account: "rAccountAddress456...",
70
- * // CredentialType: "41472D4B59432D..." // Hex encoded "AG-KYC-{originalIssuer}-2Y"
71
- * // }
72
- * ```
73
- */
74
- async function CopyCredentialAcceptPayload(copyCredentialIssuerAddress, accountAddress, originalCredentialIssuerAddress, credentialType, timelockYears) {
75
- if (!Number.isInteger(timelockYears) || timelockYears < 0) throw new Error("timelockYears must be a non-negative integer");
76
- let decodeAccountID;
77
- try {
78
- ({decodeAccountID} = await import("xrpl"));
79
- } catch {
80
- throw new Error("Missing optional peer dependency \"xrpl\". Install it to use CopyCredentialAcceptPayload.");
81
- }
82
- return {
83
- TransactionType: "CredentialAccept",
84
- Issuer: copyCredentialIssuerAddress,
85
- Account: accountAddress,
86
- CredentialType: hexEncode(Buffer.concat([
87
- utf8Encode("AG"),
88
- utf8Encode("-"),
89
- utf8Encode(credentialType),
90
- utf8Encode("-"),
91
- decodeAccountID(originalCredentialIssuerAddress),
92
- utf8Encode("-"),
93
- utf8Encode(`${timelockYears}Y`)
94
- ]))
95
- };
96
- }
97
- //#endregion
98
- //#region src/xrpl-credentials/create.ts
99
- /**
100
- * Service class for creating credentials on the XRPL blockchain
101
- *
102
- * This service provides methods to create both original and copy credentials
103
- * on the XRPL. It handles connection management, transaction submission,
104
- * and proper encoding of credential data according to XRPL specifications.
105
- *
106
- * @example
107
- * ```typescript
108
- * const wallet = Wallet.fromSeed("s...");
109
- * const xrplService = await XrplCredentialsCreate.init("wss://s.devnet.rippletest.net:51233", wallet);
110
- *
111
- * // Create original credential
112
- * await xrplService.createCredentialForOriginal({
113
- * credId: "741a9caf-ec53-42c7-aed6-519950dcded5",
114
- * credType: "KYC",
115
- * userAddress: "rPT1Sjq2YGrBMTttX4GZHjKu9dyf6bpAYe"
116
- * });
117
- * ```
118
- */
119
- var XrplCredentialsCreate = class XrplCredentialsCreate {
120
- #client;
121
- #wallet;
122
- #xrpl;
123
- constructor(nodeUrl, wallet, xrpl) {
124
- this.#xrpl = xrpl;
125
- this.#wallet = wallet;
126
- this.#client = new this.#xrpl.Client(nodeUrl);
127
- }
128
- /**
129
- * Creates a new XRPL credentials service instance.
130
- *
131
- * @param nodeUrl - The WebSocket URL of the XRPL node to connect to
132
- * @param wallet - The XRPL wallet to use for signing transactions
133
- */
134
- static async init(nodeUrl, wallet) {
135
- let xrpl;
136
- try {
137
- xrpl = await import("xrpl");
138
- } catch {
139
- throw new Error("Missing optional peer dependency 'xrpl'. Install it to use XrplCredentialsCreate.");
140
- }
141
- return new XrplCredentialsCreate(nodeUrl, wallet, xrpl);
142
- }
143
- /**
144
- * Creates a credential on the XRPL that reflects an idOS original credential.
145
- *
146
- * This method creates a new credential with the specified type and assigns it to the given user.
147
- * The credential type is encoded as a hex string, and the credential ID is encoded as a hex URI.
148
- *
149
- * @param params - Parameters for creating the original credential
150
- * @returns Promise resolving to the XRPL transaction result
151
- *
152
- * @example
153
- * ```typescript
154
- * await xrplService.createCredentialForOriginal({
155
- * credId: "741a9caf-ec53-42c7-aed6-519950dcded5",
156
- * credType: "KYC",
157
- * userAddress: "rPT1Sjq2YGrBMTttX4GZHjKu9dyf6bpAYe"
158
- * });
159
- * ```
160
- */
161
- async createCredentialForOriginal(params) {
162
- const { credId, credType, userAddress } = params;
163
- await this.#client.connect();
164
- const res = await this.#client.submitAndWait({
165
- TransactionType: "CredentialCreate",
166
- Account: this.#wallet.address,
167
- Subject: userAddress,
168
- CredentialType: hexEncode(utf8Encode(credType)),
169
- URI: hexEncode(utf8Encode(credId))
170
- }, { wallet: this.#wallet });
171
- await this.#client.disconnect();
172
- return res;
173
- }
174
- /**
175
- * Creates a time-locked credential copy on the XRPL.
176
- *
177
- * This method creates a Credential object in XRPL that reflects an idOS credential copy.
178
- * The credential type includes metadata about the original issuer and time-lock duration.
179
- * The composite credential type follows the format: "AG-{type}-{originalIssuer}-{timelock}Y"
180
- *
181
- * @param params - Parameters for creating the time-locked credential copy
182
- * @returns Promise resolving to the XRPL transaction result
183
- *
184
- * @throws {Error} When timelockYears is not a non-negative integer
185
- *
186
- * @example
187
- * ```typescript
188
- * const result = await xrplService.createCredentialForCopy({
189
- * credId: "741a9caf-ec53-42c7-aed6-519950dcded5",
190
- * credType: "KYC",
191
- * userAddress: "rPT1Sjq2YGrBMTttX4GZHjKu9dyf6bpAYe",
192
- * timelockYears: 5,
193
- * origCredIssuerAddress: "rU9C67bZ3ZvjXaJYwYqMqjMq1o4ZbwK3YN"
194
- * });
195
- * ```
196
- */
197
- async createCredentialForCopy(params) {
198
- const { credId, credType, userAddress, timelockYears, origCredIssuerAddress } = params;
199
- if (!Number.isInteger(timelockYears) || timelockYears < 0) throw new Error("timelockYears must be a non-negative integer");
200
- await this.#client.connect();
201
- const type = Buffer.concat([
202
- utf8Encode("AG"),
203
- utf8Encode("-"),
204
- utf8Encode(credType),
205
- utf8Encode("-"),
206
- this.#xrpl.decodeAccountID(origCredIssuerAddress),
207
- utf8Encode("-"),
208
- utf8Encode(`${timelockYears}Y`)
209
- ]);
210
- const res = await this.#client.submitAndWait({
211
- TransactionType: "CredentialCreate",
212
- Account: this.#wallet.address,
213
- Subject: userAddress,
214
- CredentialType: hexEncode(type),
215
- URI: hexEncode(utf8Encode(credId))
216
- }, { wallet: this.#wallet });
217
- await this.#client.disconnect();
218
- return res;
219
- }
220
- };
221
- //#endregion
222
- export { CopyCredentialAcceptPayload, OriginalCredentialAcceptPayload, XrplCredentialsCreate };
223
-
1
+ import{hexEncode as e,utf8Encode as t}from"@idos-network/utils/codecs";function n(n,r,i){return{TransactionType:`CredentialAccept`,Issuer:n,Account:r,CredentialType:e(t(i))}}async function r(n,r,i,a,o){if(!Number.isInteger(o)||o<0)throw Error(`timelockYears must be a non-negative integer`);let s;try{({decodeAccountID:s}=await import(`xrpl`))}catch{throw Error(`Missing optional peer dependency "xrpl". Install it to use CopyCredentialAcceptPayload.`)}let c=Buffer.concat([t(`AG`),t(`-`),t(a),t(`-`),s(i),t(`-`),t(`${o}Y`)]);return{TransactionType:`CredentialAccept`,Issuer:n,Account:r,CredentialType:e(c)}}var i=class n{#e;#t;#n;constructor(e,t,n){this.#n=n,this.#t=t,this.#e=new this.#n.Client(e)}static async init(e,t){let r;try{r=await import(`xrpl`)}catch{throw Error(`Missing optional peer dependency 'xrpl'. Install it to use XrplCredentialsCreate.`)}return new n(e,t,r)}async createCredentialForOriginal(n){let{credId:r,credType:i,userAddress:a}=n;await this.#e.connect();let o=await this.#e.submitAndWait({TransactionType:`CredentialCreate`,Account:this.#t.address,Subject:a,CredentialType:e(t(i)),URI:e(t(r))},{wallet:this.#t});return await this.#e.disconnect(),o}async createCredentialForCopy(n){let{credId:r,credType:i,userAddress:a,timelockYears:o,origCredIssuerAddress:s}=n;if(!Number.isInteger(o)||o<0)throw Error(`timelockYears must be a non-negative integer`);await this.#e.connect();let c=Buffer.concat([t(`AG`),t(`-`),t(i),t(`-`),this.#n.decodeAccountID(s),t(`-`),t(`${o}Y`)]),l=await this.#e.submitAndWait({TransactionType:`CredentialCreate`,Account:this.#t.address,Subject:a,CredentialType:e(c),URI:e(t(r))},{wallet:this.#t});return await this.#e.disconnect(),l}};export{r as CopyCredentialAcceptPayload,n as OriginalCredentialAcceptPayload,i as XrplCredentialsCreate};
224
2
  //# sourceMappingURL=index.mjs.map