@opengovsg/formsg-sdk 7.5.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs-entry.cjs +4 -1
- package/dist/cjs/crypto-v3.d.ts +2 -2
- package/dist/cjs/crypto-v3.js +8 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/types-v4.d.ts +5 -1
- package/dist/esm/crypto-v3.d.ts +2 -2
- package/dist/esm/crypto-v3.js +8 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/types-v4.d.ts +5 -1
- package/package.json +1 -1
package/cjs-entry.cjs
CHANGED
|
@@ -2,4 +2,7 @@
|
|
|
2
2
|
// TypeScript compiles `export default function` to `exports.default = fn`,
|
|
3
3
|
// but CJS consumers expect `require('@opengovsg/formsg-sdk')` to return
|
|
4
4
|
// the function directly (matching the old v0.15.0 behavior).
|
|
5
|
-
|
|
5
|
+
// Object.assign preserves named exports (adaptV3ToV4, etc.) on the
|
|
6
|
+
// callable default so both `formsg(config)` and `formsg.adaptV3ToV4` work.
|
|
7
|
+
const mod = require('./dist/cjs/index.js')
|
|
8
|
+
module.exports = Object.assign(mod.default, mod)
|
package/dist/cjs/crypto-v3.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import CryptoBase from './crypto-base';
|
|
2
2
|
import { DecryptedContentV3, DecryptParams, DecryptParamsV3, EncryptedContentV3 } from './types';
|
|
3
|
-
import { DecryptedContentV4, FieldResponsesV4, FormFieldMeta } from './types-v4';
|
|
3
|
+
import { DecryptedContentV4, DecryptParamsV4, FieldResponsesV4, FormFieldMeta } from './types-v4';
|
|
4
4
|
/**
|
|
5
5
|
* Checks whether decrypted responses are already in V4 format.
|
|
6
6
|
* V4 entries have a `provenance` object, which V3 entries lack.
|
|
@@ -49,7 +49,7 @@ export default class CryptoV3 extends CryptoBase {
|
|
|
49
49
|
* @returns The decrypted content in V4 format if successful. Else, null will be returned.
|
|
50
50
|
* @throws {MissingPublicKeyError} if a public key is not provided when instantiating this class and is needed for verifying signed content.
|
|
51
51
|
*/
|
|
52
|
-
decryptToV4: (formSecretKey: string, decryptParams:
|
|
52
|
+
decryptToV4: (formSecretKey: string, decryptParams: DecryptParamsV4, formFields: Record<string, FormFieldMeta>) => DecryptedContentV4 | null;
|
|
53
53
|
/**
|
|
54
54
|
* Returns true if a pair of public & secret keys are associated with each other
|
|
55
55
|
* @param publicKey The public key to verify against.
|
package/dist/cjs/crypto-v3.js
CHANGED
|
@@ -209,8 +209,16 @@ var CryptoV3 = /** @class */ (function (_super) {
|
|
|
209
209
|
var responses = isFieldResponsesV4(decrypted.responses)
|
|
210
210
|
? backfillMissingQuestions(decrypted.responses, formFields)
|
|
211
211
|
: (0, adapt_v3_to_v4_1.adaptV3ToV4)(decrypted.responses, { formFields: formFields });
|
|
212
|
+
var stepToken = undefined;
|
|
213
|
+
if (decryptParams.encryptedStepToken) {
|
|
214
|
+
var decryptedStepToken = (0, crypto_1.decryptContent)(formSecretKey, decryptParams.encryptedStepToken);
|
|
215
|
+
if (decryptedStepToken) {
|
|
216
|
+
stepToken = (0, tweetnacl_util_1.encodeUTF8)(decryptedStepToken);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
212
219
|
return {
|
|
213
220
|
submissionSecretKey: decrypted.submissionSecretKey,
|
|
221
|
+
stepToken: stepToken,
|
|
214
222
|
responses: responses,
|
|
215
223
|
verified: decrypted.verified,
|
|
216
224
|
};
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { adaptV3ToV4 } from './adapt-v3-to-v4';
|
|
|
7
7
|
export { adaptV4ToV3 } from './adapt-v4-to-v3';
|
|
8
8
|
export { isFieldResponsesV4 } from './crypto-v3';
|
|
9
9
|
export { ADDRESS_SUBFIELD_KEYS, GENERIC_STRING_FIELD_TYPES, } from './constants-v4';
|
|
10
|
+
export { generateUUID } from './util/crypto';
|
|
10
11
|
export type { DecryptedContent, DecryptedContentV3, DecryptParams, DecryptParamsV3, EncryptedAttachmentContent, EncryptedAttachmentRecords, EncryptedContent, EncryptedContentV3, EncryptedFileContent, FieldType, FormField, FormFieldsV3, Keypair, PackageMode, VerificationOptions, } from './types';
|
|
11
12
|
export type { AdaptV3ToV4Options, AnswerV4, AddressAnswerV4, AttachmentAnswerV4, CheckboxAnswerV4, ChildrenAnswerV4, DecryptedContentV4, FieldResponsesV4, FieldResponseV4, FormFieldMeta, FormFieldV4, FormFieldsV4, RadioAnswerV4, ResponseProvenance, SignatureAnswerV4, StringAnswerV4, TableAnswerV4, VerifiableAnswerV4, } from './types-v4';
|
|
12
13
|
/**
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.GENERIC_STRING_FIELD_TYPES = exports.ADDRESS_SUBFIELD_KEYS = exports.isFieldResponsesV4 = exports.adaptV4ToV3 = exports.adaptV3ToV4 = void 0;
|
|
6
|
+
exports.generateUUID = exports.GENERIC_STRING_FIELD_TYPES = exports.ADDRESS_SUBFIELD_KEYS = exports.isFieldResponsesV4 = exports.adaptV4ToV3 = exports.adaptV3ToV4 = void 0;
|
|
7
7
|
exports.default = default_1;
|
|
8
8
|
var publicKey_1 = require("./util/publicKey");
|
|
9
9
|
var crypto_1 = __importDefault(require("./crypto"));
|
|
@@ -19,6 +19,8 @@ Object.defineProperty(exports, "isFieldResponsesV4", { enumerable: true, get: fu
|
|
|
19
19
|
var constants_v4_1 = require("./constants-v4");
|
|
20
20
|
Object.defineProperty(exports, "ADDRESS_SUBFIELD_KEYS", { enumerable: true, get: function () { return constants_v4_1.ADDRESS_SUBFIELD_KEYS; } });
|
|
21
21
|
Object.defineProperty(exports, "GENERIC_STRING_FIELD_TYPES", { enumerable: true, get: function () { return constants_v4_1.GENERIC_STRING_FIELD_TYPES; } });
|
|
22
|
+
var crypto_2 = require("./util/crypto");
|
|
23
|
+
Object.defineProperty(exports, "generateUUID", { enumerable: true, get: function () { return crypto_2.generateUUID; } });
|
|
22
24
|
/**
|
|
23
25
|
* Entrypoint into the FormSG SDK
|
|
24
26
|
*
|
package/dist/cjs/types-v4.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldType } from './types';
|
|
1
|
+
import { DecryptParamsV3, EncryptedContent, FieldType } from './types';
|
|
2
2
|
export type ResponseProvenance = {
|
|
3
3
|
submittedAt?: string;
|
|
4
4
|
stepNumber?: number;
|
|
@@ -140,8 +140,12 @@ export type AdaptV3ToV4Options = {
|
|
|
140
140
|
/** Form field definitions keyed by field ID, used to populate question text and myInfo. */
|
|
141
141
|
formFields?: Record<string, FormFieldMeta>;
|
|
142
142
|
};
|
|
143
|
+
export interface DecryptParamsV4 extends DecryptParamsV3 {
|
|
144
|
+
encryptedStepToken?: EncryptedContent;
|
|
145
|
+
}
|
|
143
146
|
export type DecryptedContentV4 = {
|
|
144
147
|
submissionSecretKey: string;
|
|
148
|
+
stepToken?: string;
|
|
145
149
|
responses: FieldResponsesV4;
|
|
146
150
|
verified?: Record<string, any>;
|
|
147
151
|
};
|
package/dist/esm/crypto-v3.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import CryptoBase from './crypto-base';
|
|
2
2
|
import { DecryptedContentV3, DecryptParams, DecryptParamsV3, EncryptedContentV3 } from './types';
|
|
3
|
-
import { DecryptedContentV4, FieldResponsesV4, FormFieldMeta } from './types-v4';
|
|
3
|
+
import { DecryptedContentV4, DecryptParamsV4, FieldResponsesV4, FormFieldMeta } from './types-v4';
|
|
4
4
|
/**
|
|
5
5
|
* Checks whether decrypted responses are already in V4 format.
|
|
6
6
|
* V4 entries have a `provenance` object, which V3 entries lack.
|
|
@@ -49,7 +49,7 @@ export default class CryptoV3 extends CryptoBase {
|
|
|
49
49
|
* @returns The decrypted content in V4 format if successful. Else, null will be returned.
|
|
50
50
|
* @throws {MissingPublicKeyError} if a public key is not provided when instantiating this class and is needed for verifying signed content.
|
|
51
51
|
*/
|
|
52
|
-
decryptToV4: (formSecretKey: string, decryptParams:
|
|
52
|
+
decryptToV4: (formSecretKey: string, decryptParams: DecryptParamsV4, formFields: Record<string, FormFieldMeta>) => DecryptedContentV4 | null;
|
|
53
53
|
/**
|
|
54
54
|
* Returns true if a pair of public & secret keys are associated with each other
|
|
55
55
|
* @param publicKey The public key to verify against.
|
package/dist/esm/crypto-v3.js
CHANGED
|
@@ -203,8 +203,16 @@ var CryptoV3 = /** @class */ (function (_super) {
|
|
|
203
203
|
var responses = isFieldResponsesV4(decrypted.responses)
|
|
204
204
|
? backfillMissingQuestions(decrypted.responses, formFields)
|
|
205
205
|
: adaptV3ToV4(decrypted.responses, { formFields: formFields });
|
|
206
|
+
var stepToken = undefined;
|
|
207
|
+
if (decryptParams.encryptedStepToken) {
|
|
208
|
+
var decryptedStepToken = decryptContent(formSecretKey, decryptParams.encryptedStepToken);
|
|
209
|
+
if (decryptedStepToken) {
|
|
210
|
+
stepToken = encodeUTF8(decryptedStepToken);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
206
213
|
return {
|
|
207
214
|
submissionSecretKey: decrypted.submissionSecretKey,
|
|
215
|
+
stepToken: stepToken,
|
|
208
216
|
responses: responses,
|
|
209
217
|
verified: decrypted.verified,
|
|
210
218
|
};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { adaptV3ToV4 } from './adapt-v3-to-v4';
|
|
|
7
7
|
export { adaptV4ToV3 } from './adapt-v4-to-v3';
|
|
8
8
|
export { isFieldResponsesV4 } from './crypto-v3';
|
|
9
9
|
export { ADDRESS_SUBFIELD_KEYS, GENERIC_STRING_FIELD_TYPES, } from './constants-v4';
|
|
10
|
+
export { generateUUID } from './util/crypto';
|
|
10
11
|
export type { DecryptedContent, DecryptedContentV3, DecryptParams, DecryptParamsV3, EncryptedAttachmentContent, EncryptedAttachmentRecords, EncryptedContent, EncryptedContentV3, EncryptedFileContent, FieldType, FormField, FormFieldsV3, Keypair, PackageMode, VerificationOptions, } from './types';
|
|
11
12
|
export type { AdaptV3ToV4Options, AnswerV4, AddressAnswerV4, AttachmentAnswerV4, CheckboxAnswerV4, ChildrenAnswerV4, DecryptedContentV4, FieldResponsesV4, FieldResponseV4, FormFieldMeta, FormFieldV4, FormFieldsV4, RadioAnswerV4, ResponseProvenance, SignatureAnswerV4, StringAnswerV4, TableAnswerV4, VerifiableAnswerV4, } from './types-v4';
|
|
12
13
|
/**
|
package/dist/esm/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { adaptV3ToV4 } from './adapt-v3-to-v4';
|
|
|
7
7
|
export { adaptV4ToV3 } from './adapt-v4-to-v3';
|
|
8
8
|
export { isFieldResponsesV4 } from './crypto-v3';
|
|
9
9
|
export { ADDRESS_SUBFIELD_KEYS, GENERIC_STRING_FIELD_TYPES, } from './constants-v4';
|
|
10
|
+
export { generateUUID } from './util/crypto';
|
|
10
11
|
/**
|
|
11
12
|
* Entrypoint into the FormSG SDK
|
|
12
13
|
*
|
package/dist/esm/types-v4.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldType } from './types';
|
|
1
|
+
import { DecryptParamsV3, EncryptedContent, FieldType } from './types';
|
|
2
2
|
export type ResponseProvenance = {
|
|
3
3
|
submittedAt?: string;
|
|
4
4
|
stepNumber?: number;
|
|
@@ -140,8 +140,12 @@ export type AdaptV3ToV4Options = {
|
|
|
140
140
|
/** Form field definitions keyed by field ID, used to populate question text and myInfo. */
|
|
141
141
|
formFields?: Record<string, FormFieldMeta>;
|
|
142
142
|
};
|
|
143
|
+
export interface DecryptParamsV4 extends DecryptParamsV3 {
|
|
144
|
+
encryptedStepToken?: EncryptedContent;
|
|
145
|
+
}
|
|
143
146
|
export type DecryptedContentV4 = {
|
|
144
147
|
submissionSecretKey: string;
|
|
148
|
+
stepToken?: string;
|
|
145
149
|
responses: FieldResponsesV4;
|
|
146
150
|
verified?: Record<string, any>;
|
|
147
151
|
};
|