deso-protocol
Advanced tools
Comparing version 1.1.14 to 1.1.15
{ | ||
"name": "deso-protocol", | ||
"version": "1.1.14", | ||
"module": "./src/index.js", | ||
"version": "1.1.15", | ||
"license": "MIT", | ||
"description": "Client side typescript/javascript SDK for building web3 applications for the DeSo blockchain.", | ||
"main": "./src/index.js", | ||
"types": "./src/index.d.ts", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "jest", | ||
"prepare": "husky install", | ||
"precommit": "lint-staged && npm run test" | ||
}, | ||
"keywords": [ | ||
@@ -13,9 +22,45 @@ "blockchain", | ||
], | ||
"bugs": { | ||
"url": "https://github.com/deso-protocol/deso-js/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/deso-protocol/deso-js.git" | ||
}, | ||
"homepage": "https://github.com/deso-protocol/deso-js#readme", | ||
"lint-staged": { | ||
"{libs,apps}/**/*.{js,jsx,ts,tsx}": [ | ||
"eslint --fix", | ||
"prettier --write" | ||
], | ||
"*.yml": [ | ||
"prettier --write" | ||
] | ||
}, | ||
"dependencies": { | ||
"@deso-core/identity": "^0.1.7", | ||
"@deso-core/data": "^0.1.1", | ||
"deso-protocol-types": "^0.7.3" | ||
"@noble/hashes": "^1.3.0", | ||
"@noble/secp256k1": "^1.7.1", | ||
"@types/elliptic": "^6.4.14", | ||
"bs58": "^5.0.0", | ||
"ethers": "^5.6.6", | ||
"reflect-metadata": "^0.1.13" | ||
}, | ||
"main": "./src/index.js", | ||
"typings": "./src/index.d.ts" | ||
"devDependencies": { | ||
"@types/jest": "^29.5.1", | ||
"@types/jsonwebtoken": "^9.0.1", | ||
"@types/node": "^18.16.1", | ||
"bs58check": "^3.0.1", | ||
"elliptic": "^6.5.4", | ||
"eslint": "^8.39.0", | ||
"husky": "^8.0.0", | ||
"jest": "^29.5.0", | ||
"jest-environment-jsdom": "^29.5.0", | ||
"jsonwebtoken": "^9.0.0", | ||
"key-encoder": "^2.0.3", | ||
"lint-staged": "^13.2.1", | ||
"prettier": "^2.8.8", | ||
"ts-jest": "^29.1.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.0.4" | ||
} | ||
} |
151
README.md
@@ -16,12 +16,39 @@ # deso-protocol | ||
// configure takes all of the same options that the identity | ||
// library's configure method takes: https://github.com/deso-protocol/deso-workspace/tree/main/libs/identity#configuration | ||
// with the addition of the MinFeeRateNanosPerKB value that will be used for all transactions. | ||
configure({ | ||
// Here we indicate the permissions a user will be asked to approve when they | ||
// log into your application. You may specify as many or as few permissions up | ||
// front as you want. You may choose not to request any permissions up front | ||
// and that's okay! Just remember that you will need to request them in your | ||
// app progressively, and you can always request as many or as few as you want | ||
// using the `requestPermissions` method described in the usage section. | ||
// | ||
// See more about the spending limit options object here | ||
// https://docs.deso.org/for-developers/backend/blockchain-data/basics/data-types#transactionspendinglimitresponse | ||
// And See an exhaustive list of transaction types here: | ||
// https://github.com/deso-protocol/core/blob/a836e4d2e92f59f7570c7a00f82a3107ec80dd02/lib/network.go#L244 | ||
spendingLimitOptions: { | ||
GlobalDESOLimit: 1000000000, | ||
// NOTE: this value is in Deso nanos, so 1 Deso * 1e9 | ||
GlobalDESOLimit: 1 * 1e9 // 1 Deso | ||
// Map of transaction type to the number of times this derived key is | ||
// allowed to perform this operation on behalf of the owner public key | ||
TransactionCountLimitMap: { | ||
SUBMIT_POST: 4, | ||
BASIC_TRANSFER: 2, // 2 basic transfer transactions are authorized | ||
SUBMIT_POST: 4, // 4 submit post transactions are authorized | ||
}, | ||
} | ||
// Optional node uri. Sets the uri for the node that will be used for all | ||
// subsequent requests. If not passed it will default to https://node.deso.org | ||
nodeURI: 'https://mynode.com', | ||
// Optional redirect URI. This is mostly useful for native mobile use cases. | ||
// Most web applications will not want to use it. If provided, we do a full | ||
// redirect to the identity domain and pass data via query params back to the | ||
// provided uri. | ||
redirectURI: 'https://mydomain.com/my-redirect-path', | ||
// This will be associated with all of the derived keys that your application | ||
// authorizes. | ||
appName: 'My Cool App', | ||
// this is optional, if not passed the default of 1500 will be used. | ||
@@ -32,4 +59,2 @@ MinFeeRateNanosPerKB: 1000, | ||
See [the identity configuration options](https://github.com/deso-protocol/deso-workspace/tree/main/libs/identity#configuration) for reference. | ||
## Usage | ||
@@ -40,14 +65,106 @@ | ||
```ts | ||
import { identity } from 'deso-protocol'; | ||
import { identity } from "deso-protocol"; | ||
identity.login(); | ||
identity.logout(); | ||
// Subscribe to identity state changes (user login/logout, permissions updated, | ||
// etc). This is useful for binding your preferred framework's state management | ||
// system to the identity instance's internal state. The function you provide to | ||
// `subscribe` will be called anytime identity's internal state changes. | ||
identity.subscribe((state) => { | ||
// The event property is a string value that tells you what triggered the | ||
// subscribe call. Useful for setting loading states or otherwise making | ||
// decisions about how you want your app to react to identity state. | ||
// You can see an exhaustive list of the events here: https://github.com/deso-protocol/deso-js/blob/4d91fd7a66debd2aa0b0b49c0ccb872c0c849d49/src/identity/types.ts#L225 | ||
const event = state.event; | ||
// The current user object contains the user's current permissions | ||
// (TransactionCountLimitMap). This value will be updated when the logged in | ||
// user changes or when the permissions change for the current user. Read | ||
// more about the transaction count limit map here | ||
// https://docs.deso.org/for-developers/backend/blockchain-data/basics/data-types#transactionspendinglimitresponse | ||
const currentUser = state.currentUser; | ||
// A list of all users that a given user has logged in with (excluding | ||
// currentUser). This is useful if you want to show a list of accounts and | ||
// provide a way to switch accounts easily. | ||
const alernateUsers = state.alternateUsers; | ||
}); | ||
// Start a login flow | ||
await identity.login(); | ||
// Start a logout flow | ||
await identity.logout(); | ||
// Switch users (for apps that manage multiple accounts for a single user). | ||
// NOTE: The publicKey here must be a user that has previously logged in. | ||
identity.setActiveUser(publicKey); | ||
// Generate a jwt for making authenticated requests via `Authorization` http | ||
// header. | ||
await identity.jwt(); | ||
// Sign and submit a transaction. This is handled for you if you're using any | ||
// of the provided transaction creation helpers. But you can also do this yourself | ||
// if you have a more complex use case. | ||
const tx = await axios.post("https://node.deso.org/api/v0/submit-post"); | ||
const submittedTx = await identity.signAndSubmit(tx); | ||
// For some use cases, you might want to handle signing, submitting, | ||
// and retrying yourself. Here's an example of handling each step of the process | ||
// yourself. | ||
const postTransaction = await axios.post( | ||
"https://node.deso.org/api/v0/submit-post" | ||
); | ||
const signedTx = await identity.signTx(postTransaction.TransactionHex); | ||
const submittedTx = await identity.submitTx(signedTx); | ||
// Checking for permissions is straightforward. Here we check if our app can | ||
// post on behalf of a user Read more about the transaction count limit map here | ||
// https://docs.deso.org/for-developers/backend/blockchain-data/basics/data-types#transactionspendinglimitresponse and you can find an exhaustive list | ||
// of available transaction types here: https://github.com/deso-protocol/core/blob/a836e4d2e92f59f7570c7a00f82a3107ec80dd02/lib/network.go#L244 | ||
// This returns a boolean value synchronously. | ||
const hasPermission = identity.hasPermissions({ | ||
TransactionCountLimitMap: { | ||
SUBMIT_POST: 1, | ||
}, | ||
}); | ||
// Here we request approval for permissions from a user. This will present the | ||
// user with the deso identity approve derived key UI. | ||
if (!hasPermissions) { | ||
await identity.requestPermissions({ | ||
TransactionCountLimitMap: { | ||
SUBMIT_POST: 1, | ||
}, | ||
}); | ||
} | ||
// Encrypt plain text with the recipients public key. This can be subsequently | ||
// decrypted using the recipient's private key. | ||
const encryptedMessageHex = await identity.encryptMessage( | ||
recipientPublicKeyBase58Check, | ||
plaintextMsg | ||
); | ||
// Decrypt a message returned from any of the message endpoints of the deso | ||
// backend messages api. If it is a group message you will need to fetch the | ||
// groups the user is a member of and provide them. If it's known that the | ||
// message is not a a group message you can pass an empty array for the groups | ||
// parameter. | ||
// | ||
// See the api docs for sending and receiving messages here: | ||
// https://docs.deso.org/deso-backend/api/messages-endpoints | ||
// | ||
// See the api docs for access groups here: | ||
// https://docs.deso.org/deso-backend/api/access-group-endpoints | ||
const decryptedMessagePlaintext = await identity.decryptMessage( | ||
message, | ||
accessGroups | ||
); | ||
``` | ||
See [the identity usage docs](https://github.com/deso-protocol/deso-workspace/tree/main/libs/identity#usage) for reference. | ||
### Data: fetching data from a node | ||
```ts | ||
import { getUsersStateless, getPostsStateless } from 'deso-protocol'; | ||
import { getUsersStateless, getPostsStateless } from "deso-protocol"; | ||
@@ -62,3 +179,3 @@ const users = await getUsersStateless({ | ||
See the [backend api documentation](https://docs.deso.org/deso-backend/api) for reference. | ||
See an exhaustive list of the available data fetching functions [here](https://github.com/deso-protocol/deso-workspace/blob/main/libs/data/src/lib/data.ts#L73). | ||
See an exhaustive list of the available data fetching functions [here](https://github.com/deso-protocol/deso-js/blob/4d91fd7a66debd2aa0b0b49c0ccb872c0c849d49/src/data/data.ts#L116). | ||
@@ -72,3 +189,3 @@ ### Transactions: Writing data to the blockchain | ||
```ts | ||
import { submitPost } from 'deso-protocol'; | ||
import { submitPost } from "deso-protocol"; | ||
@@ -78,3 +195,3 @@ const txInfo = submitPost({ | ||
BodyObj: { | ||
Body: 'My first post on DeSo!', | ||
Body: "My first post on DeSo!", | ||
ImageURLs: [], | ||
@@ -87,2 +204,2 @@ VideoURLs: [], | ||
See the [transaction construction api documentation](https://docs.deso.org/deso-backend/construct-transactions) for reference. | ||
See an exhaustive list of the available transaction construction functions [here](https://github.com/deso-protocol/deso-workspace/tree/beta/libs/deso-protocol/src/lib/transactions) | ||
See an exhaustive list of the available transaction construction functions [here](https://github.com/deso-protocol/deso-js/tree/main/src/transactions) |
@@ -1,12 +0,12 @@ | ||
export * from '@deso-core/data'; | ||
export * from '@deso-core/identity'; | ||
export * from 'deso-protocol-types'; | ||
export * from './lib/deso-protocol'; | ||
export * from './lib/jwt-requests'; | ||
export * from './lib/transactions/access-groups'; | ||
export * from './lib/transactions/associations'; | ||
export * from './lib/transactions/derived-keys'; | ||
export * from './lib/transactions/deso-tokens'; | ||
export * from './lib/transactions/financial'; | ||
export * from './lib/transactions/nfts'; | ||
export * from './lib/transactions/social'; | ||
export * from "./backend-types"; | ||
export * from "./data"; | ||
export * from "./deso-protocol"; | ||
export * from "./identity"; | ||
export * from "./jwt-requests"; | ||
export * from "./transactions/access-groups"; | ||
export * from "./transactions/associations"; | ||
export * from "./transactions/derived-keys"; | ||
export * from "./transactions/deso-tokens"; | ||
export * from "./transactions/financial"; | ||
export * from "./transactions/nfts"; | ||
export * from "./transactions/social"; |
@@ -1,13 +0,13 @@ | ||
export * from '@deso-core/data'; | ||
export * from '@deso-core/identity'; | ||
export * from 'deso-protocol-types'; | ||
export * from './lib/deso-protocol'; | ||
export * from './lib/jwt-requests'; | ||
export * from './lib/transactions/access-groups'; | ||
export * from './lib/transactions/associations'; | ||
export * from './lib/transactions/derived-keys'; | ||
export * from './lib/transactions/deso-tokens'; | ||
export * from './lib/transactions/financial'; | ||
export * from './lib/transactions/nfts'; | ||
export * from './lib/transactions/social'; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9saWJzL2Rlc28tcHJvdG9jb2wvc3JjL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsaUJBQWlCLENBQUM7QUFDaEMsY0FBYyxxQkFBcUIsQ0FBQztBQUNwQyxjQUFjLHFCQUFxQixDQUFDO0FBQ3BDLGNBQWMscUJBQXFCLENBQUM7QUFDcEMsY0FBYyxvQkFBb0IsQ0FBQztBQUNuQyxjQUFjLGtDQUFrQyxDQUFDO0FBQ2pELGNBQWMsaUNBQWlDLENBQUM7QUFDaEQsY0FBYyxpQ0FBaUMsQ0FBQztBQUNoRCxjQUFjLGdDQUFnQyxDQUFDO0FBQy9DLGNBQWMsOEJBQThCLENBQUM7QUFDN0MsY0FBYyx5QkFBeUIsQ0FBQztBQUN4QyxjQUFjLDJCQUEyQixDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0ICogZnJvbSAnQGRlc28tY29yZS9kYXRhJztcbmV4cG9ydCAqIGZyb20gJ0BkZXNvLWNvcmUvaWRlbnRpdHknO1xuZXhwb3J0ICogZnJvbSAnZGVzby1wcm90b2NvbC10eXBlcyc7XG5leHBvcnQgKiBmcm9tICcuL2xpYi9kZXNvLXByb3RvY29sJztcbmV4cG9ydCAqIGZyb20gJy4vbGliL2p3dC1yZXF1ZXN0cyc7XG5leHBvcnQgKiBmcm9tICcuL2xpYi90cmFuc2FjdGlvbnMvYWNjZXNzLWdyb3Vwcyc7XG5leHBvcnQgKiBmcm9tICcuL2xpYi90cmFuc2FjdGlvbnMvYXNzb2NpYXRpb25zJztcbmV4cG9ydCAqIGZyb20gJy4vbGliL3RyYW5zYWN0aW9ucy9kZXJpdmVkLWtleXMnO1xuZXhwb3J0ICogZnJvbSAnLi9saWIvdHJhbnNhY3Rpb25zL2Rlc28tdG9rZW5zJztcbmV4cG9ydCAqIGZyb20gJy4vbGliL3RyYW5zYWN0aW9ucy9maW5hbmNpYWwnO1xuZXhwb3J0ICogZnJvbSAnLi9saWIvdHJhbnNhY3Rpb25zL25mdHMnO1xuZXhwb3J0ICogZnJvbSAnLi9saWIvdHJhbnNhY3Rpb25zL3NvY2lhbCc7XG4iXX0= | ||
export * from "./backend-types"; | ||
export * from "./data"; | ||
export * from "./deso-protocol"; | ||
export * from "./identity"; | ||
export * from "./jwt-requests"; | ||
export * from "./transactions/access-groups"; | ||
export * from "./transactions/associations"; | ||
export * from "./transactions/derived-keys"; | ||
export * from "./transactions/deso-tokens"; | ||
export * from "./transactions/financial"; | ||
export * from "./transactions/nfts"; | ||
export * from "./transactions/social"; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxpQkFBaUIsQ0FBQztBQUNoQyxjQUFjLFFBQVEsQ0FBQztBQUN2QixjQUFjLGlCQUFpQixDQUFDO0FBQ2hDLGNBQWMsWUFBWSxDQUFDO0FBQzNCLGNBQWMsZ0JBQWdCLENBQUM7QUFDL0IsY0FBYyw4QkFBOEIsQ0FBQztBQUM3QyxjQUFjLDZCQUE2QixDQUFDO0FBQzVDLGNBQWMsNkJBQTZCLENBQUM7QUFDNUMsY0FBYyw0QkFBNEIsQ0FBQztBQUMzQyxjQUFjLDBCQUEwQixDQUFDO0FBQ3pDLGNBQWMscUJBQXFCLENBQUM7QUFDcEMsY0FBYyx1QkFBdUIsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCAqIGZyb20gXCIuL2JhY2tlbmQtdHlwZXNcIjtcbmV4cG9ydCAqIGZyb20gXCIuL2RhdGFcIjtcbmV4cG9ydCAqIGZyb20gXCIuL2Rlc28tcHJvdG9jb2xcIjtcbmV4cG9ydCAqIGZyb20gXCIuL2lkZW50aXR5XCI7XG5leHBvcnQgKiBmcm9tIFwiLi9qd3QtcmVxdWVzdHNcIjtcbmV4cG9ydCAqIGZyb20gXCIuL3RyYW5zYWN0aW9ucy9hY2Nlc3MtZ3JvdXBzXCI7XG5leHBvcnQgKiBmcm9tIFwiLi90cmFuc2FjdGlvbnMvYXNzb2NpYXRpb25zXCI7XG5leHBvcnQgKiBmcm9tIFwiLi90cmFuc2FjdGlvbnMvZGVyaXZlZC1rZXlzXCI7XG5leHBvcnQgKiBmcm9tIFwiLi90cmFuc2FjdGlvbnMvZGVzby10b2tlbnNcIjtcbmV4cG9ydCAqIGZyb20gXCIuL3RyYW5zYWN0aW9ucy9maW5hbmNpYWxcIjtcbmV4cG9ydCAqIGZyb20gXCIuL3RyYW5zYWN0aW9ucy9uZnRzXCI7XG5leHBvcnQgKiBmcm9tIFwiLi90cmFuc2FjdGlvbnMvc29jaWFsXCI7XG4iXX0= |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1340129
69
0
12812
1
0
199
0
6
16
3
+ Added@noble/hashes@^1.3.0
+ Added@noble/secp256k1@^1.7.1
+ Added@types/elliptic@^6.4.14
+ Addedbs58@^5.0.0
+ Addedethers@^5.6.6
+ Addedreflect-metadata@^0.1.13
+ Added@types/bn.js@5.1.6(transitive)
+ Added@types/elliptic@6.4.18(transitive)
+ Added@types/node@22.7.4(transitive)
+ Addedundici-types@6.19.8(transitive)
- Removed@deso-core/data@^0.1.1
- Removed@deso-core/identity@^0.1.7
- Removeddeso-protocol-types@^0.7.3
- Removed@deso-core/data@0.1.1(transitive)
- Removed@deso-core/identity@0.1.7(transitive)
- Removeddeso-protocol-types@0.7.3(transitive)