@profullstack/coinpay 0.5.1 → 0.5.3
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/bin/coinpay.js +59 -1
- package/package.json +1 -1
- package/src/reputation.d.ts +11 -0
- package/src/reputation.js +40 -0
package/bin/coinpay.js
CHANGED
|
@@ -1727,9 +1727,67 @@ async function handleReputation(subcommand, args, flags) {
|
|
|
1727
1727
|
break;
|
|
1728
1728
|
}
|
|
1729
1729
|
|
|
1730
|
+
case 'did': {
|
|
1731
|
+
const didSubcommand = args[0];
|
|
1732
|
+
const client = createClient();
|
|
1733
|
+
|
|
1734
|
+
if (didSubcommand === 'claim') {
|
|
1735
|
+
const { claimDid } = await import('../src/reputation.js');
|
|
1736
|
+
const result = await claimDid(client);
|
|
1737
|
+
|
|
1738
|
+
if (result.did) {
|
|
1739
|
+
print.success(`DID claimed: ${result.did}`);
|
|
1740
|
+
console.log(` Public Key: ${result.public_key}`);
|
|
1741
|
+
console.log(` Verified: ${result.verified}`);
|
|
1742
|
+
} else {
|
|
1743
|
+
print.error(result.error || 'Failed to claim DID');
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
if (flags.json) print.json(result);
|
|
1747
|
+
} else if (didSubcommand === 'link') {
|
|
1748
|
+
const didValue = flags.did;
|
|
1749
|
+
const publicKey = flags['public-key'];
|
|
1750
|
+
const signature = flags.signature;
|
|
1751
|
+
|
|
1752
|
+
if (!didValue || !publicKey || !signature) {
|
|
1753
|
+
print.error('Required: --did <did> --public-key <key> --signature <sig>');
|
|
1754
|
+
print.info('Usage: coinpay reputation did link --did <did> --public-key <key> --signature <sig>');
|
|
1755
|
+
break;
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
const { linkDid } = await import('../src/reputation.js');
|
|
1759
|
+
const result = await linkDid(client, { did: didValue, publicKey, signature });
|
|
1760
|
+
|
|
1761
|
+
if (result.did) {
|
|
1762
|
+
print.success(`DID linked: ${result.did}`);
|
|
1763
|
+
console.log(` Verified: ${result.verified}`);
|
|
1764
|
+
} else {
|
|
1765
|
+
print.error(result.error || 'Failed to link DID');
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
if (flags.json) print.json(result);
|
|
1769
|
+
} else {
|
|
1770
|
+
// Default: show current DID
|
|
1771
|
+
const { getMyDid } = await import('../src/reputation.js');
|
|
1772
|
+
const result = await getMyDid(client);
|
|
1773
|
+
|
|
1774
|
+
if (result.did) {
|
|
1775
|
+
print.success(`Your DID: ${result.did}`);
|
|
1776
|
+
console.log(` Public Key: ${result.public_key}`);
|
|
1777
|
+
console.log(` Verified: ${result.verified}`);
|
|
1778
|
+
console.log(` Created: ${result.created_at}`);
|
|
1779
|
+
} else {
|
|
1780
|
+
print.info('No DID found. Run: coinpay reputation did claim');
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
if (flags.json) print.json(result);
|
|
1784
|
+
}
|
|
1785
|
+
break;
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1730
1788
|
default:
|
|
1731
1789
|
print.error(`Unknown reputation command: ${subcommand}`);
|
|
1732
|
-
print.info('Available: submit, query, credential, verify, revocations');
|
|
1790
|
+
print.info('Available: submit, query, credential, verify, revocations, did');
|
|
1733
1791
|
process.exit(1);
|
|
1734
1792
|
}
|
|
1735
1793
|
}
|
package/package.json
CHANGED
package/src/reputation.d.ts
CHANGED
|
@@ -69,3 +69,14 @@ export function getReputation(client: CoinPayClient, agentDid: string): Promise<
|
|
|
69
69
|
export function getCredential(client: CoinPayClient, credentialId: string): Promise<{ success: boolean; credential: Credential }>;
|
|
70
70
|
export function verifyCredential(client: CoinPayClient, credential: { credential_id: string }): Promise<{ valid: boolean; reason?: string }>;
|
|
71
71
|
export function getRevocationList(client: CoinPayClient): Promise<{ success: boolean; revoked_credentials: string[]; revocations: Array<Record<string, unknown>> }>;
|
|
72
|
+
|
|
73
|
+
export interface DidInfo {
|
|
74
|
+
did: string;
|
|
75
|
+
public_key: string;
|
|
76
|
+
verified: boolean;
|
|
77
|
+
created_at: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function getMyDid(client: CoinPayClient): Promise<DidInfo>;
|
|
81
|
+
export function claimDid(client: CoinPayClient): Promise<DidInfo>;
|
|
82
|
+
export function linkDid(client: CoinPayClient, params: { did: string; publicKey: string; signature: string }): Promise<DidInfo>;
|
package/src/reputation.js
CHANGED
|
@@ -62,3 +62,43 @@ export async function verifyCredential(client, credential) {
|
|
|
62
62
|
export async function getRevocationList(client) {
|
|
63
63
|
return client.request('/reputation/revocation-list');
|
|
64
64
|
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get the authenticated merchant's DID
|
|
68
|
+
* @param {import('./client.js').CoinPayClient} client
|
|
69
|
+
* @returns {Promise<Object>}
|
|
70
|
+
*/
|
|
71
|
+
export async function getMyDid(client) {
|
|
72
|
+
return client.request('/reputation/did/me');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Claim (auto-generate) a new DID for the authenticated merchant
|
|
77
|
+
* @param {import('./client.js').CoinPayClient} client
|
|
78
|
+
* @returns {Promise<Object>}
|
|
79
|
+
*/
|
|
80
|
+
export async function claimDid(client) {
|
|
81
|
+
return client.request('/reputation/did/claim', {
|
|
82
|
+
method: 'POST',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Link an existing DID to the authenticated merchant
|
|
88
|
+
* @param {import('./client.js').CoinPayClient} client
|
|
89
|
+
* @param {Object} params
|
|
90
|
+
* @param {string} params.did - The DID to link
|
|
91
|
+
* @param {string} params.publicKey - Base64url-encoded public key
|
|
92
|
+
* @param {string} params.signature - Base64url-encoded signature
|
|
93
|
+
* @returns {Promise<Object>}
|
|
94
|
+
*/
|
|
95
|
+
export async function linkDid(client, { did, publicKey, signature }) {
|
|
96
|
+
return client.request('/reputation/did/claim', {
|
|
97
|
+
method: 'POST',
|
|
98
|
+
body: JSON.stringify({
|
|
99
|
+
did,
|
|
100
|
+
public_key: publicKey,
|
|
101
|
+
signature,
|
|
102
|
+
}),
|
|
103
|
+
});
|
|
104
|
+
}
|