File tree Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ const _ = require('lodash')
60
60
61
61
let Model = thinky .createModel (' Model' , {})
62
62
63
- Model .encryptedAttributes = EncryptedAttributes ([' secret' ], {
63
+ Model .encryptedAttributes = EncryptedAttributes ([' secret' , ' nested.secret ' ], {
64
64
keys: {
65
65
k1: crypto .randomBytes (32 ).toString (' base64' ) // use an actual key here
66
66
},
@@ -107,6 +107,40 @@ for (let attr of Model.encryptedAttributes.attributes) {
107
107
}
108
108
```
109
109
110
+ And a usage example:
111
+
112
+ ``` js
113
+ async function storeSomeSecrets (doc ) {
114
+ await doc .merge ({
115
+ secret: ' red' ,
116
+ nested: {
117
+ hint: ' colour' ,
118
+ secret: ' yellow'
119
+ }
120
+ }).save ()
121
+
122
+ console .log (await Model .get (1 ))
123
+ // {
124
+ // id: '543bed92-e241-4151-9d8f-1aa942c36d24',
125
+ // nested: {
126
+ // hint: 'colour',
127
+ // secret: 'yellow'
128
+ // },
129
+ // secret: 'red'
130
+ // }
131
+
132
+ console .log (await Model .get (1 ).execute ())
133
+ // {
134
+ // id: '543bed92-e241-4151-9d8f-1aa942c36d24',
135
+ // nested: {
136
+ // hint: 'colour',
137
+ // secret: 'YWVzLTI1Ni1nY20kMSQwMQ==$JvDvLhZ1GlqYgCXx$wQCLkW7u$kt5To2YBdG5USLmtBTHS+g'
138
+ // },
139
+ // secret: 'YWVzLTI1Ni1nY20kMSQwMQ==$0n/ZpuUUIHRzAX5H$jbUS$bFRZOEe3mBrnWVQX6DMA3g'
140
+ // }
141
+ }
142
+ ```
143
+
110
144
# License
111
145
112
146
[ MIT] ( LICENSE )
You can’t perform that action at this time.
0 commit comments