In certain contexts, you may want to allow another account to update your aggregate. This can be done by creating a Security Key.
import { ItemType } from 'aleph-sdk-ts/dist/messages/message';
import { Publish as publishAggregate } from 'aleph-sdk-ts/dist/messages/aggregate';
(async () => {
await publishAggregate({
account: account,
key: 'testkey',
content: {'a': 1},
channel: 'TEST',
})
})();
The message result is here
Post by: 0x0BBB06C238bE7D4c5Df7BA56b7ad75a09eea5F56
"content": { "a": 1 }
import { ItemType } from 'aleph-sdk-ts/dist/messages/message';
import { Publish as publishAggregate } from 'aleph-sdk-ts/dist/messages/aggregate';
(async () => {
await publishAggregate({
account: account,
key: 'security',
content: {'authorizations': [
{
'address': '0x38533Af979CdE5b399F6375D98D318cCC3004c09',
'types': ['AGGREGATE'],
'aggregate_keys': ['testkey'],
}
]},
channel: 'security',
})
})();
The message result is here
Post by: 0x0BBB06C238bE7D4c5Df7BA56b7ad75a09eea5F56
As you can see, we specified the delegate account will only be able to update the testkey
field of the owner's aggregates.
Update with the delegated account
const res = await publishAggregate({
account: account, // Your delegated account
address: '0x0BBB06C238bE7D4c5Df7BA56b7ad75a09eea5F56', // The address of message Owner
key: 'testkey',
content: {'a': 101},
channel: 'TEST',
})
The message result is here
Post by: 0x38533Af979CdE5b399F6375D98D318cCC3004c09
import { ItemType } from 'aleph-sdk-ts/dist/messages/message';
import { Get as getAggregate } from 'aleph-sdk-ts/dist/messages/aggregate';
(async () => {
const fetched = await getAggregate({
address: '0x0BBB06C238bE7D4c5Df7BA56b7ad75a09eea5F56', // The Owner account
APIServer: 'https://api2.aleph.im'
})
})();
When fetching the result you can see that the a
key was correctly updated
{ testkey: { a: 101 }, security: { authorizations: [ [Object] ] } }