https://github.com/functionland/fula-sec
Fula Security Library for DID creation and sharing
https://github.com/functionland/fula-sec
Last synced: 28 days ago
JSON representation
Fula Security Library for DID creation and sharing
- Host: GitHub
- URL: https://github.com/functionland/fula-sec
- Owner: functionland
- Created: 2022-11-08T00:26:05.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-09T14:01:07.000Z (about 3 years ago)
- Last Synced: 2025-01-20T05:43:16.923Z (about 1 year ago)
- Language: TypeScript
- Size: 327 KB
- Stars: 1
- Watchers: 6
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Fula Security Layer (FSL)
Fula Security Layer Includes Decentralized Identity and Encryption.
#
The Fula-sec library allows you to create DID (Decentrlized-ID) and Encript/Decypt by using `Ed25519` and `EDHD` algorithms.
`Ed25519` KeyPairs are used for creating DID, JWE/JWET/JWT signing identity of token which is passed as `iss:` attribyte of the payload. In same way opposite side user can verify or/and decrypt by passing their own KeyPair.
## Installation
Install NPM package
```sh
npm install @functionland/fula-sec --save
```
## Decentralized Identity (DID)
```js
import {HDKEY, DID} from '@functionland/fula-sec'
/* Prefix moc keys */
let password = '123456789' //User`s password
let signedKey = '9d7020006cf....f33a32adb81ae';
/* signedKey is the signature coming from the locally-running
service of a 3rd party signing authority like Meta Mask Wallet
by signing part of the password (not the full password is being
sent to the 3rd party signing authority)
*/
/* 1 - Add user`s password */
const ed = new HDKEY(password);
// A. Sign with chaincode |chainCode| ---> |Metamask|
// B. Get signedKey |signedKey| <--- |Metamask|
/* 2 - Get chainCode to get signedKey from Metamask*/
const chainCode = ed.chainCode;
/*
chainCode is created from part of the password to be sent
to the signing authority like MetaMask wallet to get a unique signature back
*/
`type:base64pad APSWnk8ULP/v//oseMeSEDadMBSSeX/SOxOREYhjQ7g=`
/* Send request to metamask*/
/* 3 - Get KeyPair: Publick and Privete Key */
const keyPair = ed.createEDKeyPair(signedKey);
`secretkey: Uint8Array(64) [
98, 47, 78, 171, 169, 201, 236, 231, 196, 23, 134,
135, 78, 180, 195, 93, 22, 57, 41, 213, 53, 86,
248, 34, 83, 162, 233, 128, 89, 128, 207, 173, 247,
94, 235, 66, 181, 212, 204, 168, 133, 182, 87, 227,
217, 233, 122, 169, 145, 20, 42, 110, 229, 233, 239,
112, 55, 203, 18, 112, 50, 251, 239, 219
],
pubkey: Uint8Array(32) [
247, 94, 235, 66, 181, 212, 204,
168, 133, 182, 87, 227, 217, 233,
122, 169, 145, 20, 42, 110, 229,
233, 239, 112, 55, 203, 18, 112,
50, 251, 239, 219
]`
/* keyPair: {
publicKey,
secretKey
} for creating DID and Encrypt/Decrypt */
/* 4 - Add KeyPair in order to generate DID*/
const did = new DID(keyPair.secretKey);
/* Get DID */
did.did();
`did:key:z6MknwZL7aFNFGoq7ZaZv47LF7tiqtwV3ZrYRbAJEmUWRRkh`
```
## Json Web Encrypted Token / Time Based Encryption
```js
import { EncryptJWT, DecryptJWT } from '@functionland/fula-sec'
/* Securly export your wrapped wnfs key */
const jwet = await new EncryptJWT({ any: 'your sensitive data to encrypt'})
.setIssuedAt()
.setNotBefore(Math.floor(Date.now() / 1000))
.setIssuer(did.did())
.setAudience(did.did())
.setExpirationTime('3s')
.encrypt(keyPair.secretKey);
/* Verify and decrypt to get your wnfs key within 3 second as declared above */
const payload = await new DecryptJWT(keyPair.secretKey).verify(jwet)
`payload: {
aud: 'did:key:z6MknwZL7aFNFGoq7ZaZv47LF7tiqtwV3ZrYRbAJEmUWRRkh',
exp: 1669043742,
iat: 1669043738,
iss: 'did:key:z6MknwZL7aFNFGoq7ZaZv47LF7tiqtwV3ZrYRbAJEmUWRRkh',
nbf: 1669043738,
any: 'your sensitive data to encrypt'
}
`
```
## Content
- [X] HDKEY Drive
- [X] Identity (DID)
- [X] JWE
- [X] JWET
See the [open issues](https://github.com/functionland/fula-sec/issues) for a full list of proposed features (and known issues).
## Development
- You have the opportunity to test it by installing a [demo application -> ](https://github.com/functionland/fula-linking)
- Fula documents related to Architecture, Protocol, dApps and and usage can be found on the [Function land documentation site](https://functionland.gitbook.io/product-docs/EZsKoqxFAOfV4Ap7jQjB/)
## Community
- Connect with function land developers. Questions, support, and discussions: [Join the Fx Discord](https://discord.com/invite/k9UybUBdBB)
- Bugs and Feature Requests: Open an issue in the appropriate [Github repository](https://github.com/functionland)
- The latest updates can be found here. [Blog](https://blog.fx.land/), [twitter](https://twitter.com/functionland)
## Maintainers
- [Saidov](https://github.com/ruffiano)
## License
See [`LICENSE`](/LICENSE) for more information.