@hauska-sdk/vda 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/CHANGELOG.md +21 -0
- package/README.md +655 -0
- package/dist/VDASDK.d.ts +158 -0
- package/dist/VDASDK.d.ts.map +1 -0
- package/dist/VDASDK.js +284 -0
- package/dist/VDASDK.js.map +1 -0
- package/dist/access-pass.d.ts +96 -0
- package/dist/access-pass.d.ts.map +1 -0
- package/dist/access-pass.js +137 -0
- package/dist/access-pass.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/minting.d.ts +101 -0
- package/dist/minting.d.ts.map +1 -0
- package/dist/minting.js +104 -0
- package/dist/minting.js.map +1 -0
- package/dist/ownership-transfer.d.ts +50 -0
- package/dist/ownership-transfer.d.ts.map +1 -0
- package/dist/ownership-transfer.js +74 -0
- package/dist/ownership-transfer.js.map +1 -0
- package/dist/ownership.d.ts +72 -0
- package/dist/ownership.d.ts.map +1 -0
- package/dist/ownership.js +138 -0
- package/dist/ownership.js.map +1 -0
- package/dist/search.d.ts +59 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +79 -0
- package/dist/search.js.map +1 -0
- package/dist/types.d.ts +144 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/validation.d.ts +33 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +203 -0
- package/dist/validation.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hauska-sdk/vda
|
|
3
|
+
* Access Pass Creation Implementation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Access Pass Creation Service
|
|
7
|
+
*/
|
|
8
|
+
export class AccessPassService {
|
|
9
|
+
mintingService;
|
|
10
|
+
storageAdapter;
|
|
11
|
+
walletManager;
|
|
12
|
+
constructor(mintingService, storageAdapter, walletManager) {
|
|
13
|
+
this.mintingService = mintingService;
|
|
14
|
+
this.storageAdapter = storageAdapter;
|
|
15
|
+
this.walletManager = walletManager;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create an access pass VDA
|
|
19
|
+
*
|
|
20
|
+
* @param params - Access pass creation parameters
|
|
21
|
+
* @returns The created access pass VDA
|
|
22
|
+
* @throws Error if validation fails or grantor doesn't own accessible VDAs
|
|
23
|
+
*/
|
|
24
|
+
async createAccessPass(params) {
|
|
25
|
+
// Validate expiry is in the future
|
|
26
|
+
if (params.expiry <= Date.now()) {
|
|
27
|
+
throw new Error("Expiry must be in the future");
|
|
28
|
+
}
|
|
29
|
+
// Validate permissions array is not empty
|
|
30
|
+
if (!params.permissions || params.permissions.length === 0) {
|
|
31
|
+
throw new Error("Permissions array is required and cannot be empty");
|
|
32
|
+
}
|
|
33
|
+
// Validate accessibleVDAs array is not empty
|
|
34
|
+
if (!params.accessibleVDAs || params.accessibleVDAs.length === 0) {
|
|
35
|
+
throw new Error("Accessible VDAs array is required and cannot be empty");
|
|
36
|
+
}
|
|
37
|
+
// Verify grantor owns all accessible VDAs
|
|
38
|
+
await this.verifyGrantorOwnership(params.grantorWallet, params.accessibleVDAs);
|
|
39
|
+
// Auto-create wallet for recipient if not provided
|
|
40
|
+
let recipientWallet = params.recipientWallet;
|
|
41
|
+
if (!recipientWallet) {
|
|
42
|
+
if (!params.userId || !params.password) {
|
|
43
|
+
throw new Error("Either recipientWallet must be provided, or both userId and password must be provided for automatic wallet creation");
|
|
44
|
+
}
|
|
45
|
+
// Get or create wallet
|
|
46
|
+
const wallet = await this.walletManager.getOrCreateWallet(params.userId, params.password);
|
|
47
|
+
recipientWallet = wallet.address;
|
|
48
|
+
}
|
|
49
|
+
// Create access pass VDA using minting service
|
|
50
|
+
const accessPassVDA = await this.mintingService.mint({
|
|
51
|
+
assetType: "access-pass",
|
|
52
|
+
grantorWallet: params.grantorWallet,
|
|
53
|
+
ownerWallet: recipientWallet,
|
|
54
|
+
spoke: params.spoke,
|
|
55
|
+
address: params.address,
|
|
56
|
+
legalDesc: params.legalDesc,
|
|
57
|
+
patientId: params.patientId,
|
|
58
|
+
api14: params.api14,
|
|
59
|
+
expiry: params.expiry,
|
|
60
|
+
accessibleVDAs: params.accessibleVDAs,
|
|
61
|
+
permissions: params.permissions,
|
|
62
|
+
metadata: params.metadata,
|
|
63
|
+
userId: params.userId,
|
|
64
|
+
password: params.password,
|
|
65
|
+
});
|
|
66
|
+
return accessPassVDA;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Verify that grantor owns all accessible VDAs
|
|
70
|
+
*
|
|
71
|
+
* @param grantorWallet - Grantor wallet address
|
|
72
|
+
* @param accessibleVDAs - Array of VDA IDs to verify
|
|
73
|
+
* @throws Error if grantor doesn't own any of the VDAs
|
|
74
|
+
*/
|
|
75
|
+
async verifyGrantorOwnership(grantorWallet, accessibleVDAs) {
|
|
76
|
+
const missingOwnership = [];
|
|
77
|
+
for (const vdaId of accessibleVDAs) {
|
|
78
|
+
const vda = await this.storageAdapter.getVDA(vdaId);
|
|
79
|
+
if (!vda) {
|
|
80
|
+
throw new Error(`VDA ${vdaId} not found`);
|
|
81
|
+
}
|
|
82
|
+
if (vda.metadata.ownerWallet !== grantorWallet) {
|
|
83
|
+
missingOwnership.push(vdaId);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (missingOwnership.length > 0) {
|
|
87
|
+
throw new Error(`Grantor does not own the following VDAs: ${missingOwnership.join(", ")}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Revoke an access pass
|
|
92
|
+
*
|
|
93
|
+
* @param accessPassId - Access pass VDA ID
|
|
94
|
+
* @param grantorWallet - Grantor wallet address (must match)
|
|
95
|
+
* @returns The revoked access pass VDA
|
|
96
|
+
* @throws Error if grantor doesn't match or access pass not found
|
|
97
|
+
*/
|
|
98
|
+
async revokeAccessPass(accessPassId, grantorWallet) {
|
|
99
|
+
// Get the access pass
|
|
100
|
+
const accessPass = await this.storageAdapter.getVDA(accessPassId);
|
|
101
|
+
if (!accessPass) {
|
|
102
|
+
throw new Error(`Access pass ${accessPassId} not found`);
|
|
103
|
+
}
|
|
104
|
+
// Verify it's an access pass
|
|
105
|
+
if (accessPass.metadata.assetType !== "access-pass") {
|
|
106
|
+
throw new Error(`VDA ${accessPassId} is not an access pass`);
|
|
107
|
+
}
|
|
108
|
+
// Verify grantor matches
|
|
109
|
+
if (accessPass.metadata.grantorWallet !== grantorWallet) {
|
|
110
|
+
throw new Error(`Grantor mismatch. Expected ${grantorWallet}, but access pass was granted by ${accessPass.metadata.grantorWallet}`);
|
|
111
|
+
}
|
|
112
|
+
// Check if already revoked
|
|
113
|
+
if (accessPass.metadata.revoked) {
|
|
114
|
+
throw new Error(`Access pass ${accessPassId} is already revoked`);
|
|
115
|
+
}
|
|
116
|
+
// Mark as revoked by setting revoked flag and revokedAt timestamp
|
|
117
|
+
// We'll update the expiry to past and set revoked flag
|
|
118
|
+
const now = Date.now();
|
|
119
|
+
accessPass.metadata.revoked = true;
|
|
120
|
+
accessPass.metadata.revokedAt = now;
|
|
121
|
+
accessPass.metadata.expiry = now - 1; // Set to past to ensure it's expired
|
|
122
|
+
accessPass.metadata.updatedAt = now;
|
|
123
|
+
// Update in storage
|
|
124
|
+
await this.storageAdapter.createVDA(accessPass);
|
|
125
|
+
return accessPass;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get access passes owned by a wallet
|
|
129
|
+
*
|
|
130
|
+
* @param wallet - Wallet address
|
|
131
|
+
* @returns Array of access pass VDAs
|
|
132
|
+
*/
|
|
133
|
+
async getAccessPassesByOwner(wallet) {
|
|
134
|
+
return this.storageAdapter.listAccessPassesByOwner(wallet);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=access-pass.js.map
|
|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UAAU,CAAC,QAAQ,CAAC,SAAS,GAAG,GAAG,CAAC;QACpC,UAAU,CAAC,QAAQ,CAAC,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,qCAAqC;QAC3E,UAAU,CAAC,QAAQ,CAAC,SAAS,GAAG,GAAG,CAAC;QAEpC,oBAAoB;QACpB,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAEhD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,sBAAsB,CAAC,MAAc;QACzC,OAAO,IAAI,CAAC,cAAc,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC;CAEF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hauska-sdk/vda
|
|
3
|
+
* CNS Protocol VDA SDK - Verified Digital Assets management
|
|
4
|
+
*/
|
|
5
|
+
export type { VDA, VDAMetadata, AssetType, SpokeType, PermissionType, MintVDAParams, ValidationError, } from "./types";
|
|
6
|
+
export { validateVDAMetadata, normalizeAddress, hasRequiredUniversalKey, VALID_ASSET_TYPES, VALID_SPOKE_TYPES, VALID_PERMISSION_TYPES, } from "./validation";
|
|
7
|
+
export { VDASearchService } from "./search";
|
|
8
|
+
export type { VDASearchConfig } from "./search";
|
|
9
|
+
export type { SearchOptions, SearchResult } from "./minting";
|
|
10
|
+
export { VDAMintingService } from "./minting";
|
|
11
|
+
export type { VDAStorageAdapter, VDAMintingConfig } from "./minting";
|
|
12
|
+
export { AccessPassService } from "./access-pass";
|
|
13
|
+
export type { CreateAccessPassParams } from "./access-pass";
|
|
14
|
+
export { OwnershipVerificationService } from "./ownership";
|
|
15
|
+
export type { OwnershipVerificationResult } from "./ownership";
|
|
16
|
+
export { OwnershipTransferService } from "./ownership-transfer";
|
|
17
|
+
export type { TransferOwnershipParams } from "./ownership-transfer";
|
|
18
|
+
export { VDASDK } from "./VDASDK";
|
|
19
|
+
export type { VDASDKConfig, LogHook } from "./VDASDK";
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EACV,GAAG,EACH,WAAW,EACX,SAAS,EACT,SAAS,EACT,cAAc,EACd,aAAa,EACb,eAAe,GAChB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAErE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAC3D,YAAY,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,YAAY,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAEpE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hauska-sdk/vda
|
|
3
|
+
* CNS Protocol VDA SDK - Verified Digital Assets management
|
|
4
|
+
*/
|
|
5
|
+
export { validateVDAMetadata, normalizeAddress, hasRequiredUniversalKey, VALID_ASSET_TYPES, VALID_SPOKE_TYPES, VALID_PERMISSION_TYPES, } from "./validation";
|
|
6
|
+
export { VDASearchService } from "./search";
|
|
7
|
+
export { VDAMintingService } from "./minting";
|
|
8
|
+
export { AccessPassService } from "./access-pass";
|
|
9
|
+
export { OwnershipVerificationService } from "./ownership";
|
|
10
|
+
export { OwnershipTransferService } from "./ownership-transfer";
|
|
11
|
+
export { VDASDK } from "./VDASDK";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAI5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAG3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAGhE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hauska-sdk/vda
|
|
3
|
+
* VDA Minting Implementation
|
|
4
|
+
*/
|
|
5
|
+
import type { WalletManager } from "@hauska-sdk/wallet";
|
|
6
|
+
import type { VDA } from "./types";
|
|
7
|
+
import type { MintVDAParams } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* Storage adapter interface for VDA operations
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Search options for pagination
|
|
13
|
+
*/
|
|
14
|
+
export interface SearchOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Maximum number of results to return
|
|
17
|
+
*/
|
|
18
|
+
limit?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Number of results to skip (for pagination)
|
|
21
|
+
*/
|
|
22
|
+
offset?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Search result with pagination metadata
|
|
26
|
+
*/
|
|
27
|
+
export interface SearchResult {
|
|
28
|
+
/**
|
|
29
|
+
* Array of VDAs matching the search
|
|
30
|
+
*/
|
|
31
|
+
results: VDA[];
|
|
32
|
+
/**
|
|
33
|
+
* Total number of results (before pagination)
|
|
34
|
+
*/
|
|
35
|
+
total: number;
|
|
36
|
+
/**
|
|
37
|
+
* Current page offset
|
|
38
|
+
*/
|
|
39
|
+
offset: number;
|
|
40
|
+
/**
|
|
41
|
+
* Current page limit
|
|
42
|
+
*/
|
|
43
|
+
limit: number;
|
|
44
|
+
}
|
|
45
|
+
export interface VDAStorageAdapter {
|
|
46
|
+
createVDA(vda: VDA): Promise<VDA>;
|
|
47
|
+
getVDA(vdaId: string): Promise<VDA | null>;
|
|
48
|
+
listVDAsByOwner(wallet: string): Promise<VDA[]>;
|
|
49
|
+
listAccessPassesByOwner(wallet: string): Promise<VDA[]>;
|
|
50
|
+
transferOwnership(vdaId: string, newOwner: string): Promise<void>;
|
|
51
|
+
indexByAddress(address: string, vdaId: string): Promise<void>;
|
|
52
|
+
indexByPatientId(patientId: string, vdaId: string): Promise<void>;
|
|
53
|
+
indexByAPI14(api14: string, vdaId: string): Promise<void>;
|
|
54
|
+
searchByAddress(address: string, options?: SearchOptions): Promise<SearchResult>;
|
|
55
|
+
searchByPatientId(patientId: string, options?: SearchOptions): Promise<SearchResult>;
|
|
56
|
+
searchByAPI14(api14: string, options?: SearchOptions): Promise<SearchResult>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Configuration for VDA minting
|
|
60
|
+
*/
|
|
61
|
+
export interface VDAMintingConfig {
|
|
62
|
+
/**
|
|
63
|
+
* Storage adapter for persisting VDAs
|
|
64
|
+
*/
|
|
65
|
+
storageAdapter: VDAStorageAdapter;
|
|
66
|
+
/**
|
|
67
|
+
* Wallet manager for automatic wallet creation
|
|
68
|
+
*/
|
|
69
|
+
walletManager: WalletManager;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* VDA Minting Service
|
|
73
|
+
*/
|
|
74
|
+
export declare class VDAMintingService {
|
|
75
|
+
private storageAdapter;
|
|
76
|
+
private walletManager;
|
|
77
|
+
constructor(config: VDAMintingConfig);
|
|
78
|
+
/**
|
|
79
|
+
* Mint a new VDA
|
|
80
|
+
*
|
|
81
|
+
* @param params - Minting parameters
|
|
82
|
+
* @returns The created VDA
|
|
83
|
+
* @throws Error if validation fails or minting fails
|
|
84
|
+
*/
|
|
85
|
+
mint(params: MintVDAParams): Promise<VDA>;
|
|
86
|
+
/**
|
|
87
|
+
* Get a VDA by ID
|
|
88
|
+
*
|
|
89
|
+
* @param vdaId - VDA ID
|
|
90
|
+
* @returns The VDA or null if not found
|
|
91
|
+
*/
|
|
92
|
+
getVDA(vdaId: string): Promise<VDA | null>;
|
|
93
|
+
/**
|
|
94
|
+
* List VDAs by owner wallet
|
|
95
|
+
*
|
|
96
|
+
* @param wallet - Owner wallet address
|
|
97
|
+
* @returns Array of VDAs owned by the wallet
|
|
98
|
+
*/
|
|
99
|
+
listVDAsByOwner(wallet: string): Promise<VDA[]>;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=minting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minting.d.ts","sourceRoot":"","sources":["../src/minting.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,GAAG,EAAe,MAAM,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AAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACjF,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACrF,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC9E;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,cAAc,EAAE,iBAAiB,CAAC;IAElC;;OAEG;IACH,aAAa,EAAE,aAAa,CAAC;CAC9B;AAED;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,cAAc,CAAoB;IAC1C,OAAO,CAAC,aAAa,CAAgB;gBAEzB,MAAM,EAAE,gBAAgB;IAKpC;;;;;;OAMG;IACG,IAAI,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC;IA4E/C;;;;;OAKG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;IAIhD;;;;;OAKG;IACG,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;CAGtD"}
|
package/dist/minting.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hauska-sdk/vda
|
|
3
|
+
* VDA Minting Implementation
|
|
4
|
+
*/
|
|
5
|
+
import { randomUUID } from "crypto";
|
|
6
|
+
import { validateVDAMetadata } from "./validation";
|
|
7
|
+
/**
|
|
8
|
+
* VDA Minting Service
|
|
9
|
+
*/
|
|
10
|
+
export class VDAMintingService {
|
|
11
|
+
storageAdapter;
|
|
12
|
+
walletManager;
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.storageAdapter = config.storageAdapter;
|
|
15
|
+
this.walletManager = config.walletManager;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Mint a new VDA
|
|
19
|
+
*
|
|
20
|
+
* @param params - Minting parameters
|
|
21
|
+
* @returns The created VDA
|
|
22
|
+
* @throws Error if validation fails or minting fails
|
|
23
|
+
*/
|
|
24
|
+
async mint(params) {
|
|
25
|
+
// Auto-create wallet if ownerWallet not provided
|
|
26
|
+
let ownerWallet = params.ownerWallet;
|
|
27
|
+
if (!ownerWallet) {
|
|
28
|
+
if (!params.userId || !params.password) {
|
|
29
|
+
throw new Error("Either ownerWallet must be provided, or both userId and password must be provided for automatic wallet creation");
|
|
30
|
+
}
|
|
31
|
+
// Get or create wallet
|
|
32
|
+
const wallet = await this.walletManager.getOrCreateWallet(params.userId, params.password);
|
|
33
|
+
ownerWallet = wallet.address;
|
|
34
|
+
}
|
|
35
|
+
// Generate VDA ID (UUID)
|
|
36
|
+
const vdaId = randomUUID();
|
|
37
|
+
const assetId = params.assetId || randomUUID();
|
|
38
|
+
// Create metadata object
|
|
39
|
+
const now = Date.now();
|
|
40
|
+
const metadata = {
|
|
41
|
+
assetId,
|
|
42
|
+
assetType: params.assetType,
|
|
43
|
+
address: params.address,
|
|
44
|
+
legalDesc: params.legalDesc,
|
|
45
|
+
patientId: params.patientId,
|
|
46
|
+
api14: params.api14,
|
|
47
|
+
ownerWallet,
|
|
48
|
+
grantorWallet: params.grantorWallet,
|
|
49
|
+
spoke: params.spoke,
|
|
50
|
+
ipfsCid: params.ipfsCid,
|
|
51
|
+
expiry: params.expiry,
|
|
52
|
+
accessibleVDAs: params.accessibleVDAs,
|
|
53
|
+
permissions: params.permissions,
|
|
54
|
+
metadata: params.metadata,
|
|
55
|
+
createdAt: now,
|
|
56
|
+
updatedAt: now,
|
|
57
|
+
};
|
|
58
|
+
// Validate metadata
|
|
59
|
+
const validation = validateVDAMetadata(metadata);
|
|
60
|
+
if (!validation.valid) {
|
|
61
|
+
const errorMessages = validation.errors
|
|
62
|
+
.map((e) => `${e.field}: ${e.message}`)
|
|
63
|
+
.join(", ");
|
|
64
|
+
throw new Error(`Invalid VDA metadata: ${errorMessages}`);
|
|
65
|
+
}
|
|
66
|
+
// Create VDA object
|
|
67
|
+
const vda = {
|
|
68
|
+
id: vdaId,
|
|
69
|
+
metadata,
|
|
70
|
+
};
|
|
71
|
+
// Store in database via storage adapter
|
|
72
|
+
const createdVDA = await this.storageAdapter.createVDA(vda);
|
|
73
|
+
// Index by universal keys (storage adapter should handle this, but we ensure it)
|
|
74
|
+
if (metadata.address) {
|
|
75
|
+
await this.storageAdapter.indexByAddress(metadata.address, vdaId);
|
|
76
|
+
}
|
|
77
|
+
if (metadata.patientId) {
|
|
78
|
+
await this.storageAdapter.indexByPatientId(metadata.patientId, vdaId);
|
|
79
|
+
}
|
|
80
|
+
if (metadata.api14) {
|
|
81
|
+
await this.storageAdapter.indexByAPI14(metadata.api14, vdaId);
|
|
82
|
+
}
|
|
83
|
+
return createdVDA;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get a VDA by ID
|
|
87
|
+
*
|
|
88
|
+
* @param vdaId - VDA ID
|
|
89
|
+
* @returns The VDA or null if not found
|
|
90
|
+
*/
|
|
91
|
+
async getVDA(vdaId) {
|
|
92
|
+
return this.storageAdapter.getVDA(vdaId);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* List VDAs by owner wallet
|
|
96
|
+
*
|
|
97
|
+
* @param wallet - Owner wallet address
|
|
98
|
+
* @returns Array of VDAs owned by the wallet
|
|
99
|
+
*/
|
|
100
|
+
async listVDAsByOwner(wallet) {
|
|
101
|
+
return this.storageAdapter.listVDAsByOwner(wallet);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=minting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minting.js","sourceRoot":"","sources":["../src/minting.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAIpC,OAAO,EAAE,mBAAmB,EAAE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CAAC,CAAC;QAChE,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,MAAM,CAAC,KAAa;QACxB,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,eAAe,CAAC,MAAc;QAClC,OAAO,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hauska-sdk/vda
|
|
3
|
+
* Ownership Transfer Implementation
|
|
4
|
+
*/
|
|
5
|
+
import type { VDA } from "./types";
|
|
6
|
+
import type { VDAStorageAdapter } from "./minting";
|
|
7
|
+
/**
|
|
8
|
+
* Options for transferring ownership
|
|
9
|
+
*/
|
|
10
|
+
export interface TransferOwnershipParams {
|
|
11
|
+
/**
|
|
12
|
+
* VDA ID to transfer
|
|
13
|
+
*/
|
|
14
|
+
vdaId: string;
|
|
15
|
+
/**
|
|
16
|
+
* Current owner wallet address (must match)
|
|
17
|
+
*/
|
|
18
|
+
currentOwner: string;
|
|
19
|
+
/**
|
|
20
|
+
* New owner wallet address
|
|
21
|
+
*/
|
|
22
|
+
newOwner: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Ownership Transfer Service
|
|
26
|
+
*/
|
|
27
|
+
export declare class OwnershipTransferService {
|
|
28
|
+
private storageAdapter;
|
|
29
|
+
constructor(storageAdapter: VDAStorageAdapter);
|
|
30
|
+
/**
|
|
31
|
+
* Transfer ownership of a VDA from one wallet to another
|
|
32
|
+
*
|
|
33
|
+
* @param params - Transfer ownership parameters
|
|
34
|
+
* @returns The updated VDA
|
|
35
|
+
* @throws Error if current owner doesn't match or VDA not found
|
|
36
|
+
*/
|
|
37
|
+
transferOwnership(params: TransferOwnershipParams): Promise<VDA>;
|
|
38
|
+
/**
|
|
39
|
+
* Transfer ownership without verification (use with caution)
|
|
40
|
+
*
|
|
41
|
+
* This method skips the current owner verification step.
|
|
42
|
+
* Only use this if you've already verified ownership elsewhere.
|
|
43
|
+
*
|
|
44
|
+
* @param vdaId - VDA ID to transfer
|
|
45
|
+
* @param newOwner - New owner wallet address
|
|
46
|
+
* @returns The updated VDA
|
|
47
|
+
*/
|
|
48
|
+
transferOwnershipUnsafe(vdaId: string, newOwner: string): Promise<VDA>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=ownership-transfer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ownership-transfer.d.ts","sourceRoot":"","sources":["../src/ownership-transfer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,wBAAwB;IACnC,OAAO,CAAC,cAAc,CAAoB;gBAE9B,cAAc,EAAE,iBAAiB;IAI7C;;;;;;OAMG;IACG,iBAAiB,CACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,GAAG,CAAC;IA4Cf;;;;;;;;;OASG;IACG,uBAAuB,CAC3B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,GAAG,CAAC;CAiBhB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hauska-sdk/vda
|
|
3
|
+
* Ownership Transfer Implementation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Ownership Transfer Service
|
|
7
|
+
*/
|
|
8
|
+
export class OwnershipTransferService {
|
|
9
|
+
storageAdapter;
|
|
10
|
+
constructor(storageAdapter) {
|
|
11
|
+
this.storageAdapter = storageAdapter;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Transfer ownership of a VDA from one wallet to another
|
|
15
|
+
*
|
|
16
|
+
* @param params - Transfer ownership parameters
|
|
17
|
+
* @returns The updated VDA
|
|
18
|
+
* @throws Error if current owner doesn't match or VDA not found
|
|
19
|
+
*/
|
|
20
|
+
async transferOwnership(params) {
|
|
21
|
+
const { vdaId, currentOwner, newOwner } = params;
|
|
22
|
+
// Get the VDA
|
|
23
|
+
const vda = await this.storageAdapter.getVDA(vdaId);
|
|
24
|
+
if (!vda) {
|
|
25
|
+
throw new Error(`VDA ${vdaId} not found`);
|
|
26
|
+
}
|
|
27
|
+
// Verify current owner
|
|
28
|
+
if (vda.metadata.ownerWallet !== currentOwner) {
|
|
29
|
+
throw new Error(`Current owner mismatch. Expected ${currentOwner}, but VDA is owned by ${vda.metadata.ownerWallet}`);
|
|
30
|
+
}
|
|
31
|
+
// Prevent transferring to the same owner
|
|
32
|
+
if (currentOwner === newOwner) {
|
|
33
|
+
throw new Error("Cannot transfer ownership to the same wallet");
|
|
34
|
+
}
|
|
35
|
+
// Update ownership via storage adapter
|
|
36
|
+
await this.storageAdapter.transferOwnership(vdaId, newOwner);
|
|
37
|
+
// Get the updated VDA
|
|
38
|
+
const updatedVDA = await this.storageAdapter.getVDA(vdaId);
|
|
39
|
+
if (!updatedVDA) {
|
|
40
|
+
throw new Error(`Failed to retrieve updated VDA ${vdaId}`);
|
|
41
|
+
}
|
|
42
|
+
// Verify the transfer was successful
|
|
43
|
+
if (updatedVDA.metadata.ownerWallet !== newOwner) {
|
|
44
|
+
throw new Error(`Ownership transfer failed. VDA is still owned by ${updatedVDA.metadata.ownerWallet}`);
|
|
45
|
+
}
|
|
46
|
+
// Verify updatedAt timestamp was updated (storage adapter should handle this)
|
|
47
|
+
// Note: Some storage adapters may update the timestamp automatically
|
|
48
|
+
// We'll just verify the ownership change was successful
|
|
49
|
+
return updatedVDA;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Transfer ownership without verification (use with caution)
|
|
53
|
+
*
|
|
54
|
+
* This method skips the current owner verification step.
|
|
55
|
+
* Only use this if you've already verified ownership elsewhere.
|
|
56
|
+
*
|
|
57
|
+
* @param vdaId - VDA ID to transfer
|
|
58
|
+
* @param newOwner - New owner wallet address
|
|
59
|
+
* @returns The updated VDA
|
|
60
|
+
*/
|
|
61
|
+
async transferOwnershipUnsafe(vdaId, newOwner) {
|
|
62
|
+
const vda = await this.storageAdapter.getVDA(vdaId);
|
|
63
|
+
if (!vda) {
|
|
64
|
+
throw new Error(`VDA ${vdaId} not found`);
|
|
65
|
+
}
|
|
66
|
+
await this.storageAdapter.transferOwnership(vdaId, newOwner);
|
|
67
|
+
const updatedVDA = await this.storageAdapter.getVDA(vdaId);
|
|
68
|
+
if (!updatedVDA) {
|
|
69
|
+
throw new Error(`Failed to retrieve updated VDA ${vdaId}`);
|
|
70
|
+
}
|
|
71
|
+
return updatedVDA;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=ownership-transfer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ownership-transfer.js","sourceRoot":"","sources":["../src/ownership-transfer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAyBH;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAC3B,cAAc,CAAoB;IAE1C,YAAY,cAAiC;QAC3C,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,iBAAiB,CACrB,MAA+B;QAE/B,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;QAEjD,cAAc;QACd,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,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,KAAK,CAAC,OAAO,KAAK,YAAY,CAAC,CAAC;QAC5C,CAAC;QAED,MAAM,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE7D,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAE3D,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,kCAAkC,KAAK,EAAE,CAAC,CAAC;QAC7D,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hauska-sdk/vda
|
|
3
|
+
* Ownership Verification Implementation
|
|
4
|
+
*/
|
|
5
|
+
import type { VDA } from "./types";
|
|
6
|
+
import type { VDAStorageAdapter } from "./minting";
|
|
7
|
+
import type { PermissionType } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* Ownership verification result
|
|
10
|
+
*/
|
|
11
|
+
export interface OwnershipVerificationResult {
|
|
12
|
+
/**
|
|
13
|
+
* Whether the wallet has access to the VDA
|
|
14
|
+
*/
|
|
15
|
+
hasAccess: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Type of access (direct ownership or access pass)
|
|
18
|
+
*/
|
|
19
|
+
accessType: "direct" | "access-pass" | null;
|
|
20
|
+
/**
|
|
21
|
+
* Access pass VDA if access is via access pass
|
|
22
|
+
*/
|
|
23
|
+
accessPass?: VDA;
|
|
24
|
+
/**
|
|
25
|
+
* Reason for denial (if hasAccess is false)
|
|
26
|
+
*/
|
|
27
|
+
reason?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Ownership Verification Service
|
|
31
|
+
*/
|
|
32
|
+
export declare class OwnershipVerificationService {
|
|
33
|
+
private storageAdapter;
|
|
34
|
+
constructor(storageAdapter: VDAStorageAdapter);
|
|
35
|
+
/**
|
|
36
|
+
* Verify if a wallet has access to a VDA
|
|
37
|
+
*
|
|
38
|
+
* Checks both direct ownership and access pass ownership.
|
|
39
|
+
*
|
|
40
|
+
* @param vdaId - VDA ID to verify access for
|
|
41
|
+
* @param wallet - Wallet address to verify
|
|
42
|
+
* @param requiredPermissions - Optional permissions required (default: ["view"])
|
|
43
|
+
* @returns Ownership verification result
|
|
44
|
+
*/
|
|
45
|
+
verifyOwnership(vdaId: string, wallet: string, requiredPermissions?: PermissionType[]): Promise<OwnershipVerificationResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Check if a wallet has a specific permission for a VDA
|
|
48
|
+
*
|
|
49
|
+
* @param vdaId - VDA ID
|
|
50
|
+
* @param wallet - Wallet address
|
|
51
|
+
* @param permission - Permission to check
|
|
52
|
+
* @returns True if wallet has the permission
|
|
53
|
+
*/
|
|
54
|
+
hasPermission(vdaId: string, wallet: string, permission: PermissionType): Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Check if a wallet is the direct owner of a VDA
|
|
57
|
+
*
|
|
58
|
+
* @param vdaId - VDA ID
|
|
59
|
+
* @param wallet - Wallet address
|
|
60
|
+
* @returns True if wallet is the direct owner
|
|
61
|
+
*/
|
|
62
|
+
isDirectOwner(vdaId: string, wallet: string): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Get all access passes that grant access to a VDA for a wallet
|
|
65
|
+
*
|
|
66
|
+
* @param vdaId - VDA ID
|
|
67
|
+
* @param wallet - Wallet address
|
|
68
|
+
* @returns Array of valid access pass VDAs
|
|
69
|
+
*/
|
|
70
|
+
getAccessPassesForVDA(vdaId: string, wallet: string): Promise<VDA[]>;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=ownership.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ownership.d.ts","sourceRoot":"","sources":["../src/ownership.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,SAAS,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,UAAU,EAAE,QAAQ,GAAG,aAAa,GAAG,IAAI,CAAC;IAE5C;;OAEG;IACH,UAAU,CAAC,EAAE,GAAG,CAAC;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,4BAA4B;IACvC,OAAO,CAAC,cAAc,CAAoB;gBAE9B,cAAc,EAAE,iBAAiB;IAI7C;;;;;;;;;OASG;IACG,eAAe,CACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,mBAAmB,GAAE,cAAc,EAAa,GAC/C,OAAO,CAAC,2BAA2B,CAAC;IA2EvC;;;;;;;OAOG;IACG,aAAa,CACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,cAAc,GACzB,OAAO,CAAC,OAAO,CAAC;IAKnB;;;;;;OAMG;IACG,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUpE;;;;;;OAMG;IACG,qBAAqB,CACzB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,GAAG,EAAE,CAAC;CAiClB"}
|