Skip to content

Commit af3384b

Browse files
authored
Merge branch 'main' into feat/local-testnet-simulator
2 parents 7d90be0 + ce3df4d commit af3384b

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/functions-toolkit': patch
3+
---
4+
5+
Renamed storageSlotId to slotId for SecretsManager.uploadEncryptedSecretsToDON()

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ const encryptedSecrets = await secretsManager.encryptSecrets({
341341

342342
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.
343343

344-
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).
344+
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).
345345

346346
```
347347
const encryptedSecretsObj = await secretsManager.encryptSecrets({ my: 'secret' })
@@ -354,7 +354,7 @@ const {
354354
} = await secretsManager.uploadEncryptedSecretsToDON({
355355
encryptedSecretsHexstring: encryptedSecretsObj.encryptedSecrets,
356356
gatewayUrls: [ 'https://exampleGatewayUrl1.com/gateway', 'https://exampleGatewayUrl2.com/gateway', ... ],
357-
storageSlotId: mySlotIdNumber,
357+
slotId: mySlotIdNumber,
358358
minutesUntilExpiration: myExpirationTimeInMinutes,
359359
})
360360
```

src/SecretsManager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ export class SecretsManager {
186186
public async uploadEncryptedSecretsToDON({
187187
encryptedSecretsHexstring,
188188
gatewayUrls,
189-
storageSlotId,
189+
slotId,
190190
minutesUntilExpiration,
191191
}: {
192192
encryptedSecretsHexstring: string
193193
gatewayUrls: string[]
194-
storageSlotId: number
194+
slotId: number
195195
minutesUntilExpiration: number
196196
}): Promise<{ version: number; success: boolean }> {
197197
this.isInitialized()
@@ -201,8 +201,8 @@ export class SecretsManager {
201201
throw Error('encryptedSecretsHexstring must be a valid hex string')
202202
}
203203

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

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

220220
const message = {
221221
address: signerAddressBase64,
222-
slotid: storageSlotId,
222+
slotid: slotId,
223223
payload: encryptedSecretsBase64,
224224
version: secretsVersion,
225225
expiration: secretsExpiration,
@@ -228,7 +228,7 @@ export class SecretsManager {
228228
const storageSignatureBase64 = Buffer.from(storageSignature.slice(2), 'hex').toString('base64')
229229

230230
const payload = {
231-
slot_id: storageSlotId,
231+
slot_id: slotId,
232232
version: secretsVersion,
233233
payload: encryptedSecretsBase64,
234234
expiration: secretsExpiration,

test/integration/integration.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ describe('Functions toolkit classes', () => {
15531553
'https://dongateway.com/uploadSuccess1',
15541554
'https://dongateway.com/uploadSuccess2',
15551555
],
1556-
storageSlotId: 0,
1556+
slotId: 0,
15571557
minutesUntilExpiration: 10,
15581558
})
15591559

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

@@ -1589,7 +1589,7 @@ describe('Functions toolkit classes', () => {
15891589
await sm.uploadEncryptedSecretsToDON({
15901590
encryptedSecretsHexstring: '0xaaaa',
15911591
gatewayUrls: ['https://dongateway.com/allNodeFail'],
1592-
storageSlotId: 0,
1592+
slotId: 0,
15931593
minutesUntilExpiration: 10,
15941594
}),
15951595
).rejects.toThrow(/All nodes failed to store the encrypted secrets/)
@@ -1604,7 +1604,7 @@ describe('Functions toolkit classes', () => {
16041604
await sm.uploadEncryptedSecretsToDON({
16051605
encryptedSecretsHexstring: '0xaaaa',
16061606
gatewayUrls: [],
1607-
storageSlotId: 0,
1607+
slotId: 0,
16081608
minutesUntilExpiration: 10,
16091609
}),
16101610
).rejects.toThrow(/gatewayUrls must be a non-empty array of strings/)
@@ -1619,7 +1619,7 @@ describe('Functions toolkit classes', () => {
16191619
await sm.uploadEncryptedSecretsToDON({
16201620
encryptedSecretsHexstring: '0xaaaa',
16211621
gatewayUrls: ['Invalid URL'],
1622-
storageSlotId: 0,
1622+
slotId: 0,
16231623
minutesUntilExpiration: 10,
16241624
}),
16251625
).rejects.toThrow(/is not a valid URL/)
@@ -1634,7 +1634,7 @@ describe('Functions toolkit classes', () => {
16341634
await sm.uploadEncryptedSecretsToDON({
16351635
encryptedSecretsHexstring: 'aaaa',
16361636
gatewayUrls: ['https://dongateway.com/uploadSuccess1'],
1637-
storageSlotId: 0,
1637+
slotId: 0,
16381638
minutesUntilExpiration: 10,
16391639
}),
16401640
).rejects.toThrow(/encryptedSecretsHexstring must be a valid hex string/)
@@ -1649,10 +1649,10 @@ describe('Functions toolkit classes', () => {
16491649
await sm.uploadEncryptedSecretsToDON({
16501650
encryptedSecretsHexstring: '0xaaaa',
16511651
gatewayUrls: ['https://dongateway.com/uploadSuccess1'],
1652-
storageSlotId: -1,
1652+
slotId: -1,
16531653
minutesUntilExpiration: 10,
16541654
}),
1655-
).rejects.toThrow(/storageSlotId must be a integer of at least 0/)
1655+
).rejects.toThrow(/slotId must be a integer of at least 0/)
16561656
})
16571657

16581658
it('Throws error for invalid expiration', async () => {
@@ -1664,7 +1664,7 @@ describe('Functions toolkit classes', () => {
16641664
await sm.uploadEncryptedSecretsToDON({
16651665
encryptedSecretsHexstring: '0xaaaa',
16661666
gatewayUrls: ['https://dongateway.com/uploadSuccess1'],
1667-
storageSlotId: 0,
1667+
slotId: 0,
16681668
minutesUntilExpiration: 4,
16691669
}),
16701670
).rejects.toThrow(/minutesUntilExpiration must be an integer of at least 5/)
@@ -1681,7 +1681,7 @@ describe('Functions toolkit classes', () => {
16811681
await sm.uploadEncryptedSecretsToDON({
16821682
encryptedSecretsHexstring: '0xaaaa',
16831683
gatewayUrls: ['https://dongateway.com/uploadSuccess1', 'https://dongateway.com/fail'],
1684-
storageSlotId: 0,
1684+
slotId: 0,
16851685
minutesUntilExpiration: 10,
16861686
}),
16871687
).rejects.toThrow(

0 commit comments

Comments
 (0)