rune-stamp-sdk 0.1.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/LICENSE +21 -0
- package/README.md +41 -0
- package/dist/index.d.mts +52 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +126 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +82 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rune-Stamp
|
|
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,41 @@
|
|
|
1
|
+
# rune-stamp-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for rune-style badge/stamp issuance on the Stacks blockchain — mint, verify, enumerate.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install rune-stamp-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { buildReadOnlyUrl, parseContractId } from 'rune-stamp-sdk';
|
|
15
|
+
|
|
16
|
+
const contract = parseContractId('SP16F6839630K5XX06KE7KVNSNMYBK89912NH6N4C.rune-stamp-a1');
|
|
17
|
+
if (contract) {
|
|
18
|
+
const url = buildReadOnlyUrl({ contract, functionName: 'get-stamp' });
|
|
19
|
+
console.log(url);
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## What's inside
|
|
24
|
+
|
|
25
|
+
- `constants` — network endpoints, project-specific defaults
|
|
26
|
+
- `utils` — address/contract-name validation, parsing, formatting, STX conversion
|
|
27
|
+
- `contract` — read-only call URL helpers
|
|
28
|
+
- `types` — `Stamp` and related shapes
|
|
29
|
+
|
|
30
|
+
## Scripts
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm test # vitest run
|
|
34
|
+
npm run typecheck # tsc --noEmit
|
|
35
|
+
npm run lint # eslint
|
|
36
|
+
npm run build # tsup → dist/
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
41
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
declare const STACKS_MAINNET = "https://api.mainnet.hiro.so";
|
|
2
|
+
declare const STACKS_TESTNET = "https://api.testnet.hiro.so";
|
|
3
|
+
declare const DEFAULT_FEE_USTX = 5000;
|
|
4
|
+
declare const MICROSTX_PER_STX = 1000000;
|
|
5
|
+
declare const CLARITY_VERSION = 4;
|
|
6
|
+
declare const MAX_RUNE_NAME_LENGTH = 64;
|
|
7
|
+
declare const MAX_STAMP_DESCRIPTION_LENGTH = 256;
|
|
8
|
+
declare const STAMP_TIER: {
|
|
9
|
+
readonly common: 1;
|
|
10
|
+
readonly rare: 2;
|
|
11
|
+
readonly legendary: 3;
|
|
12
|
+
};
|
|
13
|
+
declare const NETWORKS: {
|
|
14
|
+
readonly mainnet: "https://api.mainnet.hiro.so";
|
|
15
|
+
readonly testnet: "https://api.testnet.hiro.so";
|
|
16
|
+
};
|
|
17
|
+
type NetworkName = keyof typeof NETWORKS;
|
|
18
|
+
|
|
19
|
+
interface ContractIdentifier {
|
|
20
|
+
address: string;
|
|
21
|
+
name: string;
|
|
22
|
+
}
|
|
23
|
+
interface Stamp {
|
|
24
|
+
id: number;
|
|
25
|
+
runeName: string;
|
|
26
|
+
recipient: string;
|
|
27
|
+
mintedAt: number;
|
|
28
|
+
}
|
|
29
|
+
interface TxOptions {
|
|
30
|
+
fee?: number;
|
|
31
|
+
nonce?: number;
|
|
32
|
+
postConditions?: unknown[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare function microStxToStx(usx: number): number;
|
|
36
|
+
declare function stxToMicroStx(stx: number): number;
|
|
37
|
+
declare function isValidStacksAddress(addr: string): boolean;
|
|
38
|
+
declare function isValidContractName(name: string): boolean;
|
|
39
|
+
declare function parseContractId(id: string): ContractIdentifier | null;
|
|
40
|
+
declare function formatContractId(address: string, name: string): string;
|
|
41
|
+
declare function truncateAddress(addr: string, prefix?: number, suffix?: number): string;
|
|
42
|
+
|
|
43
|
+
interface ReadOnlyCallArgs {
|
|
44
|
+
contract: ContractIdentifier;
|
|
45
|
+
functionName: string;
|
|
46
|
+
network?: NetworkName;
|
|
47
|
+
sender?: string;
|
|
48
|
+
}
|
|
49
|
+
declare function buildReadOnlyUrl(args: ReadOnlyCallArgs): string;
|
|
50
|
+
declare function describeContract(c: ContractIdentifier): string;
|
|
51
|
+
|
|
52
|
+
export { CLARITY_VERSION, type ContractIdentifier, DEFAULT_FEE_USTX, MAX_RUNE_NAME_LENGTH, MAX_STAMP_DESCRIPTION_LENGTH, MICROSTX_PER_STX, NETWORKS, type NetworkName, type ReadOnlyCallArgs, STACKS_MAINNET, STACKS_TESTNET, STAMP_TIER, type Stamp, type TxOptions, buildReadOnlyUrl, describeContract, formatContractId, isValidContractName, isValidStacksAddress, microStxToStx, parseContractId, stxToMicroStx, truncateAddress };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
declare const STACKS_MAINNET = "https://api.mainnet.hiro.so";
|
|
2
|
+
declare const STACKS_TESTNET = "https://api.testnet.hiro.so";
|
|
3
|
+
declare const DEFAULT_FEE_USTX = 5000;
|
|
4
|
+
declare const MICROSTX_PER_STX = 1000000;
|
|
5
|
+
declare const CLARITY_VERSION = 4;
|
|
6
|
+
declare const MAX_RUNE_NAME_LENGTH = 64;
|
|
7
|
+
declare const MAX_STAMP_DESCRIPTION_LENGTH = 256;
|
|
8
|
+
declare const STAMP_TIER: {
|
|
9
|
+
readonly common: 1;
|
|
10
|
+
readonly rare: 2;
|
|
11
|
+
readonly legendary: 3;
|
|
12
|
+
};
|
|
13
|
+
declare const NETWORKS: {
|
|
14
|
+
readonly mainnet: "https://api.mainnet.hiro.so";
|
|
15
|
+
readonly testnet: "https://api.testnet.hiro.so";
|
|
16
|
+
};
|
|
17
|
+
type NetworkName = keyof typeof NETWORKS;
|
|
18
|
+
|
|
19
|
+
interface ContractIdentifier {
|
|
20
|
+
address: string;
|
|
21
|
+
name: string;
|
|
22
|
+
}
|
|
23
|
+
interface Stamp {
|
|
24
|
+
id: number;
|
|
25
|
+
runeName: string;
|
|
26
|
+
recipient: string;
|
|
27
|
+
mintedAt: number;
|
|
28
|
+
}
|
|
29
|
+
interface TxOptions {
|
|
30
|
+
fee?: number;
|
|
31
|
+
nonce?: number;
|
|
32
|
+
postConditions?: unknown[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare function microStxToStx(usx: number): number;
|
|
36
|
+
declare function stxToMicroStx(stx: number): number;
|
|
37
|
+
declare function isValidStacksAddress(addr: string): boolean;
|
|
38
|
+
declare function isValidContractName(name: string): boolean;
|
|
39
|
+
declare function parseContractId(id: string): ContractIdentifier | null;
|
|
40
|
+
declare function formatContractId(address: string, name: string): string;
|
|
41
|
+
declare function truncateAddress(addr: string, prefix?: number, suffix?: number): string;
|
|
42
|
+
|
|
43
|
+
interface ReadOnlyCallArgs {
|
|
44
|
+
contract: ContractIdentifier;
|
|
45
|
+
functionName: string;
|
|
46
|
+
network?: NetworkName;
|
|
47
|
+
sender?: string;
|
|
48
|
+
}
|
|
49
|
+
declare function buildReadOnlyUrl(args: ReadOnlyCallArgs): string;
|
|
50
|
+
declare function describeContract(c: ContractIdentifier): string;
|
|
51
|
+
|
|
52
|
+
export { CLARITY_VERSION, type ContractIdentifier, DEFAULT_FEE_USTX, MAX_RUNE_NAME_LENGTH, MAX_STAMP_DESCRIPTION_LENGTH, MICROSTX_PER_STX, NETWORKS, type NetworkName, type ReadOnlyCallArgs, STACKS_MAINNET, STACKS_TESTNET, STAMP_TIER, type Stamp, type TxOptions, buildReadOnlyUrl, describeContract, formatContractId, isValidContractName, isValidStacksAddress, microStxToStx, parseContractId, stxToMicroStx, truncateAddress };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
CLARITY_VERSION: () => CLARITY_VERSION,
|
|
24
|
+
DEFAULT_FEE_USTX: () => DEFAULT_FEE_USTX,
|
|
25
|
+
MAX_RUNE_NAME_LENGTH: () => MAX_RUNE_NAME_LENGTH,
|
|
26
|
+
MAX_STAMP_DESCRIPTION_LENGTH: () => MAX_STAMP_DESCRIPTION_LENGTH,
|
|
27
|
+
MICROSTX_PER_STX: () => MICROSTX_PER_STX,
|
|
28
|
+
NETWORKS: () => NETWORKS,
|
|
29
|
+
STACKS_MAINNET: () => STACKS_MAINNET,
|
|
30
|
+
STACKS_TESTNET: () => STACKS_TESTNET,
|
|
31
|
+
STAMP_TIER: () => STAMP_TIER,
|
|
32
|
+
buildReadOnlyUrl: () => buildReadOnlyUrl,
|
|
33
|
+
describeContract: () => describeContract,
|
|
34
|
+
formatContractId: () => formatContractId,
|
|
35
|
+
isValidContractName: () => isValidContractName,
|
|
36
|
+
isValidStacksAddress: () => isValidStacksAddress,
|
|
37
|
+
microStxToStx: () => microStxToStx,
|
|
38
|
+
parseContractId: () => parseContractId,
|
|
39
|
+
stxToMicroStx: () => stxToMicroStx,
|
|
40
|
+
truncateAddress: () => truncateAddress
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(index_exports);
|
|
43
|
+
|
|
44
|
+
// src/constants.ts
|
|
45
|
+
var STACKS_MAINNET = "https://api.mainnet.hiro.so";
|
|
46
|
+
var STACKS_TESTNET = "https://api.testnet.hiro.so";
|
|
47
|
+
var DEFAULT_FEE_USTX = 5e3;
|
|
48
|
+
var MICROSTX_PER_STX = 1e6;
|
|
49
|
+
var CLARITY_VERSION = 4;
|
|
50
|
+
var MAX_RUNE_NAME_LENGTH = 64;
|
|
51
|
+
var MAX_STAMP_DESCRIPTION_LENGTH = 256;
|
|
52
|
+
var STAMP_TIER = { common: 1, rare: 2, legendary: 3 };
|
|
53
|
+
var NETWORKS = {
|
|
54
|
+
mainnet: STACKS_MAINNET,
|
|
55
|
+
testnet: STACKS_TESTNET
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// src/utils.ts
|
|
59
|
+
var STACKS_ADDRESS_RE = /^S[PT][0-9A-HJKMNP-Z]{38,40}$/;
|
|
60
|
+
var CONTRACT_NAME_RE = /^[a-zA-Z][a-zA-Z0-9\-]{0,127}$/;
|
|
61
|
+
function microStxToStx(usx) {
|
|
62
|
+
return usx / MICROSTX_PER_STX;
|
|
63
|
+
}
|
|
64
|
+
function stxToMicroStx(stx) {
|
|
65
|
+
return Math.round(stx * MICROSTX_PER_STX);
|
|
66
|
+
}
|
|
67
|
+
function isValidStacksAddress(addr) {
|
|
68
|
+
if (typeof addr !== "string") return false;
|
|
69
|
+
return STACKS_ADDRESS_RE.test(addr);
|
|
70
|
+
}
|
|
71
|
+
function isValidContractName(name) {
|
|
72
|
+
if (typeof name !== "string") return false;
|
|
73
|
+
return CONTRACT_NAME_RE.test(name);
|
|
74
|
+
}
|
|
75
|
+
function parseContractId(id) {
|
|
76
|
+
const parts = id.split(".");
|
|
77
|
+
if (parts.length !== 2) return null;
|
|
78
|
+
const [address, name] = parts;
|
|
79
|
+
if (!isValidStacksAddress(address) || !isValidContractName(name)) return null;
|
|
80
|
+
return { address, name };
|
|
81
|
+
}
|
|
82
|
+
function formatContractId(address, name) {
|
|
83
|
+
return `${address}.${name}`;
|
|
84
|
+
}
|
|
85
|
+
function truncateAddress(addr, prefix = 4, suffix = 4) {
|
|
86
|
+
if (!addr || addr.length <= prefix + suffix + 3) return addr;
|
|
87
|
+
return `${addr.slice(0, prefix)}...${addr.slice(-suffix)}`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/contract.ts
|
|
91
|
+
function buildReadOnlyUrl(args) {
|
|
92
|
+
const { contract, functionName, network = "mainnet" } = args;
|
|
93
|
+
if (!isValidStacksAddress(contract.address)) {
|
|
94
|
+
throw new Error(`Invalid contract address: ${contract.address}`);
|
|
95
|
+
}
|
|
96
|
+
if (!isValidContractName(contract.name)) {
|
|
97
|
+
throw new Error(`Invalid contract name: ${contract.name}`);
|
|
98
|
+
}
|
|
99
|
+
const base = NETWORKS[network];
|
|
100
|
+
return `${base}/v2/contracts/call-read/${contract.address}/${contract.name}/${functionName}`;
|
|
101
|
+
}
|
|
102
|
+
function describeContract(c) {
|
|
103
|
+
return `Stacks contract ${formatContractId(c.address, c.name)}`;
|
|
104
|
+
}
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
CLARITY_VERSION,
|
|
108
|
+
DEFAULT_FEE_USTX,
|
|
109
|
+
MAX_RUNE_NAME_LENGTH,
|
|
110
|
+
MAX_STAMP_DESCRIPTION_LENGTH,
|
|
111
|
+
MICROSTX_PER_STX,
|
|
112
|
+
NETWORKS,
|
|
113
|
+
STACKS_MAINNET,
|
|
114
|
+
STACKS_TESTNET,
|
|
115
|
+
STAMP_TIER,
|
|
116
|
+
buildReadOnlyUrl,
|
|
117
|
+
describeContract,
|
|
118
|
+
formatContractId,
|
|
119
|
+
isValidContractName,
|
|
120
|
+
isValidStacksAddress,
|
|
121
|
+
microStxToStx,
|
|
122
|
+
parseContractId,
|
|
123
|
+
stxToMicroStx,
|
|
124
|
+
truncateAddress
|
|
125
|
+
});
|
|
126
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/constants.ts","../src/utils.ts","../src/contract.ts"],"sourcesContent":["export * from './constants';\nexport * from './utils';\nexport * from './contract';\nexport * from './types';\n","export const STACKS_MAINNET = 'https://api.mainnet.hiro.so';\nexport const STACKS_TESTNET = 'https://api.testnet.hiro.so';\n\nexport const DEFAULT_FEE_USTX = 5_000;\nexport const MICROSTX_PER_STX = 1_000_000;\n\nexport const CLARITY_VERSION = 4;\n\nexport const MAX_RUNE_NAME_LENGTH = 64;\nexport const MAX_STAMP_DESCRIPTION_LENGTH = 256;\nexport const STAMP_TIER = { common: 1, rare: 2, legendary: 3 } as const;\n\nexport const NETWORKS = {\n mainnet: STACKS_MAINNET,\n testnet: STACKS_TESTNET,\n} as const;\n\nexport type NetworkName = keyof typeof NETWORKS;\n","import { MICROSTX_PER_STX } from './constants';\nimport type { ContractIdentifier } from './types';\n\nconst STACKS_ADDRESS_RE = /^S[PT][0-9A-HJKMNP-Z]{38,40}$/;\nconst CONTRACT_NAME_RE = /^[a-zA-Z][a-zA-Z0-9\\-]{0,127}$/;\n\nexport function microStxToStx(usx: number): number {\n return usx / MICROSTX_PER_STX;\n}\n\nexport function stxToMicroStx(stx: number): number {\n return Math.round(stx * MICROSTX_PER_STX);\n}\n\nexport function isValidStacksAddress(addr: string): boolean {\n if (typeof addr !== 'string') return false;\n return STACKS_ADDRESS_RE.test(addr);\n}\n\nexport function isValidContractName(name: string): boolean {\n if (typeof name !== 'string') return false;\n return CONTRACT_NAME_RE.test(name);\n}\n\nexport function parseContractId(id: string): ContractIdentifier | null {\n const parts = id.split('.');\n if (parts.length !== 2) return null;\n const [address, name] = parts;\n if (!isValidStacksAddress(address) || !isValidContractName(name)) return null;\n return { address, name };\n}\n\nexport function formatContractId(address: string, name: string): string {\n return `${address}.${name}`;\n}\n\nexport function truncateAddress(addr: string, prefix = 4, suffix = 4): string {\n if (!addr || addr.length <= prefix + suffix + 3) return addr;\n return `${addr.slice(0, prefix)}...${addr.slice(-suffix)}`;\n}\n","import { NETWORKS, type NetworkName } from './constants';\nimport { formatContractId, isValidContractName, isValidStacksAddress } from './utils';\nimport type { ContractIdentifier } from './types';\n\nexport interface ReadOnlyCallArgs {\n contract: ContractIdentifier;\n functionName: string;\n network?: NetworkName;\n sender?: string;\n}\n\nexport function buildReadOnlyUrl(args: ReadOnlyCallArgs): string {\n const { contract, functionName, network = 'mainnet' } = args;\n if (!isValidStacksAddress(contract.address)) {\n throw new Error(`Invalid contract address: ${contract.address}`);\n }\n if (!isValidContractName(contract.name)) {\n throw new Error(`Invalid contract name: ${contract.name}`);\n }\n const base = NETWORKS[network];\n return `${base}/v2/contracts/call-read/${contract.address}/${contract.name}/${functionName}`;\n}\n\nexport function describeContract(c: ContractIdentifier): string {\n return `Stacks contract ${formatContractId(c.address, c.name)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,iBAAiB;AACvB,IAAM,iBAAiB;AAEvB,IAAM,mBAAmB;AACzB,IAAM,mBAAmB;AAEzB,IAAM,kBAAkB;AAExB,IAAM,uBAAuB;AAC7B,IAAM,+BAA+B;AACrC,IAAM,aAAa,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,EAAE;AAEtD,IAAM,WAAW;AAAA,EACtB,SAAS;AAAA,EACT,SAAS;AACX;;;ACZA,IAAM,oBAAoB;AAC1B,IAAM,mBAAmB;AAElB,SAAS,cAAc,KAAqB;AACjD,SAAO,MAAM;AACf;AAEO,SAAS,cAAc,KAAqB;AACjD,SAAO,KAAK,MAAM,MAAM,gBAAgB;AAC1C;AAEO,SAAS,qBAAqB,MAAuB;AAC1D,MAAI,OAAO,SAAS,SAAU,QAAO;AACrC,SAAO,kBAAkB,KAAK,IAAI;AACpC;AAEO,SAAS,oBAAoB,MAAuB;AACzD,MAAI,OAAO,SAAS,SAAU,QAAO;AACrC,SAAO,iBAAiB,KAAK,IAAI;AACnC;AAEO,SAAS,gBAAgB,IAAuC;AACrE,QAAM,QAAQ,GAAG,MAAM,GAAG;AAC1B,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,QAAM,CAAC,SAAS,IAAI,IAAI;AACxB,MAAI,CAAC,qBAAqB,OAAO,KAAK,CAAC,oBAAoB,IAAI,EAAG,QAAO;AACzE,SAAO,EAAE,SAAS,KAAK;AACzB;AAEO,SAAS,iBAAiB,SAAiB,MAAsB;AACtE,SAAO,GAAG,OAAO,IAAI,IAAI;AAC3B;AAEO,SAAS,gBAAgB,MAAc,SAAS,GAAG,SAAS,GAAW;AAC5E,MAAI,CAAC,QAAQ,KAAK,UAAU,SAAS,SAAS,EAAG,QAAO;AACxD,SAAO,GAAG,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC;AAC1D;;;AC5BO,SAAS,iBAAiB,MAAgC;AAC/D,QAAM,EAAE,UAAU,cAAc,UAAU,UAAU,IAAI;AACxD,MAAI,CAAC,qBAAqB,SAAS,OAAO,GAAG;AAC3C,UAAM,IAAI,MAAM,6BAA6B,SAAS,OAAO,EAAE;AAAA,EACjE;AACA,MAAI,CAAC,oBAAoB,SAAS,IAAI,GAAG;AACvC,UAAM,IAAI,MAAM,0BAA0B,SAAS,IAAI,EAAE;AAAA,EAC3D;AACA,QAAM,OAAO,SAAS,OAAO;AAC7B,SAAO,GAAG,IAAI,2BAA2B,SAAS,OAAO,IAAI,SAAS,IAAI,IAAI,YAAY;AAC5F;AAEO,SAAS,iBAAiB,GAA+B;AAC9D,SAAO,mBAAmB,iBAAiB,EAAE,SAAS,EAAE,IAAI,CAAC;AAC/D;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var STACKS_MAINNET = "https://api.mainnet.hiro.so";
|
|
3
|
+
var STACKS_TESTNET = "https://api.testnet.hiro.so";
|
|
4
|
+
var DEFAULT_FEE_USTX = 5e3;
|
|
5
|
+
var MICROSTX_PER_STX = 1e6;
|
|
6
|
+
var CLARITY_VERSION = 4;
|
|
7
|
+
var MAX_RUNE_NAME_LENGTH = 64;
|
|
8
|
+
var MAX_STAMP_DESCRIPTION_LENGTH = 256;
|
|
9
|
+
var STAMP_TIER = { common: 1, rare: 2, legendary: 3 };
|
|
10
|
+
var NETWORKS = {
|
|
11
|
+
mainnet: STACKS_MAINNET,
|
|
12
|
+
testnet: STACKS_TESTNET
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// src/utils.ts
|
|
16
|
+
var STACKS_ADDRESS_RE = /^S[PT][0-9A-HJKMNP-Z]{38,40}$/;
|
|
17
|
+
var CONTRACT_NAME_RE = /^[a-zA-Z][a-zA-Z0-9\-]{0,127}$/;
|
|
18
|
+
function microStxToStx(usx) {
|
|
19
|
+
return usx / MICROSTX_PER_STX;
|
|
20
|
+
}
|
|
21
|
+
function stxToMicroStx(stx) {
|
|
22
|
+
return Math.round(stx * MICROSTX_PER_STX);
|
|
23
|
+
}
|
|
24
|
+
function isValidStacksAddress(addr) {
|
|
25
|
+
if (typeof addr !== "string") return false;
|
|
26
|
+
return STACKS_ADDRESS_RE.test(addr);
|
|
27
|
+
}
|
|
28
|
+
function isValidContractName(name) {
|
|
29
|
+
if (typeof name !== "string") return false;
|
|
30
|
+
return CONTRACT_NAME_RE.test(name);
|
|
31
|
+
}
|
|
32
|
+
function parseContractId(id) {
|
|
33
|
+
const parts = id.split(".");
|
|
34
|
+
if (parts.length !== 2) return null;
|
|
35
|
+
const [address, name] = parts;
|
|
36
|
+
if (!isValidStacksAddress(address) || !isValidContractName(name)) return null;
|
|
37
|
+
return { address, name };
|
|
38
|
+
}
|
|
39
|
+
function formatContractId(address, name) {
|
|
40
|
+
return `${address}.${name}`;
|
|
41
|
+
}
|
|
42
|
+
function truncateAddress(addr, prefix = 4, suffix = 4) {
|
|
43
|
+
if (!addr || addr.length <= prefix + suffix + 3) return addr;
|
|
44
|
+
return `${addr.slice(0, prefix)}...${addr.slice(-suffix)}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/contract.ts
|
|
48
|
+
function buildReadOnlyUrl(args) {
|
|
49
|
+
const { contract, functionName, network = "mainnet" } = args;
|
|
50
|
+
if (!isValidStacksAddress(contract.address)) {
|
|
51
|
+
throw new Error(`Invalid contract address: ${contract.address}`);
|
|
52
|
+
}
|
|
53
|
+
if (!isValidContractName(contract.name)) {
|
|
54
|
+
throw new Error(`Invalid contract name: ${contract.name}`);
|
|
55
|
+
}
|
|
56
|
+
const base = NETWORKS[network];
|
|
57
|
+
return `${base}/v2/contracts/call-read/${contract.address}/${contract.name}/${functionName}`;
|
|
58
|
+
}
|
|
59
|
+
function describeContract(c) {
|
|
60
|
+
return `Stacks contract ${formatContractId(c.address, c.name)}`;
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
CLARITY_VERSION,
|
|
64
|
+
DEFAULT_FEE_USTX,
|
|
65
|
+
MAX_RUNE_NAME_LENGTH,
|
|
66
|
+
MAX_STAMP_DESCRIPTION_LENGTH,
|
|
67
|
+
MICROSTX_PER_STX,
|
|
68
|
+
NETWORKS,
|
|
69
|
+
STACKS_MAINNET,
|
|
70
|
+
STACKS_TESTNET,
|
|
71
|
+
STAMP_TIER,
|
|
72
|
+
buildReadOnlyUrl,
|
|
73
|
+
describeContract,
|
|
74
|
+
formatContractId,
|
|
75
|
+
isValidContractName,
|
|
76
|
+
isValidStacksAddress,
|
|
77
|
+
microStxToStx,
|
|
78
|
+
parseContractId,
|
|
79
|
+
stxToMicroStx,
|
|
80
|
+
truncateAddress
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/utils.ts","../src/contract.ts"],"sourcesContent":["export const STACKS_MAINNET = 'https://api.mainnet.hiro.so';\nexport const STACKS_TESTNET = 'https://api.testnet.hiro.so';\n\nexport const DEFAULT_FEE_USTX = 5_000;\nexport const MICROSTX_PER_STX = 1_000_000;\n\nexport const CLARITY_VERSION = 4;\n\nexport const MAX_RUNE_NAME_LENGTH = 64;\nexport const MAX_STAMP_DESCRIPTION_LENGTH = 256;\nexport const STAMP_TIER = { common: 1, rare: 2, legendary: 3 } as const;\n\nexport const NETWORKS = {\n mainnet: STACKS_MAINNET,\n testnet: STACKS_TESTNET,\n} as const;\n\nexport type NetworkName = keyof typeof NETWORKS;\n","import { MICROSTX_PER_STX } from './constants';\nimport type { ContractIdentifier } from './types';\n\nconst STACKS_ADDRESS_RE = /^S[PT][0-9A-HJKMNP-Z]{38,40}$/;\nconst CONTRACT_NAME_RE = /^[a-zA-Z][a-zA-Z0-9\\-]{0,127}$/;\n\nexport function microStxToStx(usx: number): number {\n return usx / MICROSTX_PER_STX;\n}\n\nexport function stxToMicroStx(stx: number): number {\n return Math.round(stx * MICROSTX_PER_STX);\n}\n\nexport function isValidStacksAddress(addr: string): boolean {\n if (typeof addr !== 'string') return false;\n return STACKS_ADDRESS_RE.test(addr);\n}\n\nexport function isValidContractName(name: string): boolean {\n if (typeof name !== 'string') return false;\n return CONTRACT_NAME_RE.test(name);\n}\n\nexport function parseContractId(id: string): ContractIdentifier | null {\n const parts = id.split('.');\n if (parts.length !== 2) return null;\n const [address, name] = parts;\n if (!isValidStacksAddress(address) || !isValidContractName(name)) return null;\n return { address, name };\n}\n\nexport function formatContractId(address: string, name: string): string {\n return `${address}.${name}`;\n}\n\nexport function truncateAddress(addr: string, prefix = 4, suffix = 4): string {\n if (!addr || addr.length <= prefix + suffix + 3) return addr;\n return `${addr.slice(0, prefix)}...${addr.slice(-suffix)}`;\n}\n","import { NETWORKS, type NetworkName } from './constants';\nimport { formatContractId, isValidContractName, isValidStacksAddress } from './utils';\nimport type { ContractIdentifier } from './types';\n\nexport interface ReadOnlyCallArgs {\n contract: ContractIdentifier;\n functionName: string;\n network?: NetworkName;\n sender?: string;\n}\n\nexport function buildReadOnlyUrl(args: ReadOnlyCallArgs): string {\n const { contract, functionName, network = 'mainnet' } = args;\n if (!isValidStacksAddress(contract.address)) {\n throw new Error(`Invalid contract address: ${contract.address}`);\n }\n if (!isValidContractName(contract.name)) {\n throw new Error(`Invalid contract name: ${contract.name}`);\n }\n const base = NETWORKS[network];\n return `${base}/v2/contracts/call-read/${contract.address}/${contract.name}/${functionName}`;\n}\n\nexport function describeContract(c: ContractIdentifier): string {\n return `Stacks contract ${formatContractId(c.address, c.name)}`;\n}\n"],"mappings":";AAAO,IAAM,iBAAiB;AACvB,IAAM,iBAAiB;AAEvB,IAAM,mBAAmB;AACzB,IAAM,mBAAmB;AAEzB,IAAM,kBAAkB;AAExB,IAAM,uBAAuB;AAC7B,IAAM,+BAA+B;AACrC,IAAM,aAAa,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,EAAE;AAEtD,IAAM,WAAW;AAAA,EACtB,SAAS;AAAA,EACT,SAAS;AACX;;;ACZA,IAAM,oBAAoB;AAC1B,IAAM,mBAAmB;AAElB,SAAS,cAAc,KAAqB;AACjD,SAAO,MAAM;AACf;AAEO,SAAS,cAAc,KAAqB;AACjD,SAAO,KAAK,MAAM,MAAM,gBAAgB;AAC1C;AAEO,SAAS,qBAAqB,MAAuB;AAC1D,MAAI,OAAO,SAAS,SAAU,QAAO;AACrC,SAAO,kBAAkB,KAAK,IAAI;AACpC;AAEO,SAAS,oBAAoB,MAAuB;AACzD,MAAI,OAAO,SAAS,SAAU,QAAO;AACrC,SAAO,iBAAiB,KAAK,IAAI;AACnC;AAEO,SAAS,gBAAgB,IAAuC;AACrE,QAAM,QAAQ,GAAG,MAAM,GAAG;AAC1B,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,QAAM,CAAC,SAAS,IAAI,IAAI;AACxB,MAAI,CAAC,qBAAqB,OAAO,KAAK,CAAC,oBAAoB,IAAI,EAAG,QAAO;AACzE,SAAO,EAAE,SAAS,KAAK;AACzB;AAEO,SAAS,iBAAiB,SAAiB,MAAsB;AACtE,SAAO,GAAG,OAAO,IAAI,IAAI;AAC3B;AAEO,SAAS,gBAAgB,MAAc,SAAS,GAAG,SAAS,GAAW;AAC5E,MAAI,CAAC,QAAQ,KAAK,UAAU,SAAS,SAAS,EAAG,QAAO;AACxD,SAAO,GAAG,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC;AAC1D;;;AC5BO,SAAS,iBAAiB,MAAgC;AAC/D,QAAM,EAAE,UAAU,cAAc,UAAU,UAAU,IAAI;AACxD,MAAI,CAAC,qBAAqB,SAAS,OAAO,GAAG;AAC3C,UAAM,IAAI,MAAM,6BAA6B,SAAS,OAAO,EAAE;AAAA,EACjE;AACA,MAAI,CAAC,oBAAoB,SAAS,IAAI,GAAG;AACvC,UAAM,IAAI,MAAM,0BAA0B,SAAS,IAAI,EAAE;AAAA,EAC3D;AACA,QAAM,OAAO,SAAS,OAAO;AAC7B,SAAO,GAAG,IAAI,2BAA2B,SAAS,OAAO,IAAI,SAAS,IAAI,IAAI,YAAY;AAC5F;AAEO,SAAS,iBAAiB,GAA+B;AAC9D,SAAO,mBAAmB,iBAAiB,EAAE,SAAS,EAAE,IAAI,CAAC;AAC/D;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rune-stamp-sdk",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "TypeScript SDK for rune-style badge/stamp issuance on the Stacks blockchain — mint, verify, enumerate.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup",
|
|
20
|
+
"dev": "tsup --watch",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"test:watch": "vitest",
|
|
23
|
+
"test:utils": "vitest run tests/utils.test.ts",
|
|
24
|
+
"test:contract": "vitest run tests/contract.test.ts",
|
|
25
|
+
"test:constants": "vitest run tests/constants.test.ts",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"lint": "eslint src tests --ext .ts",
|
|
28
|
+
"prepublishOnly": "npm run build"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"stacks",
|
|
32
|
+
"clarity",
|
|
33
|
+
"blockchain",
|
|
34
|
+
"sdk",
|
|
35
|
+
"badges",
|
|
36
|
+
"stamps",
|
|
37
|
+
"runes",
|
|
38
|
+
"reputation",
|
|
39
|
+
"soulbound",
|
|
40
|
+
"web3"
|
|
41
|
+
],
|
|
42
|
+
"author": "Rune-Stamp",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/wurlelham531-svg/rune-stamp-sdk"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@stacks/transactions": "^6.12.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
53
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
54
|
+
"eslint": "^8.57.0",
|
|
55
|
+
"tsup": "^8.0.0",
|
|
56
|
+
"typescript": "^5.4.5",
|
|
57
|
+
"vitest": "^1.6.0"
|
|
58
|
+
}
|
|
59
|
+
}
|