Skip to content

Commit

Permalink
feat: remove near-api-js account object dependency from change functi…
Browse files Browse the repository at this point in the history
…ons (#38)

* refactor: remove dependency on near-api-js account and connection objects from change functions

* test: update tests to use new network initialization

* chore: squash

* docs: amend docs to use new initailaization

* docs: update docs to use the new signer object and fix broken links

* build(lint): fix linting errors

* chore: squash

* refactor: convert signer to account because signer is icky
  • Loading branch information
kieranroneill authored Jul 25, 2024
1 parent 8f6ad43 commit 134e463
Show file tree
Hide file tree
Showing 50 changed files with 779 additions and 572 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<img alt="GitHub Pre-release" src="https://img.shields.io/github/v/release/NEARBuilders/near-social-js?include_prereleases&label=pre-release&logo=github">
</a>
<a href="https://github.com/NEARBuilders/near-social-js/releases">
<img alt="GitHub Pre-release Date - Published At" src="https://img.shields.io/github/release-date-pre/NEARBuilders/near-social-js?label=pre-release%20date&logo=github
">
<img alt="GitHub Pre-release Date - Published At" src="https://img.shields.io/github/release-date-pre/NEARBuilders/near-social-js?label=pre-release%20date&logo=github">
</a>
</p>

Expand Down
81 changes: 28 additions & 53 deletions docs/advanced/granting-write-permission.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,17 @@ Accounts can grant write permission to other accounts for a set of keys.
```js
const { Social } = require('@builddao/near-social-js');

const grantee = await nearConnection.account('alice.near');
const granter = await nearConnection.account('bob.near');
const accessKeys = await granter.getAccessKeys();
const social = new Social();
const transaction = await social.grantWritePermission({
blockHash: accessKeys[0].block_hash,
granteeAccountId: grantee.accountId,
account: {
accountID: 'bob.near',
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
},
granteeAccountId: 'alice.near',
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url',
],
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer: granter,
});

// ...sign the returned transaction and post to the network
Expand All @@ -56,41 +53,22 @@ Accounts can grant write permission to other accounts for a set of keys.
<TabItem value="javascript-via-cdn">

```js
var accessKeys;
var grantee;
var granter;
var social;

nearConnection.account('alice.near')
.then((_granter) => {
granter = _granter;

return nearConnection.account('bob.near');
})
.then((_grantee) => {
grantee = _grantee;

return granter.getAccessKeys();
})
.then((_accessKeys) => {
accessKeys = _accessKeys;
social = new NEARSocialSDK();

return social.grantWritePermission({
blockHash: accessKeys[0].block_hash,
granteeAccountId: grantee.accountId,
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url',
],
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer: granter,
});
})
.then((transaction) => {
// ...sign the returned transaction and post to the network
});
var social = new NEARSocialSDK();

social.grantWritePermission({
account: {
accountID: 'bob.near',
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
},
granteeAccountId: 'alice.near',
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url'
]
})
.then((transaction) => {
// ...sign the returned transaction and post to the network
});
```

</TabItem>
Expand All @@ -99,20 +77,17 @@ Accounts can grant write permission to other accounts for a set of keys.
```typescript
import { Social } from '@builddao/near-social-js';

const grantee = await nearConnection.account('alice.near');
const granter = await nearConnection.account('bob.near');
const accessKeys = await granter.getAccessKeys();
const social = new Social();
const transaction = await social.grantWritePermission({
blockHash: accessKeys[0].block_hash,
granteeAccountId: grantee.accountId,
account: {
accountID: 'bob.near',
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
},
granteeAccountId: 'alice.near',
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url',
],
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer: granter,
});

// ...sign the returned transaction and post to the network
Expand All @@ -124,12 +99,12 @@ Accounts can grant write permission to other accounts for a set of keys.

:::caution

If the grantee account ID or the account ID in each key is not a valid account ID then a [`InvalidAccountIdError`](../../api-reference/errors#invalidaccountiderror) is thrown.
If the grantee account ID or the account ID in each key is not a valid account ID then a [`InvalidAccountIdError`](../api-reference/errors#invalidaccountiderror) is thrown.

:::

:::caution

If a key does is not owned by the granter, then a [`KeyNotAllowedError`](../../api-reference/errors#keynotallowederror) is thrown.
If a key does is not owned by the granter, then a [`KeyNotAllowedError`](../api-reference/errors#keynotallowederror) is thrown.

:::
6 changes: 0 additions & 6 deletions docs/advanced/reading-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Getting specific values, like the example from above, you can use a set of keys:
'alice.near/profile/image/url',
'bob.near/profile/name',
],
rpcURL //rpc url for your network.
});

console.log(result);
Expand Down Expand Up @@ -95,7 +94,6 @@ Getting specific values, like the example from above, you can use a set of keys:
'alice.near/profile/image/url',
'bob.near/profile/name',
],
rpcURL //rpc url for your network.
}).then((result) => {
console.log(result);
/*
Expand Down Expand Up @@ -135,7 +133,6 @@ Getting specific values, like the example from above, you can use a set of keys:
'alice.near/profile/image/url',
'bob.near/profile/name',
],
rpcURL //rpc url for your network.
});

console.log(result);
Expand Down Expand Up @@ -186,7 +183,6 @@ The [`get`](../api-reference/social#getoptions) function also supports wildcard
keys: [
'alice.near/profile/**',
],
rpcURL //rpc url for your network.
});

console.log(result);
Expand Down Expand Up @@ -214,7 +210,6 @@ The [`get`](../api-reference/social#getoptions) function also supports wildcard
keys: [
'alice.near/profile/**',
],
rpcURL, //rpc url for your network.
}).then((result) => {
console.log(result);
/*
Expand Down Expand Up @@ -243,7 +238,6 @@ The [`get`](../api-reference/social#getoptions) function also supports wildcard
keys: [
'alice.near/profile/**'
],
rpcURL, //rpc url for your network.
});

console.log(result);
Expand Down
Loading

0 comments on commit 134e463

Please sign in to comment.