SDK Docs
UID Connection SDK
Installation
To install the package, run the following command:
npm install uid-connection-sdk
Or, if you're using yarn
:
yarn add uid-connection-sdk
Usage
1. Initialize the Client
Before logging in or approving data sharing, initialize the SDK by passing your partner ID and environment (staging or production).
import { init } from "uid-connection-sdk";
init({
partnerId: 'your-partner-id', // Your unique partner ID
environment: 'staging' // Environment: 'staging' or 'production'
});
2. Login a User
To log in a user and create their wallet, call our login method, which in turn brings up an oauth modal for easy authentication (creation of wallet).
import { login } from 'uid-connection-sdk';
login()
.then((wallet) => console.log("Auth Wallet:", wallet))
.catch((error) => console.error("Login failed:", error.message));
On successful login, the user's wallet will be created on our side, and their session will be active.
3. Approve Data Sharing
Once logged in, the user can approve data-sharing connections with specific partners. This request should specify the partner requesting the data, and the categories of data to be shared.
import { approveData } from 'uid-connection-sdk';
approveData(
wallet: 'user-wallet, // User's wallet
partnerId: 'your-partner-id', // Partner requesting the data
dataTypes: ['purchaseHistory', 'browsingData'] // Approved data categories
)
.then(() => console.log('Data sharing approved.'))
.catch((error) => console.error('Approval failed:', error.message));
- wallet: The user's wallet from the login.
- partnerId: The ID of the partner requesting the data.
- dataTypes: An array of approved data categories (e.g., 'purchaseHistory').
Data Integrity SDK
Installation
To install the package, run the following command:
npm install uid-connection-sdk
Or, if you're using yarn
:
yarn add uid-connection-sdk
Usage
1. Initialize the Client
Before logging in or approving data sharing, initialize the SDK by passing your partner ID and environment (staging or production).
import { init } from "uid-connection-sdk";
init({
partnerId: 'your-partner-id', // Your unique partner ID
environment: 'staging' // Environment: 'staging' or 'production'
});
2. Creating a Hash
A hash can be created from user event data for verifications and integrity.
import { createHash } from 'uid-connection-sdk';
createHash(
data: {} // Event data
)
.then((hash) => console.log('Retrieved Hash:', response.data))
.catch((error) => console.error('Failed to create hash:', error.message));
3. Retrieve and Verify Stored Data
Partners can retrieve and verify stored event data by querying it using the hash based on the event.
import { retrieveData } from 'uid-connection-sdk';
retrieveData(
partnerId: 'user123',
hash: '0xasdeaHaie…'
)
.then((response) => {
console.log('Retrieved Data:', response.data);
})
.catch((error) => console.error('Failed to retrieve data:', error.message));
4. Registering an event
Partners can register events with user data, which will be hashed and stored on-chain via our backend.
import { registerEvent } from 'uid-connection-sdk';
registerEvent(
eventName: 'UserPurchase', // Name of the event
userId: 'user123', // User ID
data: { // Event data
itemsPurchased: 3,
totalAmount: 150,
purchaseDate: new Date().toISOString()
}
)
.then(() => console.log('Event registered successfully.'))
.catch((error) => console.error('Failed to register event:', error.message));
Contributing
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Updated 3 months ago