@andamio/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 +190 -0
- package/README.md +83 -0
- package/dist/constants/index.d.mts +102 -0
- package/dist/constants/index.d.ts +102 -0
- package/dist/constants/index.js +123 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/index.mjs +108 -0
- package/dist/constants/index.mjs.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +432 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +381 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils/hashing/index.d.mts +276 -0
- package/dist/utils/hashing/index.d.ts +276 -0
- package/dist/utils/hashing/index.js +313 -0
- package/dist/utils/hashing/index.js.map +1 -0
- package/dist/utils/hashing/index.mjs +276 -0
- package/dist/utils/hashing/index.mjs.map +1 -0
- package/package.json +58 -0
- package/src/constants/cardano.ts +90 -0
- package/src/constants/index.ts +31 -0
- package/src/constants/policies.ts +122 -0
- package/src/index.ts +14 -0
- package/src/utils/hashing/commitment-hash.ts +223 -0
- package/src/utils/hashing/index.ts +43 -0
- package/src/utils/hashing/slt-hash.ts +193 -0
- package/src/utils/hashing/task-hash.ts +308 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2024 Andamio Platform
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# @andamio/core
|
|
2
|
+
|
|
3
|
+
Core utilities and constants for the Andamio protocol. Zero React dependencies - can be used in any JavaScript/TypeScript environment.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @andamio/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Hashing Utilities
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import {
|
|
17
|
+
computeSltHash,
|
|
18
|
+
computeTaskHash,
|
|
19
|
+
computeCommitmentHash,
|
|
20
|
+
} from "@andamio/core/hashing";
|
|
21
|
+
|
|
22
|
+
// SLT (Student Learning Target) hashing
|
|
23
|
+
const sltHash = computeSltHash("course-123", "module-456", 1);
|
|
24
|
+
|
|
25
|
+
// Task hashing (for project tasks)
|
|
26
|
+
const taskHash = computeTaskHash({
|
|
27
|
+
projectTokenPolicyId: "abc123...",
|
|
28
|
+
taskCreatorTokenName: "creator-token",
|
|
29
|
+
taskIndex: 0,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Commitment/Assignment info hashing
|
|
33
|
+
const commitmentHash = computeCommitmentHash({
|
|
34
|
+
type: "doc",
|
|
35
|
+
content: [{ type: "paragraph", content: [{ type: "text", text: "Evidence" }] }],
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Constants
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import {
|
|
43
|
+
POLICY_IDS,
|
|
44
|
+
getTxExplorerUrl,
|
|
45
|
+
getAddressExplorerUrl,
|
|
46
|
+
} from "@andamio/core/constants";
|
|
47
|
+
|
|
48
|
+
// Get policy IDs for a network
|
|
49
|
+
const policyIds = POLICY_IDS.preprod;
|
|
50
|
+
console.log(policyIds.accessToken);
|
|
51
|
+
|
|
52
|
+
// Generate explorer URLs
|
|
53
|
+
const txUrl = getTxExplorerUrl("preprod", "abc123...");
|
|
54
|
+
const addrUrl = getAddressExplorerUrl("preprod", "addr_test1...");
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## API Reference
|
|
58
|
+
|
|
59
|
+
### Hashing Functions
|
|
60
|
+
|
|
61
|
+
| Function | Description |
|
|
62
|
+
|----------|-------------|
|
|
63
|
+
| `computeSltHash(courseId, moduleCode, moduleIndex)` | Compute SLT token name hash |
|
|
64
|
+
| `computeSltHashDefinite(courseId, moduleCode, moduleIndex)` | Same as above, always returns string (throws on error) |
|
|
65
|
+
| `verifySltHash(hash, courseId, moduleCode, moduleIndex)` | Verify an SLT hash matches inputs |
|
|
66
|
+
| `computeTaskHash(taskData)` | Compute project task hash |
|
|
67
|
+
| `verifyTaskHash(hash, taskData)` | Verify a task hash matches inputs |
|
|
68
|
+
| `computeCommitmentHash(evidence)` | Compute hash of Tiptap JSON evidence |
|
|
69
|
+
| `verifyCommitmentHash(hash, evidence)` | Verify a commitment hash |
|
|
70
|
+
|
|
71
|
+
### Constants
|
|
72
|
+
|
|
73
|
+
| Export | Description |
|
|
74
|
+
|--------|-------------|
|
|
75
|
+
| `POLICY_IDS` | Policy IDs by network (preprod, preview, mainnet) |
|
|
76
|
+
| `EXPLORER_URLS` | Block explorer base URLs |
|
|
77
|
+
| `getTxExplorerUrl(network, txHash)` | Get transaction explorer URL |
|
|
78
|
+
| `getAddressExplorerUrl(network, address)` | Get address explorer URL |
|
|
79
|
+
| `getAssetExplorerUrl(network, policyId, assetName)` | Get asset explorer URL |
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
Apache-2.0
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cardano Network Constants
|
|
3
|
+
*
|
|
4
|
+
* Network identifiers, explorer URLs, and other Cardano-specific constants.
|
|
5
|
+
*
|
|
6
|
+
* @module @andamio/core/constants
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Supported Cardano networks
|
|
10
|
+
*/
|
|
11
|
+
type CardanoNetwork = "mainnet" | "preprod" | "preview";
|
|
12
|
+
/**
|
|
13
|
+
* Block explorer URLs by network
|
|
14
|
+
*/
|
|
15
|
+
declare const EXPLORER_URLS: Record<CardanoNetwork, string>;
|
|
16
|
+
/**
|
|
17
|
+
* CExplorer URLs by network (alternative explorer)
|
|
18
|
+
*/
|
|
19
|
+
declare const CEXPLORER_URLS: Record<CardanoNetwork, string>;
|
|
20
|
+
/**
|
|
21
|
+
* Network magic numbers for Cardano networks
|
|
22
|
+
*/
|
|
23
|
+
declare const NETWORK_MAGIC: Record<CardanoNetwork, number>;
|
|
24
|
+
/**
|
|
25
|
+
* Bech32 address prefixes by network
|
|
26
|
+
*/
|
|
27
|
+
declare const ADDRESS_PREFIX: Record<CardanoNetwork, string>;
|
|
28
|
+
/**
|
|
29
|
+
* Get explorer URL for a transaction
|
|
30
|
+
*/
|
|
31
|
+
declare function getTxExplorerUrl(network: CardanoNetwork, txHash: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Get explorer URL for an address
|
|
34
|
+
*/
|
|
35
|
+
declare function getAddressExplorerUrl(network: CardanoNetwork, address: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Get explorer URL for a token/asset
|
|
38
|
+
*/
|
|
39
|
+
declare function getAssetExplorerUrl(network: CardanoNetwork, policyId: string, assetName?: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Get explorer URL for a policy
|
|
42
|
+
*/
|
|
43
|
+
declare function getPolicyExplorerUrl(network: CardanoNetwork, policyId: string): string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Andamio Policy IDs
|
|
47
|
+
*
|
|
48
|
+
* Policy IDs for Andamio protocol tokens by network.
|
|
49
|
+
* These are used to identify access tokens, course tokens, and other
|
|
50
|
+
* protocol-specific assets on-chain.
|
|
51
|
+
*
|
|
52
|
+
* @module @andamio/core/constants
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Policy ID configuration for a network
|
|
57
|
+
*/
|
|
58
|
+
interface NetworkPolicies {
|
|
59
|
+
/** Access token policy ID - identifies user access tokens */
|
|
60
|
+
accessToken: string;
|
|
61
|
+
/** Course token policy ID - identifies course tokens */
|
|
62
|
+
courseToken: string;
|
|
63
|
+
/** Module token policy ID - identifies module tokens */
|
|
64
|
+
moduleToken: string;
|
|
65
|
+
/** Assignment token policy ID - identifies assignment tokens */
|
|
66
|
+
assignmentToken: string;
|
|
67
|
+
/** Project token policy ID - identifies project tokens */
|
|
68
|
+
projectToken: string;
|
|
69
|
+
/** Task token policy ID - identifies task tokens */
|
|
70
|
+
taskToken: string;
|
|
71
|
+
/** Contributor token policy ID - identifies contributor tokens */
|
|
72
|
+
contributorToken: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Policy IDs by network
|
|
76
|
+
*
|
|
77
|
+
* Note: These should be loaded from environment variables in production.
|
|
78
|
+
* The values here are examples/defaults for the preprod network.
|
|
79
|
+
*/
|
|
80
|
+
declare const POLICY_IDS: Record<CardanoNetwork, NetworkPolicies>;
|
|
81
|
+
/**
|
|
82
|
+
* Get the access token policy ID for a network
|
|
83
|
+
*/
|
|
84
|
+
declare function getAccessTokenPolicyId(network: CardanoNetwork): string;
|
|
85
|
+
/**
|
|
86
|
+
* Validate a policy ID format (56 hex characters)
|
|
87
|
+
*/
|
|
88
|
+
declare function isValidPolicyId(policyId: string): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Validate an asset name format (hex string, max 64 chars / 32 bytes)
|
|
91
|
+
*/
|
|
92
|
+
declare function isValidAssetName(assetName: string): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Convert a UTF-8 string to hex asset name
|
|
95
|
+
*/
|
|
96
|
+
declare function stringToAssetName(str: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* Convert a hex asset name to UTF-8 string
|
|
99
|
+
*/
|
|
100
|
+
declare function assetNameToString(hex: string): string;
|
|
101
|
+
|
|
102
|
+
export { ADDRESS_PREFIX, CEXPLORER_URLS, type CardanoNetwork, EXPLORER_URLS, NETWORK_MAGIC, type NetworkPolicies, POLICY_IDS, assetNameToString, getAccessTokenPolicyId, getAddressExplorerUrl, getAssetExplorerUrl, getPolicyExplorerUrl, getTxExplorerUrl, isValidAssetName, isValidPolicyId, stringToAssetName };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cardano Network Constants
|
|
3
|
+
*
|
|
4
|
+
* Network identifiers, explorer URLs, and other Cardano-specific constants.
|
|
5
|
+
*
|
|
6
|
+
* @module @andamio/core/constants
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Supported Cardano networks
|
|
10
|
+
*/
|
|
11
|
+
type CardanoNetwork = "mainnet" | "preprod" | "preview";
|
|
12
|
+
/**
|
|
13
|
+
* Block explorer URLs by network
|
|
14
|
+
*/
|
|
15
|
+
declare const EXPLORER_URLS: Record<CardanoNetwork, string>;
|
|
16
|
+
/**
|
|
17
|
+
* CExplorer URLs by network (alternative explorer)
|
|
18
|
+
*/
|
|
19
|
+
declare const CEXPLORER_URLS: Record<CardanoNetwork, string>;
|
|
20
|
+
/**
|
|
21
|
+
* Network magic numbers for Cardano networks
|
|
22
|
+
*/
|
|
23
|
+
declare const NETWORK_MAGIC: Record<CardanoNetwork, number>;
|
|
24
|
+
/**
|
|
25
|
+
* Bech32 address prefixes by network
|
|
26
|
+
*/
|
|
27
|
+
declare const ADDRESS_PREFIX: Record<CardanoNetwork, string>;
|
|
28
|
+
/**
|
|
29
|
+
* Get explorer URL for a transaction
|
|
30
|
+
*/
|
|
31
|
+
declare function getTxExplorerUrl(network: CardanoNetwork, txHash: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Get explorer URL for an address
|
|
34
|
+
*/
|
|
35
|
+
declare function getAddressExplorerUrl(network: CardanoNetwork, address: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Get explorer URL for a token/asset
|
|
38
|
+
*/
|
|
39
|
+
declare function getAssetExplorerUrl(network: CardanoNetwork, policyId: string, assetName?: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Get explorer URL for a policy
|
|
42
|
+
*/
|
|
43
|
+
declare function getPolicyExplorerUrl(network: CardanoNetwork, policyId: string): string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Andamio Policy IDs
|
|
47
|
+
*
|
|
48
|
+
* Policy IDs for Andamio protocol tokens by network.
|
|
49
|
+
* These are used to identify access tokens, course tokens, and other
|
|
50
|
+
* protocol-specific assets on-chain.
|
|
51
|
+
*
|
|
52
|
+
* @module @andamio/core/constants
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Policy ID configuration for a network
|
|
57
|
+
*/
|
|
58
|
+
interface NetworkPolicies {
|
|
59
|
+
/** Access token policy ID - identifies user access tokens */
|
|
60
|
+
accessToken: string;
|
|
61
|
+
/** Course token policy ID - identifies course tokens */
|
|
62
|
+
courseToken: string;
|
|
63
|
+
/** Module token policy ID - identifies module tokens */
|
|
64
|
+
moduleToken: string;
|
|
65
|
+
/** Assignment token policy ID - identifies assignment tokens */
|
|
66
|
+
assignmentToken: string;
|
|
67
|
+
/** Project token policy ID - identifies project tokens */
|
|
68
|
+
projectToken: string;
|
|
69
|
+
/** Task token policy ID - identifies task tokens */
|
|
70
|
+
taskToken: string;
|
|
71
|
+
/** Contributor token policy ID - identifies contributor tokens */
|
|
72
|
+
contributorToken: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Policy IDs by network
|
|
76
|
+
*
|
|
77
|
+
* Note: These should be loaded from environment variables in production.
|
|
78
|
+
* The values here are examples/defaults for the preprod network.
|
|
79
|
+
*/
|
|
80
|
+
declare const POLICY_IDS: Record<CardanoNetwork, NetworkPolicies>;
|
|
81
|
+
/**
|
|
82
|
+
* Get the access token policy ID for a network
|
|
83
|
+
*/
|
|
84
|
+
declare function getAccessTokenPolicyId(network: CardanoNetwork): string;
|
|
85
|
+
/**
|
|
86
|
+
* Validate a policy ID format (56 hex characters)
|
|
87
|
+
*/
|
|
88
|
+
declare function isValidPolicyId(policyId: string): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Validate an asset name format (hex string, max 64 chars / 32 bytes)
|
|
91
|
+
*/
|
|
92
|
+
declare function isValidAssetName(assetName: string): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Convert a UTF-8 string to hex asset name
|
|
95
|
+
*/
|
|
96
|
+
declare function stringToAssetName(str: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* Convert a hex asset name to UTF-8 string
|
|
99
|
+
*/
|
|
100
|
+
declare function assetNameToString(hex: string): string;
|
|
101
|
+
|
|
102
|
+
export { ADDRESS_PREFIX, CEXPLORER_URLS, type CardanoNetwork, EXPLORER_URLS, NETWORK_MAGIC, type NetworkPolicies, POLICY_IDS, assetNameToString, getAccessTokenPolicyId, getAddressExplorerUrl, getAssetExplorerUrl, getPolicyExplorerUrl, getTxExplorerUrl, isValidAssetName, isValidPolicyId, stringToAssetName };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/constants/cardano.ts
|
|
4
|
+
var EXPLORER_URLS = {
|
|
5
|
+
mainnet: "https://cardanoscan.io",
|
|
6
|
+
preprod: "https://preprod.cardanoscan.io",
|
|
7
|
+
preview: "https://preview.cardanoscan.io"
|
|
8
|
+
};
|
|
9
|
+
var CEXPLORER_URLS = {
|
|
10
|
+
mainnet: "https://cexplorer.io",
|
|
11
|
+
preprod: "https://preprod.cexplorer.io",
|
|
12
|
+
preview: "https://preview.cexplorer.io"
|
|
13
|
+
};
|
|
14
|
+
var NETWORK_MAGIC = {
|
|
15
|
+
mainnet: 764824073,
|
|
16
|
+
preprod: 1,
|
|
17
|
+
preview: 2
|
|
18
|
+
};
|
|
19
|
+
var ADDRESS_PREFIX = {
|
|
20
|
+
mainnet: "addr",
|
|
21
|
+
preprod: "addr_test",
|
|
22
|
+
preview: "addr_test"
|
|
23
|
+
};
|
|
24
|
+
function getTxExplorerUrl(network, txHash) {
|
|
25
|
+
return `${EXPLORER_URLS[network]}/transaction/${txHash}`;
|
|
26
|
+
}
|
|
27
|
+
function getAddressExplorerUrl(network, address) {
|
|
28
|
+
return `${EXPLORER_URLS[network]}/address/${address}`;
|
|
29
|
+
}
|
|
30
|
+
function getAssetExplorerUrl(network, policyId, assetName) {
|
|
31
|
+
const assetId = assetName ? `${policyId}.${assetName}` : policyId;
|
|
32
|
+
return `${EXPLORER_URLS[network]}/token/${assetId}`;
|
|
33
|
+
}
|
|
34
|
+
function getPolicyExplorerUrl(network, policyId) {
|
|
35
|
+
return `${EXPLORER_URLS[network]}/tokenPolicy/${policyId}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/constants/policies.ts
|
|
39
|
+
var POLICY_IDS = {
|
|
40
|
+
preprod: {
|
|
41
|
+
accessToken: "4758613867a8a7aa500b5d57a0e877f01a8e63c1365469589b12063c",
|
|
42
|
+
courseToken: "",
|
|
43
|
+
// Set via environment
|
|
44
|
+
moduleToken: "",
|
|
45
|
+
// Set via environment
|
|
46
|
+
assignmentToken: "",
|
|
47
|
+
// Set via environment
|
|
48
|
+
projectToken: "",
|
|
49
|
+
// Set via environment
|
|
50
|
+
taskToken: "",
|
|
51
|
+
// Set via environment
|
|
52
|
+
contributorToken: ""
|
|
53
|
+
// Set via environment
|
|
54
|
+
},
|
|
55
|
+
preview: {
|
|
56
|
+
accessToken: "",
|
|
57
|
+
courseToken: "",
|
|
58
|
+
moduleToken: "",
|
|
59
|
+
assignmentToken: "",
|
|
60
|
+
projectToken: "",
|
|
61
|
+
taskToken: "",
|
|
62
|
+
contributorToken: ""
|
|
63
|
+
},
|
|
64
|
+
mainnet: {
|
|
65
|
+
accessToken: "",
|
|
66
|
+
courseToken: "",
|
|
67
|
+
moduleToken: "",
|
|
68
|
+
assignmentToken: "",
|
|
69
|
+
projectToken: "",
|
|
70
|
+
taskToken: "",
|
|
71
|
+
contributorToken: ""
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
function getAccessTokenPolicyId(network) {
|
|
75
|
+
return POLICY_IDS[network].accessToken;
|
|
76
|
+
}
|
|
77
|
+
function isValidPolicyId(policyId) {
|
|
78
|
+
if (typeof policyId !== "string") {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (policyId.length !== 56) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return /^[0-9a-fA-F]{56}$/.test(policyId);
|
|
85
|
+
}
|
|
86
|
+
function isValidAssetName(assetName) {
|
|
87
|
+
if (typeof assetName !== "string") {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (assetName.length > 64) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
if (assetName.length % 2 !== 0) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return /^[0-9a-fA-F]*$/.test(assetName);
|
|
97
|
+
}
|
|
98
|
+
function stringToAssetName(str) {
|
|
99
|
+
return Array.from(new TextEncoder().encode(str)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
100
|
+
}
|
|
101
|
+
function assetNameToString(hex) {
|
|
102
|
+
const bytes = new Uint8Array(
|
|
103
|
+
hex.match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16)) ?? []
|
|
104
|
+
);
|
|
105
|
+
return new TextDecoder().decode(bytes);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
exports.ADDRESS_PREFIX = ADDRESS_PREFIX;
|
|
109
|
+
exports.CEXPLORER_URLS = CEXPLORER_URLS;
|
|
110
|
+
exports.EXPLORER_URLS = EXPLORER_URLS;
|
|
111
|
+
exports.NETWORK_MAGIC = NETWORK_MAGIC;
|
|
112
|
+
exports.POLICY_IDS = POLICY_IDS;
|
|
113
|
+
exports.assetNameToString = assetNameToString;
|
|
114
|
+
exports.getAccessTokenPolicyId = getAccessTokenPolicyId;
|
|
115
|
+
exports.getAddressExplorerUrl = getAddressExplorerUrl;
|
|
116
|
+
exports.getAssetExplorerUrl = getAssetExplorerUrl;
|
|
117
|
+
exports.getPolicyExplorerUrl = getPolicyExplorerUrl;
|
|
118
|
+
exports.getTxExplorerUrl = getTxExplorerUrl;
|
|
119
|
+
exports.isValidAssetName = isValidAssetName;
|
|
120
|
+
exports.isValidPolicyId = isValidPolicyId;
|
|
121
|
+
exports.stringToAssetName = stringToAssetName;
|
|
122
|
+
//# sourceMappingURL=index.js.map
|
|
123
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/constants/cardano.ts","../../src/constants/polic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AA,KAAM,CAAA,EAAG;AAC9B,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,gBAAA,CAAiB,KAAK,SAAS,CAAA;AACxC;AAKO,SAAS,kBAAkB,GAAA,EAAqB;AACrD,EAAA,OAAO,KAAA,CAAM,KAAK,IAAI,WAAA,GAAc,MAAA,CAAO,GAAG,CAAC,CAAA,CAC5C,GAAA,CAAI,CAAC,MAAM,CAAA,CAAE,QAAA,CAAS,EAAE,CAAA,CAAE,QAAA,CAAS,GAAG,GAAG,CAAC,CAAA,CAC1C,IAAA,CAAK,EAAE,CAAA;AACZ;AAKO,SAAS,kBAAkB,GAAA,EAAqB;AACrD,EAAA,MAAM,QAAQ,IAAI,UAAA;AAAA,IAChB,GAAA,CAAI,KAAA,CAAM,SAAS,CAAA,EAAG,GAAA,CAAI,CAAC,IAAA,KAAS,QAAA,CAAS,IAAA,EAAM,EAAE,CAAC,CAAA,IAAK;AAAC,GAC9D;AACA,EAAA,OAAO,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,KAAK,CAAA;AACvC","file":"index.js","sourcesContent":["/**\n * Cardano Network Constants\n *\n * Network identifiers, explorer URLs, and other Cardano-specific constants.\n *\n * @module @andamio/core/constants\n */\n\n/**\n * Supported Cardano networks\n */\nexport type CardanoNetwork = \"mainnet\" | \"preprod\" | \"preview\";\n\n/**\n * Block explorer URLs by network\n */\nexport const EXPLORER_URLS: Record<CardanoNetwork, string> = {\n mainnet: \"https://cardanoscan.io\",\n preprod: \"https://preprod.cardanoscan.io\",\n preview: \"https://preview.cardanoscan.io\",\n} as const;\n\n/**\n * CExplorer URLs by network (alternative explorer)\n */\nexport const CEXPLORER_URLS: Record<CardanoNetwork, string> = {\n mainnet: \"https://cexplorer.io\",\n preprod: \"https://preprod.cexplorer.io\",\n preview: \"https://preview.cexplorer.io\",\n} as const;\n\n/**\n * Network magic numbers for Cardano networks\n */\nexport const NETWORK_MAGIC: Record<CardanoNetwork, number> = {\n mainnet: 764824073,\n preprod: 1,\n preview: 2,\n} as const;\n\n/**\n * Bech32 address prefixes by network\n */\nexport const ADDRESS_PREFIX: Record<CardanoNetwork, string> = {\n mainnet: \"addr\",\n preprod: \"addr_test\",\n preview: \"addr_test\",\n} as const;\n\n/**\n * Get explorer URL for a transaction\n */\nexport function getTxExplorerUrl(\n network: CardanoNetwork,\n txHash: string\n): string {\n return `${EXPLORER_URLS[network]}/transaction/${txHash}`;\n}\n\n/**\n * Get explorer URL for an address\n */\nexport function getAddressExplorerUrl(\n network: CardanoNetwork,\n address: string\n): string {\n return `${EXPLORER_URLS[network]}/address/${address}`;\n}\n\n/**\n * Get explorer URL for a token/asset\n */\nexport function getAssetExplorerUrl(\n network: CardanoNetwork,\n policyId: string,\n assetName?: string\n): string {\n const assetId = assetName ? `${policyId}.${assetName}` : policyId;\n return `${EXPLORER_URLS[network]}/token/${assetId}`;\n}\n\n/**\n * Get explorer URL for a policy\n */\nexport function getPolicyExplorerUrl(\n network: CardanoNetwork,\n policyId: string\n): string {\n return `${EXPLORER_URLS[network]}/tokenPolicy/${policyId}`;\n}\n","/**\n * Andamio Policy IDs\n *\n * Policy IDs for Andamio protocol tokens by network.\n * These are used to identify access tokens, course tokens, and other\n * protocol-specific assets on-chain.\n *\n * @module @andamio/core/constants\n */\n\nimport type { CardanoNetwork } from \"./cardano\";\n\n/**\n * Policy ID configuration for a network\n */\nexport interface NetworkPolicies {\n /** Access token policy ID - identifies user access tokens */\n accessToken: string;\n /** Course token policy ID - identifies course tokens */\n courseToken: string;\n /** Module token policy ID - identifies module tokens */\n moduleToken: string;\n /** Assignment token policy ID - identifies assignment tokens */\n assignmentToken: string;\n /** Project token policy ID - identifies project tokens */\n projectToken: string;\n /** Task token policy ID - identifies task tokens */\n taskToken: string;\n /** Contributor token policy ID - identifies contributor tokens */\n contributorToken: string;\n}\n\n/**\n * Policy IDs by network\n *\n * Note: These should be loaded from environment variables in production.\n * The values here are examples/defaults for the preprod network.\n */\nexport const POLICY_IDS: Record<CardanoNetwork, NetworkPolicies> = {\n preprod: {\n accessToken: \"4758613867a8a7aa500b5d57a0e877f01a8e63c1365469589b12063c\",\n courseToken: \"\", // Set via environment\n moduleToken: \"\", // Set via environment\n assignmentToken: \"\", // Set via environment\n projectToken: \"\", // Set via environment\n taskToken: \"\", // Set via environment\n contributorToken: \"\", // Set via environment\n },\n preview: {\n accessToken: \"\",\n courseToken: \"\",\n moduleToken: \"\",\n assignmentToken: \"\",\n projectToken: \"\",\n taskToken: \"\",\n contributorToken: \"\",\n },\n mainnet: {\n accessToken: \"\",\n courseToken: \"\",\n moduleToken: \"\",\n assignmentToken: \"\",\n projectToken: \"\",\n taskToken: \"\",\n contributorToken: \"\",\n },\n} as const;\n\n/**\n * Get the access token policy ID for a network\n */\nexport function getAccessTokenPolicyId(network: CardanoNetwork): string {\n return POLICY_IDS[network].accessToken;\n}\n\n/**\n * Validate a policy ID format (56 hex characters)\n */\nexport function isValidPolicyId(policyId: string): boolean {\n if (typeof policyId !== \"string\") {\n return false;\n }\n if (policyId.length !== 56) {\n return false;\n }\n return /^[0-9a-fA-F]{56}$/.test(policyId);\n}\n\n/**\n * Validate an asset name format (hex string, max 64 chars / 32 bytes)\n */\nexport function isValidAssetName(assetName: string): boolean {\n if (typeof assetName !== \"string\") {\n return false;\n }\n if (assetName.length > 64) {\n return false;\n }\n if (assetName.length % 2 !== 0) {\n return false;\n }\n return /^[0-9a-fA-F]*$/.test(assetName);\n}\n\n/**\n * Convert a UTF-8 string to hex asset name\n */\nexport function stringToAssetName(str: string): string {\n return Array.from(new TextEncoder().encode(str))\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Convert a hex asset name to UTF-8 string\n */\nexport function assetNameToString(hex: string): string {\n const bytes = new Uint8Array(\n hex.match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16)) ?? []\n );\n return new TextDecoder().decode(bytes);\n}\n"]}
|