@smontero/hashed-confidential-docs v0.2.27
Hashed Confidential Docs Client API
Enables the usage of the Hashed Confidential docs services by client applications.
To install the hashed private client api run the following command:
npm i --save @smontero/hashed-confidential-docs
Access to most of the functionality is done through the HashedConfidentailDocs object which enables its configuration and provides access to the different API objects:
import { HashedConfidentialDocs } from '@smontero/hashed-confidential-docs'
A new instance of the HashedConfidentialDocs class has to be created passing in the ipfs url, ipfs auth header, polkadot service class instance and a faucet instance:
const hcd = new HashedConfidentialDocs({
ipfsURL: 'https://ipfs.infura.io:5001',
ipfsAuthHeader: `Basic ${Buffer.from(`${process.env.IPFS_PROJECT_ID}:${process.env.IPFS_PROJECT_SECRET}`).toString('base64')}`,
polkadot,
faucet
})
Then the user has to be logged in to hashed confidential docs, to login the user a VaultAuthProvider is required, the VaultAuthProvider used depends on how the user is login in to the system ex. username/password, google sign in or a native wallet, the current auth channels are:
- PasswordVaultAuthProvider: for a user login in using username/password
- GoogleVaultAuthProvider: for a user login in google sign in
The creation and initialization of a vaultAuthProvider is done through creation methods which are exported from this package while the classes themselves are not.
const vaultAuthProvider = await createPasswordVaultAuthProvider({
authName, // the name to identify this auth channel
jwt, // the JSON Web Token generated by the authentication channel
faucetServerUrl, //the url for the hashed faucet server
password
})
const vaultAuthProvider = await createGoogleVaultAuthProvider({
authName, // the name to identify this auth channel
jwt, // the JSON Web Token generated by the authentication channel
faucetServerUrl, //the url for the hashed faucet server
googleDrive //instance of the google drive service class
})
During the VaultAuthProvider creation, the jwt token is verified, after the creation of the VaultAuthProvider the decoded can be accessed as follows:
vaultAuthProvider.decodedJWT
await hcd.login(vaultAuthProvider)
Its important to note that the polkadot service class instance passed in to the hashed confidential docs will be configured with a VaultWallet when the user is logged in, that will enable this instance to be used to call extrinsics and sign on behalf of the user.
Once logged in the services provided by the OwnedData,SharedData and Group objects can be accessed.
OwnedData services
- add: Store a payload(object or File) in the hashed private service
const ownedData = await hcd.ownedData().add({
name: 'name1',
description: 'desc1',
payload: {
prop1: 1,
prop2: 'str1'
}
})
- viewByCID: View a stored payload by owned data cid, returns the deciphered payload(object or File)
const ownedData = await hcd.ownedData().viewByCID(cid)
SharedData services
- share: Share the specified existing owned data record with another user
let sharedData = await hp.sharedData().share({
toUserAddress: '5FSuxe2q7qCYKie8yqmM56U4ovD1YtBb3DoPzGKjwZ98vxua',
name: 'name1',
description: 'desc1',
payload: {
prop1: 1,
prop2: 'str1'
}
})
- viewByCID: View a stored payload by shared data cid, returns the deciphered payload(object or File)
const ownedData = await hcd.sharedData().viewByCID(cid)
Group services
- createGroup: Creates a new group with the logged in user as the owner
const group = await hcd.group().createGroup('test1')
- addGroupMember: Adds a member to the specified group, only owners and admins are able to add members
await hcd.group().addGroupMember({
groupAddress: group.group,
memberAddress,
role: GroupRole.MEMBER
})
Export Vault
- exportVault: Exports vault secret data
- BrowserDownloadExporter Exports payload as a file download in the browser
const exporter = BrowserDownloadExporter()
await hcd.vault().exportVault(exporter)
11 months ago
11 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago