stellarid-sdk 1.0.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/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # StellarID JavaScript SDK
2
+
3
+ The official JavaScript/TypeScript SDK for **StellarID** — the protocol-grade identity and reputation layer on Stellar.
4
+
5
+ Easily integrate user credential verification, reputation score lookups, on-chain credential issuance, and embeddable trust badges into your Web3 applications.
6
+
7
+ ---
8
+
9
+ ## Installation
10
+
11
+ Install the package via npm, yarn, or pnpm:
12
+
13
+ ```bash
14
+ npm install stellarid-sdk
15
+ # or
16
+ yarn add stellarid-sdk
17
+ # or
18
+ pnpm add stellarid-sdk
19
+ ```
20
+
21
+ ---
22
+
23
+ ## Quick Start
24
+
25
+ ### 1. Initialize the Client
26
+
27
+ Obtain your Developer API Key from the StellarID Dashboard and instantiate the client:
28
+
29
+ ```typescript
30
+ import { StellarID } from 'stellarid-sdk';
31
+
32
+ const stellarId = new StellarID({
33
+ apiKey: 'your-developer-api-key',
34
+ // Optional: Custom base URL (e.g. for local testing)
35
+ // baseURL: 'http://localhost:5555/api/v1'
36
+ });
37
+ ```
38
+
39
+ ### 2. Verify a User's Reputation Score & Credentials
40
+
41
+ Retrieve verified credentials and computed reputation levels for any Stellar wallet address:
42
+
43
+ ```typescript
44
+ async function checkUserReputation(walletAddress: string) {
45
+ try {
46
+ const profile = await stellarId.verifyWallet(walletAddress);
47
+
48
+ console.log(`Score: ${profile.reputation_score}`);
49
+ console.log(`Tier: ${profile.tier}`);
50
+ console.log(`Is Verified: ${profile.verified}`);
51
+
52
+ // List user credentials
53
+ profile.credentials.forEach(cred => {
54
+ console.log(`- ${cred.name} (${cred.status}) issued by ${cred.issuer_name}`);
55
+ });
56
+ } catch (error) {
57
+ console.error('Verification failed:', error.message);
58
+ }
59
+ }
60
+
61
+ checkUserReputation('GA2C7...55');
62
+ ```
63
+
64
+ ### 3. Generate and Embed a Trust Badge
65
+
66
+ Retrieve the ready-to-use `iframe` HTML code to render a gorgeous, glassmorphic trust badge on your website:
67
+
68
+ ```typescript
69
+ async function renderUserBadge(walletAddress: string) {
70
+ const badge = await stellarId.getBadge({
71
+ walletAddress,
72
+ style: 'dark', // 'light' | 'dark'
73
+ size: 'md', // 'sm' | 'md' | 'lg'
74
+ });
75
+
76
+ console.log('Insert this HTML to display the badge:');
77
+ console.log(badge.html);
78
+
79
+ // Or get the direct URL to use as you wish:
80
+ console.log('Iframe URL:', badge.iframe_url);
81
+ }
82
+ ```
83
+
84
+ ### 4. Issue a New Credential
85
+
86
+ Programmatically issue credentials to builders. This inserts a pending credential and emails the recipient a secure link to claim it:
87
+
88
+ ```typescript
89
+ async function sendDeveloperCredential(recipientEmail: string, walletAddress?: string) {
90
+ const result = await stellarId.issueCredential({
91
+ recipientEmail,
92
+ recipientWallet: walletAddress, // Optional
93
+ credential: {
94
+ name: 'github_developer',
95
+ description: 'Verified GitHub Contributor',
96
+ metadata: {
97
+ repositoriesContributionCount: 15,
98
+ languages: ['Rust', 'TypeScript']
99
+ },
100
+ expires_at: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString() // 1 year
101
+ }
102
+ });
103
+
104
+ console.log(`Credential Pending! Claim URL: ${result.claim_url}`);
105
+ }
106
+ ```
107
+
108
+ ---
109
+
110
+ ## React Integration Pattern
111
+
112
+ You can build a reactive hook or component to fetch reputation dynamically:
113
+
114
+ ```tsx
115
+ import React, { useState, useEffect } from 'react';
116
+ import { StellarID, VerifyWalletResponse } from 'stellarid-sdk';
117
+
118
+ const stellarIdClient = new StellarID({ apiKey: process.env.NEXT_PUBLIC_STELLARID_KEY! });
119
+
120
+ export function UserReputationWidget({ walletAddress }: { walletAddress: string }) {
121
+ const [data, setData] = useState<VerifyWalletResponse | null>(null);
122
+ const [loading, setLoading] = useState(true);
123
+
124
+ useEffect(() => {
125
+ stellarIdClient.verifyWallet(walletAddress)
126
+ .then(setData)
127
+ .finally(() => setLoading(false));
128
+ }, [walletAddress]);
129
+
130
+ if (loading) return <div>Loading reputation...</div>;
131
+ if (!data) return <div>Unverified User</div>;
132
+
133
+ return (
134
+ <div className="reputation-card">
135
+ <h4>Reputation: {data.reputation_score}</h4>
136
+ <span className="tier-tag">{data.tier}</span>
137
+ </div>
138
+ );
139
+ }
140
+ ```
141
+
142
+ ---
143
+
144
+ ## SDK API Reference
145
+
146
+ | Method | Parameters | Return Type | Required API Permission | Description |
147
+ | :--- | :--- | :--- | :--- | :--- |
148
+ | `verifyWallet(walletAddress)` | `walletAddress: string` | `Promise<VerifyWalletResponse>` | `verify` | Fetches a wallet's full reputation score, credentials list, and tier. |
149
+ | `getBadge(params)` | `{ walletAddress, style?, size? }` | `Promise<GetBadgeResponse>` | `verify` or `read_profile` | Generates iframe embedding HTML & source URL to show a micro-badge. |
150
+ | `issueCredential(params)` | `{ recipientEmail, recipientWallet?, credential }` | `Promise<IssueCredentialResponse>` | `issue` | Creates a pending credential and triggers a verification email. |
151
+ | `getCredential(credentialId)` | `credentialId: string` | `Promise<GetCredentialResponse>` | `read_profile` | Retrieves specific details of an existing, verified credential. |
152
+ | `getProof(credentialId)` | `credentialId: string` | `Promise<GetProofResponse>` | `verify` | Retrieves details about a verified zero-knowledge proof for a credential. |
153
+
154
+ ---
155
+
156
+ ## License
157
+
158
+ MIT License. Copyright (c) 2026 StellarID.
@@ -0,0 +1,126 @@
1
+ interface StellarIDConfig {
2
+ apiKey: string;
3
+ baseURL?: string;
4
+ }
5
+ interface CredentialListItem {
6
+ id: string;
7
+ name: string;
8
+ issuer_name: string;
9
+ issuer_verified: boolean;
10
+ issuer_verification_status: string;
11
+ issued_at: string;
12
+ expires_at: string;
13
+ status: 'active' | 'revoked' | 'expired';
14
+ tx_hash?: string;
15
+ }
16
+ interface VerifyWalletResponse {
17
+ wallet_address: string;
18
+ reputation_score: number;
19
+ tier: 'Verified' | 'Proven' | 'Elite Builder';
20
+ credential_count: number;
21
+ verified: boolean;
22
+ credentials: CredentialListItem[];
23
+ last_updated: string;
24
+ }
25
+ interface IssueCredentialParams {
26
+ recipientEmail: string;
27
+ recipientWallet?: string;
28
+ credential: {
29
+ name: string;
30
+ description?: string;
31
+ expires_at?: string;
32
+ metadata?: Record<string, any>;
33
+ };
34
+ }
35
+ interface IssueCredentialResponse {
36
+ success: boolean;
37
+ pending_credential_id: string;
38
+ claim_token: string;
39
+ claim_url: string;
40
+ expires_at: string;
41
+ created_at: string;
42
+ }
43
+ interface GetCredentialResponse {
44
+ id: string;
45
+ name: string;
46
+ claim_data: Record<string, any>;
47
+ wallet_address: string;
48
+ issuer: {
49
+ name: string;
50
+ verified: boolean;
51
+ verification_status: string;
52
+ };
53
+ status: 'active' | 'revoked' | 'expired';
54
+ issued_at: string;
55
+ expires_at: string;
56
+ revoked_at?: string;
57
+ on_chain: {
58
+ tx_hash?: string;
59
+ ipfs_hash?: string;
60
+ nft_token_id?: string;
61
+ };
62
+ zk_proof_available: boolean;
63
+ zk_proof: {
64
+ proof_id: string;
65
+ circuit_type: string;
66
+ public_token: string;
67
+ verified_at: string;
68
+ } | null;
69
+ }
70
+ interface GetProofResponse {
71
+ proof_id: string;
72
+ credential_name: string;
73
+ issuer_name: string;
74
+ circuit_type: string;
75
+ claim_type: string;
76
+ status: string;
77
+ public_token: string;
78
+ verification_url: string;
79
+ proof_time_ms: number;
80
+ created_at: string;
81
+ expires_at?: string;
82
+ valid: boolean;
83
+ }
84
+ interface GetBadgeParams {
85
+ walletAddress: string;
86
+ style?: 'light' | 'dark';
87
+ size?: 'sm' | 'md' | 'lg';
88
+ }
89
+ interface GetBadgeResponse {
90
+ html: string;
91
+ iframe_url: string;
92
+ }
93
+
94
+ declare class StellarID {
95
+ private apiKey;
96
+ private baseURL;
97
+ constructor(config: StellarIDConfig);
98
+ private request;
99
+ /**
100
+ * Verifies a Stellar wallet address, returning its reputation score, tier, and credentials.
101
+ * @param walletAddress Valid Stellar wallet address (G...)
102
+ */
103
+ verifyWallet(walletAddress: string): Promise<VerifyWalletResponse>;
104
+ /**
105
+ * Issues a pending credential to a recipient via email.
106
+ * @param params recipient details and credential metadata
107
+ */
108
+ issueCredential(params: IssueCredentialParams): Promise<IssueCredentialResponse>;
109
+ /**
110
+ * Retrieves details of a specific credential.
111
+ * @param credentialId The unique ID of the credential
112
+ */
113
+ getCredential(credentialId: string): Promise<GetCredentialResponse>;
114
+ /**
115
+ * Retrieves the ZK proof associated with a credential.
116
+ * @param credentialId The unique ID of the credential
117
+ */
118
+ getProof(credentialId: string): Promise<GetProofResponse>;
119
+ /**
120
+ * Gets the HTML embed code and iframe URL for a wallet badge.
121
+ * @param params parameters for styling and sizing the badge
122
+ */
123
+ getBadge(params: GetBadgeParams): Promise<GetBadgeResponse>;
124
+ }
125
+
126
+ export { type CredentialListItem, type GetBadgeParams, type GetBadgeResponse, type GetCredentialResponse, type GetProofResponse, type IssueCredentialParams, type IssueCredentialResponse, StellarID, StellarID as StellarIDClient, type StellarIDConfig, type VerifyWalletResponse };
@@ -0,0 +1,126 @@
1
+ interface StellarIDConfig {
2
+ apiKey: string;
3
+ baseURL?: string;
4
+ }
5
+ interface CredentialListItem {
6
+ id: string;
7
+ name: string;
8
+ issuer_name: string;
9
+ issuer_verified: boolean;
10
+ issuer_verification_status: string;
11
+ issued_at: string;
12
+ expires_at: string;
13
+ status: 'active' | 'revoked' | 'expired';
14
+ tx_hash?: string;
15
+ }
16
+ interface VerifyWalletResponse {
17
+ wallet_address: string;
18
+ reputation_score: number;
19
+ tier: 'Verified' | 'Proven' | 'Elite Builder';
20
+ credential_count: number;
21
+ verified: boolean;
22
+ credentials: CredentialListItem[];
23
+ last_updated: string;
24
+ }
25
+ interface IssueCredentialParams {
26
+ recipientEmail: string;
27
+ recipientWallet?: string;
28
+ credential: {
29
+ name: string;
30
+ description?: string;
31
+ expires_at?: string;
32
+ metadata?: Record<string, any>;
33
+ };
34
+ }
35
+ interface IssueCredentialResponse {
36
+ success: boolean;
37
+ pending_credential_id: string;
38
+ claim_token: string;
39
+ claim_url: string;
40
+ expires_at: string;
41
+ created_at: string;
42
+ }
43
+ interface GetCredentialResponse {
44
+ id: string;
45
+ name: string;
46
+ claim_data: Record<string, any>;
47
+ wallet_address: string;
48
+ issuer: {
49
+ name: string;
50
+ verified: boolean;
51
+ verification_status: string;
52
+ };
53
+ status: 'active' | 'revoked' | 'expired';
54
+ issued_at: string;
55
+ expires_at: string;
56
+ revoked_at?: string;
57
+ on_chain: {
58
+ tx_hash?: string;
59
+ ipfs_hash?: string;
60
+ nft_token_id?: string;
61
+ };
62
+ zk_proof_available: boolean;
63
+ zk_proof: {
64
+ proof_id: string;
65
+ circuit_type: string;
66
+ public_token: string;
67
+ verified_at: string;
68
+ } | null;
69
+ }
70
+ interface GetProofResponse {
71
+ proof_id: string;
72
+ credential_name: string;
73
+ issuer_name: string;
74
+ circuit_type: string;
75
+ claim_type: string;
76
+ status: string;
77
+ public_token: string;
78
+ verification_url: string;
79
+ proof_time_ms: number;
80
+ created_at: string;
81
+ expires_at?: string;
82
+ valid: boolean;
83
+ }
84
+ interface GetBadgeParams {
85
+ walletAddress: string;
86
+ style?: 'light' | 'dark';
87
+ size?: 'sm' | 'md' | 'lg';
88
+ }
89
+ interface GetBadgeResponse {
90
+ html: string;
91
+ iframe_url: string;
92
+ }
93
+
94
+ declare class StellarID {
95
+ private apiKey;
96
+ private baseURL;
97
+ constructor(config: StellarIDConfig);
98
+ private request;
99
+ /**
100
+ * Verifies a Stellar wallet address, returning its reputation score, tier, and credentials.
101
+ * @param walletAddress Valid Stellar wallet address (G...)
102
+ */
103
+ verifyWallet(walletAddress: string): Promise<VerifyWalletResponse>;
104
+ /**
105
+ * Issues a pending credential to a recipient via email.
106
+ * @param params recipient details and credential metadata
107
+ */
108
+ issueCredential(params: IssueCredentialParams): Promise<IssueCredentialResponse>;
109
+ /**
110
+ * Retrieves details of a specific credential.
111
+ * @param credentialId The unique ID of the credential
112
+ */
113
+ getCredential(credentialId: string): Promise<GetCredentialResponse>;
114
+ /**
115
+ * Retrieves the ZK proof associated with a credential.
116
+ * @param credentialId The unique ID of the credential
117
+ */
118
+ getProof(credentialId: string): Promise<GetProofResponse>;
119
+ /**
120
+ * Gets the HTML embed code and iframe URL for a wallet badge.
121
+ * @param params parameters for styling and sizing the badge
122
+ */
123
+ getBadge(params: GetBadgeParams): Promise<GetBadgeResponse>;
124
+ }
125
+
126
+ export { type CredentialListItem, type GetBadgeParams, type GetBadgeResponse, type GetCredentialResponse, type GetProofResponse, type IssueCredentialParams, type IssueCredentialResponse, StellarID, StellarID as StellarIDClient, type StellarIDConfig, type VerifyWalletResponse };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict';var s=class{constructor(e){if(!e.apiKey)throw new Error("StellarID SDK Error: apiKey is required");this.apiKey=e.apiKey;let r=e.baseURL||"https://stellarid.io/api/v1";this.baseURL=r.endsWith("/")?r.slice(0,-1):r;}async request(e,r={}){let l=`${this.baseURL}${e}`,n={"Content-Type":"application/json","X-API-Key":this.apiKey,...r.headers},t=await fetch(l,{...r,headers:n});if(!t.ok){let i=`StellarID request failed with status ${t.status}`;try{let a=await t.json();i=a.error||a.message||i;}catch{}throw new Error(`StellarID SDK Error: ${i}`)}return t.json()}async verifyWallet(e){if(!e||!/^G[A-Z2-7]{55}$/.test(e))throw new Error("StellarID SDK Error: Invalid Stellar wallet address format");return this.request(`/public/verify/${e}`)}async issueCredential(e){if(!e.recipientEmail)throw new Error("StellarID SDK Error: recipientEmail is required");if(!e.credential||!e.credential.name)throw new Error("StellarID SDK Error: credential.name is required");return this.request("/public/credentials/issue",{method:"POST",body:JSON.stringify({recipient_email:e.recipientEmail,recipient_wallet:e.recipientWallet,credential:e.credential})})}async getCredential(e){if(!e)throw new Error("StellarID SDK Error: credentialId is required");return this.request(`/public/credentials/${e}`)}async getProof(e){if(!e)throw new Error("StellarID SDK Error: credentialId is required");return this.request(`/public/proof/${e}`)}async getBadge(e){if(!e.walletAddress||!/^G[A-Z2-7]{55}$/.test(e.walletAddress))throw new Error("StellarID SDK Error: Invalid Stellar wallet address format");return this.request("/public/embed/badge",{method:"POST",body:JSON.stringify({wallet_address:e.walletAddress,style:e.style||"dark",size:e.size||"md"})})}};
2
+ exports.StellarID=s;exports.StellarIDClient=s;//# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts"],"names":["StellarID","config","base","path","options","url","headers","response","errorMessage","errorData","walletAddress","params","credentialId"],"mappings":"aAWO,IAAMA,CAAAA,CAAN,KAAgB,CAIrB,WAAA,CAAYC,CAAAA,CAAyB,CACnC,GAAI,CAACA,CAAAA,CAAO,MAAA,CACV,MAAM,IAAI,MAAM,yCAAyC,CAAA,CAE3D,IAAA,CAAK,MAAA,CAASA,CAAAA,CAAO,MAAA,CAErB,IAAMC,CAAAA,CAAOD,EAAO,OAAA,EAAW,6BAAA,CAC/B,IAAA,CAAK,OAAA,CAAUC,CAAAA,CAAK,QAAA,CAAS,GAAG,CAAA,CAAIA,EAAK,KAAA,CAAM,CAAA,CAAG,EAAE,CAAA,CAAIA,EAC1D,CAEA,MAAc,OAAA,CAAWC,CAAAA,CAAcC,CAAAA,CAAuB,EAAC,CAAe,CAC5E,IAAMC,CAAAA,CAAM,CAAA,EAAG,KAAK,OAAO,CAAA,EAAGF,CAAI,CAAA,CAAA,CAC5BG,CAAAA,CAAU,CACd,cAAA,CAAgB,kBAAA,CAChB,YAAa,IAAA,CAAK,MAAA,CAClB,GAAGF,CAAAA,CAAQ,OACb,CAAA,CAEMG,CAAAA,CAAW,MAAM,MAAMF,CAAAA,CAAK,CAChC,GAAGD,CAAAA,CACH,OAAA,CAAAE,CACF,CAAC,CAAA,CAED,GAAI,CAACC,CAAAA,CAAS,EAAA,CAAI,CAChB,IAAIC,CAAAA,CAAe,CAAA,qCAAA,EAAwCD,EAAS,MAAM,CAAA,CAAA,CAC1E,GAAI,CACF,IAAME,CAAAA,CAAY,MAAMF,CAAAA,CAAS,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EAEjE,OAAO,IAAA,CAAK,OAAA,CAA0B,CAAA,cAAA,EAAiBA,CAAY,CAAA,CAAE,CACvE,CAMA,MAAM,QAAA,CAASD,CAAAA,CAAmD,CAChE,GAAI,CAACA,CAAAA,CAAO,aAAA,EAAiB,CAAC,kBAAkB,IAAA,CAAKA,CAAAA,CAAO,aAAa,CAAA,CACvE,MAAM,IAAI,KAAA,CAAM,4DAA4D,CAAA,CAE9E,OAAO,IAAA,CAAK,OAAA,CAA0B,qBAAA,CAAuB,CAC3D,MAAA,CAAQ,MAAA,CACR,KAAM,IAAA,CAAK,SAAA,CAAU,CACnB,cAAA,CAAgBA,CAAAA,CAAO,aAAA,CACvB,KAAA,CAAOA,CAAAA,CAAO,OAAS,MAAA,CACvB,IAAA,CAAMA,CAAAA,CAAO,IAAA,EAAQ,IACvB,CAAC,CACH,CAAC,CACH,CACF","file":"index.js","sourcesContent":["import {\n StellarIDConfig,\n VerifyWalletResponse,\n IssueCredentialParams,\n IssueCredentialResponse,\n GetCredentialResponse,\n GetProofResponse,\n GetBadgeParams,\n GetBadgeResponse,\n} from './types';\n\nexport class StellarID {\n private apiKey: string;\n private baseURL: string;\n\n constructor(config: StellarIDConfig) {\n if (!config.apiKey) {\n throw new Error('StellarID SDK Error: apiKey is required');\n }\n this.apiKey = config.apiKey;\n // Strip trailing slash if present\n const base = config.baseURL || 'https://stellarid.io/api/v1';\n this.baseURL = base.endsWith('/') ? base.slice(0, -1) : base;\n }\n\n private async request<T>(path: string, options: RequestInit = {}): Promise<T> {\n const url = `${this.baseURL}${path}`;\n const headers = {\n 'Content-Type': 'application/json',\n 'X-API-Key': this.apiKey,\n ...options.headers,\n };\n\n const response = await fetch(url, {\n ...options,\n headers,\n });\n\n if (!response.ok) {\n let errorMessage = `StellarID request failed with status ${response.status}`;\n try {\n const errorData = await response.json();\n errorMessage = errorData.error || errorData.message || errorMessage;\n } catch (e) {\n // ignore JSON parse errors, use fallback message\n }\n throw new Error(`StellarID SDK Error: ${errorMessage}`);\n }\n\n return response.json() as Promise<T>;\n }\n\n /**\n * Verifies a Stellar wallet address, returning its reputation score, tier, and credentials.\n * @param walletAddress Valid Stellar wallet address (G...)\n */\n async verifyWallet(walletAddress: string): Promise<VerifyWalletResponse> {\n if (!walletAddress || !/^G[A-Z2-7]{55}$/.test(walletAddress)) {\n throw new Error('StellarID SDK Error: Invalid Stellar wallet address format');\n }\n return this.request<VerifyWalletResponse>(`/public/verify/${walletAddress}`);\n }\n\n /**\n * Issues a pending credential to a recipient via email.\n * @param params recipient details and credential metadata\n */\n async issueCredential(params: IssueCredentialParams): Promise<IssueCredentialResponse> {\n if (!params.recipientEmail) {\n throw new Error('StellarID SDK Error: recipientEmail is required');\n }\n if (!params.credential || !params.credential.name) {\n throw new Error('StellarID SDK Error: credential.name is required');\n }\n return this.request<IssueCredentialResponse>('/public/credentials/issue', {\n method: 'POST',\n body: JSON.stringify({\n recipient_email: params.recipientEmail,\n recipient_wallet: params.recipientWallet,\n credential: params.credential,\n }),\n });\n }\n\n /**\n * Retrieves details of a specific credential.\n * @param credentialId The unique ID of the credential\n */\n async getCredential(credentialId: string): Promise<GetCredentialResponse> {\n if (!credentialId) {\n throw new Error('StellarID SDK Error: credentialId is required');\n }\n return this.request<GetCredentialResponse>(`/public/credentials/${credentialId}`);\n }\n\n /**\n * Retrieves the ZK proof associated with a credential.\n * @param credentialId The unique ID of the credential\n */\n async getProof(credentialId: string): Promise<GetProofResponse> {\n if (!credentialId) {\n throw new Error('StellarID SDK Error: credentialId is required');\n }\n return this.request<GetProofResponse>(`/public/proof/${credentialId}`);\n }\n\n /**\n * Gets the HTML embed code and iframe URL for a wallet badge.\n * @param params parameters for styling and sizing the badge\n */\n async getBadge(params: GetBadgeParams): Promise<GetBadgeResponse> {\n if (!params.walletAddress || !/^G[A-Z2-7]{55}$/.test(params.walletAddress)) {\n throw new Error('StellarID SDK Error: Invalid Stellar wallet address format');\n }\n return this.request<GetBadgeResponse>('/public/embed/badge', {\n method: 'POST',\n body: JSON.stringify({\n wallet_address: params.walletAddress,\n style: params.style || 'dark',\n size: params.size || 'md',\n }),\n });\n }\n}\n\n// Export under alternative alias name\nexport { StellarID as StellarIDClient };\n"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ var s=class{constructor(e){if(!e.apiKey)throw new Error("StellarID SDK Error: apiKey is required");this.apiKey=e.apiKey;let r=e.baseURL||"https://stellarid.io/api/v1";this.baseURL=r.endsWith("/")?r.slice(0,-1):r;}async request(e,r={}){let l=`${this.baseURL}${e}`,n={"Content-Type":"application/json","X-API-Key":this.apiKey,...r.headers},t=await fetch(l,{...r,headers:n});if(!t.ok){let i=`StellarID request failed with status ${t.status}`;try{let a=await t.json();i=a.error||a.message||i;}catch{}throw new Error(`StellarID SDK Error: ${i}`)}return t.json()}async verifyWallet(e){if(!e||!/^G[A-Z2-7]{55}$/.test(e))throw new Error("StellarID SDK Error: Invalid Stellar wallet address format");return this.request(`/public/verify/${e}`)}async issueCredential(e){if(!e.recipientEmail)throw new Error("StellarID SDK Error: recipientEmail is required");if(!e.credential||!e.credential.name)throw new Error("StellarID SDK Error: credential.name is required");return this.request("/public/credentials/issue",{method:"POST",body:JSON.stringify({recipient_email:e.recipientEmail,recipient_wallet:e.recipientWallet,credential:e.credential})})}async getCredential(e){if(!e)throw new Error("StellarID SDK Error: credentialId is required");return this.request(`/public/credentials/${e}`)}async getProof(e){if(!e)throw new Error("StellarID SDK Error: credentialId is required");return this.request(`/public/proof/${e}`)}async getBadge(e){if(!e.walletAddress||!/^G[A-Z2-7]{55}$/.test(e.walletAddress))throw new Error("StellarID SDK Error: Invalid Stellar wallet address format");return this.request("/public/embed/badge",{method:"POST",body:JSON.stringify({wallet_address:e.walletAddress,style:e.style||"dark",size:e.size||"md"})})}};
2
+ export{s as StellarID,s as StellarIDClient};//# sourceMappingURL=index.mjs.map
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts"],"names":["StellarID","config","base","path","options","url","headers","response","errorMessage","errorData","walletAddress","params","credentialId"],"mappings":"AAWO,IAAMA,CAAAA,CAAN,KAAgB,CAIrB,WAAA,CAAYC,CAAAA,CAAyB,CACnC,GAAI,CAACA,CAAAA,CAAO,MAAA,CACV,MAAM,IAAI,MAAM,yCAAyC,CAAA,CAE3D,IAAA,CAAK,MAAA,CAASA,CAAAA,CAAO,MAAA,CAErB,IAAMC,CAAAA,CAAOD,EAAO,OAAA,EAAW,6BAAA,CAC/B,IAAA,CAAK,OAAA,CAAUC,CAAAA,CAAK,QAAA,CAAS,GAAG,CAAA,CAAIA,EAAK,KAAA,CAAM,CAAA,CAAG,EAAE,CAAA,CAAIA,EAC1D,CAEA,MAAc,OAAA,CAAWC,CAAAA,CAAcC,CAAAA,CAAuB,EAAC,CAAe,CAC5E,IAAMC,CAAAA,CAAM,CAAA,EAAG,KAAK,OAAO,CAAA,EAAGF,CAAI,CAAA,CAAA,CAC5BG,CAAAA,CAAU,CACd,cAAA,CAAgB,kBAAA,CAChB,YAAa,IAAA,CAAK,MAAA,CAClB,GAAGF,CAAAA,CAAQ,OACb,CAAA,CAEMG,CAAAA,CAAW,MAAM,MAAMF,CAAAA,CAAK,CAChC,GAAGD,CAAAA,CACH,OAAA,CAAAE,CACF,CAAC,CAAA,CAED,GAAI,CAACC,CAAAA,CAAS,EAAA,CAAI,CAChB,IAAIC,CAAAA,CAAe,CAAA,qCAAA,EAAwCD,EAAS,MAAM,CAAA,CAAA,CAC1E,GAAI,CACF,IAAME,CAAAA,CAAY,MAAMF,CAAAA,CAAS,MAAK,CACtCC,CAAAA,CAAeC,CAAAA,CAAU,KAAA,EAASA,CAAAA,CAAU,OAAA,EAAWD,EACzD,CAAA,KAAY,CAEZ,CACA,MAAM,IAAI,KAAA,CAAM,CAAA,qBAAA,EAAwBA,CAAY,CAAA,CAAE,CACxD,CAEA,OAAOD,CAAAA,CAAS,IAAA,EAClB,CAMA,MAAM,YAAA,CAAaG,EAAsD,CACv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4D,CAAA,CAE9E,OAAO,IAAA,CAAK,OAAA,CAA0B,qBAAA,CAAuB,CAC3D,MAAA,CAAQ,MAAA,CACR,KAAM,IAAA,CAAK,SAAA,CAAU,CACnB,cAAA,CAAgBA,CAAAA,CAAO,aAAA,CACvB,KAAA,CAAOA,CAAAA,CAAO,OAAS,MAAA,CACvB,IAAA,CAAMA,CAAAA,CAAO,IAAA,EAAQ,IACvB,CAAC,CACH,CAAC,CACH,CACF","file":"index.mjs","sourcesContent":["import {\n StellarIDConfig,\n VerifyWalletResponse,\n IssueCredentialParams,\n IssueCredentialResponse,\n GetCredentialResponse,\n GetProofResponse,\n GetBadgeParams,\n GetBadgeResponse,\n} from './types';\n\nexport class StellarID {\n private apiKey: string;\n private baseURL: string;\n\n constructor(config: StellarIDConfig) {\n if (!config.apiKey) {\n throw new Error('StellarID SDK Error: apiKey is required');\n }\n this.apiKey = config.apiKey;\n // Strip trailing slash if present\n const base = config.baseURL || 'https://stellarid.io/api/v1';\n this.baseURL = base.endsWith('/') ? base.slice(0, -1) : base;\n }\n\n private async request<T>(path: string, options: RequestInit = {}): Promise<T> {\n const url = `${this.baseURL}${path}`;\n const headers = {\n 'Content-Type': 'application/json',\n 'X-API-Key': this.apiKey,\n ...options.headers,\n };\n\n const response = await fetch(url, {\n ...options,\n headers,\n });\n\n if (!response.ok) {\n let errorMessage = `StellarID request failed with status ${response.status}`;\n try {\n const errorData = await response.json();\n errorMessage = errorData.error || errorData.message || errorMessage;\n } catch (e) {\n // ignore JSON parse errors, use fallback message\n }\n throw new Error(`StellarID SDK Error: ${errorMessage}`);\n }\n\n return response.json() as Promise<T>;\n }\n\n /**\n * Verifies a Stellar wallet address, returning its reputation score, tier, and credentials.\n * @param walletAddress Valid Stellar wallet address (G...)\n */\n async verifyWallet(walletAddress: string): Promise<VerifyWalletResponse> {\n if (!walletAddress || !/^G[A-Z2-7]{55}$/.test(walletAddress)) {\n throw new Error('StellarID SDK Error: Invalid Stellar wallet address format');\n }\n return this.request<VerifyWalletResponse>(`/public/verify/${walletAddress}`);\n }\n\n /**\n * Issues a pending credential to a recipient via email.\n * @param params recipient details and credential metadata\n */\n async issueCredential(params: IssueCredentialParams): Promise<IssueCredentialResponse> {\n if (!params.recipientEmail) {\n throw new Error('StellarID SDK Error: recipientEmail is required');\n }\n if (!params.credential || !params.credential.name) {\n throw new Error('StellarID SDK Error: credential.name is required');\n }\n return this.request<IssueCredentialResponse>('/public/credentials/issue', {\n method: 'POST',\n body: JSON.stringify({\n recipient_email: params.recipientEmail,\n recipient_wallet: params.recipientWallet,\n credential: params.credential,\n }),\n });\n }\n\n /**\n * Retrieves details of a specific credential.\n * @param credentialId The unique ID of the credential\n */\n async getCredential(credentialId: string): Promise<GetCredentialResponse> {\n if (!credentialId) {\n throw new Error('StellarID SDK Error: credentialId is required');\n }\n return this.request<GetCredentialResponse>(`/public/credentials/${credentialId}`);\n }\n\n /**\n * Retrieves the ZK proof associated with a credential.\n * @param credentialId The unique ID of the credential\n */\n async getProof(credentialId: string): Promise<GetProofResponse> {\n if (!credentialId) {\n throw new Error('StellarID SDK Error: credentialId is required');\n }\n return this.request<GetProofResponse>(`/public/proof/${credentialId}`);\n }\n\n /**\n * Gets the HTML embed code and iframe URL for a wallet badge.\n * @param params parameters for styling and sizing the badge\n */\n async getBadge(params: GetBadgeParams): Promise<GetBadgeResponse> {\n if (!params.walletAddress || !/^G[A-Z2-7]{55}$/.test(params.walletAddress)) {\n throw new Error('StellarID SDK Error: Invalid Stellar wallet address format');\n }\n return this.request<GetBadgeResponse>('/public/embed/badge', {\n method: 'POST',\n body: JSON.stringify({\n wallet_address: params.walletAddress,\n style: params.style || 'dark',\n size: params.size || 'md',\n }),\n });\n }\n}\n\n// Export under alternative alias name\nexport { StellarID as StellarIDClient };\n"]}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "stellarid-sdk",
3
+ "version": "1.0.0",
4
+ "description": "Official JavaScript SDK for StellarID, the protocol-grade identity layer on Stellar.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "require": "./dist/index.js",
12
+ "import": "./dist/index.mjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup",
20
+ "dev": "tsup --watch",
21
+ "test": "jest",
22
+ "test:watch": "jest --watch"
23
+ },
24
+ "keywords": [
25
+ "stellar",
26
+ "identity",
27
+ "sdk",
28
+ "zk-proof",
29
+ "verification",
30
+ "blockchain",
31
+ "did"
32
+ ],
33
+ "author": "StellarID Team",
34
+ "license": "MIT",
35
+ "devDependencies": {
36
+ "@types/jest": "^29.5.12",
37
+ "@types/node": "^20.11.24",
38
+ "jest": "^29.7.0",
39
+ "ts-jest": "^29.1.2",
40
+ "tsup": "^8.0.2",
41
+ "typescript": "^5.3.3"
42
+ }
43
+ }