Skip to content

Commit

Permalink
Merge branch 'main' into feat/local-testnet-simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
KuphJr authored Sep 8, 2023
2 parents 7d90be0 + ce3df4d commit af3384b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-impalas-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/functions-toolkit': patch
---

Renamed storageSlotId to slotId for SecretsManager.uploadEncryptedSecretsToDON()
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ const encryptedSecrets = await secretsManager.encryptSecrets({

Encrypted secrets can be uploaded directly to the DON via gateway URLs such that they can be used when making an on-chain request. This is accomplished by sending a signed POST request to gateway URLs which are connected to the DON. The DON then maintains a decentralized database with eventual consistency, such that the stored values will propagate to all DON nodes. To ensure redundancy, it is always recommended to send encrypted secrets storage requests to multiple gateway URLs.

First, encrypt the secrets with [`encryptSecrets()`](#encrypting-secrets). Then, pass the `encryptedSecrets` hex string in an object to the `uploadEncryptedSecretsToDON()` method as shown below. The `storageSlotId` can be any integer value of zero or greater, however using a previously used slot ID will overwrite the existing data. After `minutesUntilExpiration`, the entry will be deleted from all DON nodes. Get the list of valid gateway URLs for each blockchain network from the [Chainlink Functions documentation](https://docs.chain.link/chainlink-functions/supported-networks).
First, encrypt the secrets with [`encryptSecrets()`](#encrypting-secrets). Then, pass the `encryptedSecrets` hex string in an object to the `uploadEncryptedSecretsToDON()` method as shown below. The `slotId` can be any integer value of zero or greater, however using a previously used slot ID will overwrite the existing data. After `minutesUntilExpiration`, the entry will be deleted from all DON nodes. Get the list of valid gateway URLs for each blockchain network from the [Chainlink Functions documentation](https://docs.chain.link/chainlink-functions/supported-networks).

```
const encryptedSecretsObj = await secretsManager.encryptSecrets({ my: 'secret' })
Expand All @@ -354,7 +354,7 @@ const {
} = await secretsManager.uploadEncryptedSecretsToDON({
encryptedSecretsHexstring: encryptedSecretsObj.encryptedSecrets,
gatewayUrls: [ 'https://exampleGatewayUrl1.com/gateway', 'https://exampleGatewayUrl2.com/gateway', ... ],
storageSlotId: mySlotIdNumber,
slotId: mySlotIdNumber,
minutesUntilExpiration: myExpirationTimeInMinutes,
})
```
Expand Down
12 changes: 6 additions & 6 deletions src/SecretsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ export class SecretsManager {
public async uploadEncryptedSecretsToDON({
encryptedSecretsHexstring,
gatewayUrls,
storageSlotId,
slotId,
minutesUntilExpiration,
}: {
encryptedSecretsHexstring: string
gatewayUrls: string[]
storageSlotId: number
slotId: number
minutesUntilExpiration: number
}): Promise<{ version: number; success: boolean }> {
this.isInitialized()
Expand All @@ -201,8 +201,8 @@ export class SecretsManager {
throw Error('encryptedSecretsHexstring must be a valid hex string')
}

if (!Number.isInteger(storageSlotId) || storageSlotId < 0) {
throw Error('storageSlotId must be a integer of at least 0')
if (!Number.isInteger(slotId) || slotId < 0) {
throw Error('slotId must be a integer of at least 0')
}

if (!Number.isInteger(minutesUntilExpiration) || minutesUntilExpiration < 5) {
Expand All @@ -219,7 +219,7 @@ export class SecretsManager {

const message = {
address: signerAddressBase64,
slotid: storageSlotId,
slotid: slotId,
payload: encryptedSecretsBase64,
version: secretsVersion,
expiration: secretsExpiration,
Expand All @@ -228,7 +228,7 @@ export class SecretsManager {
const storageSignatureBase64 = Buffer.from(storageSignature.slice(2), 'hex').toString('base64')

const payload = {
slot_id: storageSlotId,
slot_id: slotId,
version: secretsVersion,
payload: encryptedSecretsBase64,
expiration: secretsExpiration,
Expand Down
20 changes: 10 additions & 10 deletions test/integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ describe('Functions toolkit classes', () => {
'https://dongateway.com/uploadSuccess1',
'https://dongateway.com/uploadSuccess2',
],
storageSlotId: 0,
slotId: 0,
minutesUntilExpiration: 10,
})

Expand All @@ -1570,7 +1570,7 @@ describe('Functions toolkit classes', () => {
const result = await sm.uploadEncryptedSecretsToDON({
encryptedSecretsHexstring: '0xaaaa',
gatewayUrls: ['https://dongateway.com/1NodeFail'],
storageSlotId: 0,
slotId: 0,
minutesUntilExpiration: 10,
})

Expand All @@ -1589,7 +1589,7 @@ describe('Functions toolkit classes', () => {
await sm.uploadEncryptedSecretsToDON({
encryptedSecretsHexstring: '0xaaaa',
gatewayUrls: ['https://dongateway.com/allNodeFail'],
storageSlotId: 0,
slotId: 0,
minutesUntilExpiration: 10,
}),
).rejects.toThrow(/All nodes failed to store the encrypted secrets/)
Expand All @@ -1604,7 +1604,7 @@ describe('Functions toolkit classes', () => {
await sm.uploadEncryptedSecretsToDON({
encryptedSecretsHexstring: '0xaaaa',
gatewayUrls: [],
storageSlotId: 0,
slotId: 0,
minutesUntilExpiration: 10,
}),
).rejects.toThrow(/gatewayUrls must be a non-empty array of strings/)
Expand All @@ -1619,7 +1619,7 @@ describe('Functions toolkit classes', () => {
await sm.uploadEncryptedSecretsToDON({
encryptedSecretsHexstring: '0xaaaa',
gatewayUrls: ['Invalid URL'],
storageSlotId: 0,
slotId: 0,
minutesUntilExpiration: 10,
}),
).rejects.toThrow(/is not a valid URL/)
Expand All @@ -1634,7 +1634,7 @@ describe('Functions toolkit classes', () => {
await sm.uploadEncryptedSecretsToDON({
encryptedSecretsHexstring: 'aaaa',
gatewayUrls: ['https://dongateway.com/uploadSuccess1'],
storageSlotId: 0,
slotId: 0,
minutesUntilExpiration: 10,
}),
).rejects.toThrow(/encryptedSecretsHexstring must be a valid hex string/)
Expand All @@ -1649,10 +1649,10 @@ describe('Functions toolkit classes', () => {
await sm.uploadEncryptedSecretsToDON({
encryptedSecretsHexstring: '0xaaaa',
gatewayUrls: ['https://dongateway.com/uploadSuccess1'],
storageSlotId: -1,
slotId: -1,
minutesUntilExpiration: 10,
}),
).rejects.toThrow(/storageSlotId must be a integer of at least 0/)
).rejects.toThrow(/slotId must be a integer of at least 0/)
})

it('Throws error for invalid expiration', async () => {
Expand All @@ -1664,7 +1664,7 @@ describe('Functions toolkit classes', () => {
await sm.uploadEncryptedSecretsToDON({
encryptedSecretsHexstring: '0xaaaa',
gatewayUrls: ['https://dongateway.com/uploadSuccess1'],
storageSlotId: 0,
slotId: 0,
minutesUntilExpiration: 4,
}),
).rejects.toThrow(/minutesUntilExpiration must be an integer of at least 5/)
Expand All @@ -1681,7 +1681,7 @@ describe('Functions toolkit classes', () => {
await sm.uploadEncryptedSecretsToDON({
encryptedSecretsHexstring: '0xaaaa',
gatewayUrls: ['https://dongateway.com/uploadSuccess1', 'https://dongateway.com/fail'],
storageSlotId: 0,
slotId: 0,
minutesUntilExpiration: 10,
}),
).rejects.toThrow(
Expand Down

0 comments on commit af3384b

Please sign in to comment.