@icure/api 4.2.31 → 5.0.3
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/icc-api/api/IccDeviceApi.d.ts +3 -3
- package/icc-api/api/IccDeviceApi.js.map +1 -1
- package/icc-api/api/IccHcpartyApi.d.ts +3 -3
- package/icc-api/api/IccHcpartyApi.js.map +1 -1
- package/icc-api/api/IccPatientApi.d.ts +3 -3
- package/icc-api/api/IccPatientApi.js.map +1 -1
- package/icc-api/api/IccUserApi.js +1 -1
- package/icc-api/api/IccUserApi.js.map +1 -1
- package/icc-api/api/XHR.js +2 -1
- package/icc-api/api/XHR.js.map +1 -1
- package/icc-api/iccApi.js +5 -1
- package/icc-api/iccApi.js.map +1 -1
- package/icc-api/index.js +5 -1
- package/icc-api/index.js.map +1 -1
- package/icc-api/model/Body.js +1 -1
- package/icc-api/model/Body.js.map +1 -1
- package/icc-api/model/Body1.js +1 -1
- package/icc-api/model/Body1.js.map +1 -1
- package/icc-api/model/Body2.js +1 -1
- package/icc-api/model/Body2.js.map +1 -1
- package/icc-api/model/Body3.js +1 -1
- package/icc-api/model/Body3.js.map +1 -1
- package/icc-api/model/ByteArray.js +1 -1
- package/icc-api/model/ByteArray.js.map +1 -1
- package/icc-api/model/Content.js +1 -1
- package/icc-api/model/Content.js.map +1 -1
- package/icc-api/model/Device.js +1 -1
- package/icc-api/model/Device.js.map +1 -1
- package/icc-api/model/Document.js +1 -1
- package/icc-api/model/Document.js.map +1 -1
- package/icc-api/model/DocumentTemplate.js +1 -1
- package/icc-api/model/DocumentTemplate.js.map +1 -1
- package/icc-api/model/HealthcareParty.js +1 -1
- package/icc-api/model/HealthcareParty.js.map +1 -1
- package/icc-api/model/MimeAttachment.js +1 -1
- package/icc-api/model/MimeAttachment.js.map +1 -1
- package/icc-api/model/Patient.js +1 -1
- package/icc-api/model/Patient.js.map +1 -1
- package/icc-api/model/models.d.ts +15 -0
- package/icc-api/model/models.js +5 -1
- package/icc-api/model/models.js.map +1 -1
- package/icc-x-api/crypto/AES.d.ts +2 -1
- package/icc-x-api/crypto/AES.js +37 -10
- package/icc-x-api/crypto/AES.js.map +1 -1
- package/icc-x-api/crypto/RSA.d.ts +0 -31
- package/icc-x-api/crypto/RSA.js +0 -64
- package/icc-x-api/crypto/RSA.js.map +1 -1
- package/icc-x-api/crypto/shamir.js.map +1 -1
- package/icc-x-api/filters/filters.js +7 -3
- package/icc-x-api/filters/filters.js.map +1 -1
- package/icc-x-api/icc-accesslog-x-api.js +25 -22
- package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
- package/icc-x-api/icc-bekmehr-x-api.js +2 -2
- package/icc-x-api/icc-bekmehr-x-api.js.map +1 -1
- package/icc-x-api/icc-calendar-item-x-api.d.ts +2 -2
- package/icc-x-api/icc-calendar-item-x-api.js +43 -30
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.js +59 -45
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +127 -54
- package/icc-x-api/icc-crypto-x-api.js +830 -393
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-doctemplate-x-api.js +2 -2
- package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
- package/icc-x-api/icc-document-x-api.js +3 -3
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.js +3 -3
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-hcparty-x-api.js +4 -4
- package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.d.ts +1 -1
- package/icc-x-api/icc-helement-x-api.js +34 -29
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-maintenance-task-x-api.js +5 -6
- package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.d.ts +1 -1
- package/icc-x-api/icc-patient-x-api.js +65 -53
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/index.d.ts +1 -2
- package/icc-x-api/index.js +9 -8
- package/icc-x-api/index.js.map +1 -1
- package/icc-x-api/utils/binary-utils.js +5 -5
- package/icc-x-api/utils/binary-utils.js.map +1 -1
- package/icc-x-api/utils/crypto-utils.d.ts +61 -0
- package/icc-x-api/utils/crypto-utils.js +245 -0
- package/icc-x-api/utils/crypto-utils.js.map +1 -0
- package/icc-x-api/utils/formatting-util.js +3 -3
- package/icc-x-api/utils/formatting-util.js.map +1 -1
- package/icc-x-api/utils/functional-util.d.ts +1 -0
- package/icc-x-api/utils/functional-util.js +8 -1
- package/icc-x-api/utils/functional-util.js.map +1 -1
- package/icc-x-api/utils/index.d.ts +1 -0
- package/icc-x-api/utils/index.js +6 -1
- package/icc-x-api/utils/index.js.map +1 -1
- package/index.js +5 -1
- package/index.js.map +1 -1
- package/node-compat.d.ts +1 -1
- package/node-compat.js +3 -3
- package/node-compat.js.map +1 -1
- package/package.json +2 -2
- package/icc-x-api/crypto/utils.d.ts +0 -68
- package/icc-x-api/crypto/utils.js +0 -239
- package/icc-x-api/crypto/utils.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../icc-api/model/models.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAoC;AACpC,0DAAuC;AACvC,yDAAsC;AACtC,gEAA6C;AAC7C,kEAA+C;AAC/C,0DAAuC;AACvC,kEAA+C;AAC/C,0DAAuC;AACvC,0DAAuC;AACvC,uDAAoC;AACpC,8CAA2B;AAC3B,kDAA+B;AAC/B,4CAAyB;AACzB,2DAAwC;AACxC,2CAAwB;AACxB,sDAAmC;AACnC,wCAAqB;AACrB,iDAA8B;AAC9B,yCAAsB;AACtB,kDAA+B;AAC/B,+CAA4B;AAC5B,wDAAqC;AACrC,4DAAyC;AACzC,4CAAyB;AACzB,wCAA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C7B,4DAAyC;AACzC,wDAAqC;AACrC,kDAA+B;AAC/B,2DAAwC;AACxC,2CAAwB;AACxB,yDAAsC;AACtC,4CAAyB;AACzB,gDAA6B;AAC7B,qDAAkC;AAClC,oDAAiC;AACjC,qDAAkC;AAClC,uDAAoC;AACpC,uDAAoC;AACpC,+CAA4B;AAC5B,0CAAuB;AACvB,0DAAuC;AACvC,4CAAyB;AACzB,+CAA4B;AAC5B,kDAA+B;AAC/B,4CAAyB;AACzB,4CAAyB;AACzB,gDAA6B;AAC7B,8DAA2C;AAC3C,sDAAmC;AACnC,kDAA+B;AAC/B,qDAAkC;AAClC,+CAA4B;AAC5B,8CAA2B;AAC3B,kDAA+B;AAC/B,qDAAkC;AAClC,4CAAyB;AACzB,kDAA+B;AAC/B,qDAAkC;AAClC,mDAAgC;AAChC,kDAA+B;AAC/B,+CAA4B;AAC5B,wCAAqB;AACrB,iDAA8B;AAC9B,4CAAyB;AACzB,+CAA4B;AAC5B,8CAA2B;AAC3B,kDAA+B;AAC/B,kDAA+B;AAC/B,mDAAgC;AAChC,qDAAkC;AAClC,yCAAsB;AACtB,yCAAsB;AACtB,2DAAwC;AACxC,8CAA2B;AAC3B,iDAA8B;AAC9B,0CAAuB;AACvB,gDAA6B;AAC7B,sDAAmC;AACnC,wCAAqB;AACrB,iDAA8B;AAC9B,6CAA0B;AAC1B,iDAA8B;AAC9B,4CAAyB;AACzB,wCAAqB;AACrB,yCAAsB;AACtB,4CAAyB","sourcesContent":["export * from './AbstractFilterCode'\nexport * from './AbstractFilterContact'\nexport * from './AbstractFilterDevice'\nexport * from './AbstractFilterHealthElement'\nexport * from './AbstractFilterHealthcareParty'\nexport * from './AbstractFilterInvoice'\nexport * from './AbstractFilterMaintenanceTask'\nexport * from './AbstractFilterPatient'\nexport * from './AbstractFilterService'\nexport * from './AbstractFilterUser'\nexport * from './AccessLog'\nexport * from './AddedDocument'\nexport * from './Address'\nexport * from './AdministrationQuantity'\nexport * from './Agenda'\nexport * from './AgreementAppendix'\nexport * from './Amp'\nexport * from './AmpComponent'\nexport * from './Ampp'\nexport * from './AmppComponent'\nexport * from './Annotation'\nexport * from './ApplicationSettings'\nexport * from './AppointmentTypeAndPlace'\nexport * from './Article'\nexport * from './Atc'\nexport * from './AuthenticationResponse'\nexport * from './AuthenticationToken'\nexport * from './Basic'\nexport * from './Body'\nexport * from './Body1'\nexport * from './CalendarItem'\nexport * from './CalendarItemTag'\nexport * from './CalendarItemType'\nexport * from './CareTeamMember'\nexport * from './CareTeamMembership'\nexport * from './CheckSMFPatientResult'\nexport * from './Classification'\nexport * from './ClassificationTemplate'\nexport * from './Code'\nexport * from './CodeStub'\nexport * from './CommentedClassification'\nexport * from './Commercialization'\nexport * from './Company'\nexport * from './Contact'\nexport * from './Content'\nexport * from './Copayment'\nexport * from './Data'\nexport * from './DataOwnerRegistrationSuccess'\nexport * from './DatabaseInfo'\nexport * from './DatabaseInitialisation'\nexport * from './DatabaseSynchronization'\nexport * from './Delegation'\nexport * from './Device'\nexport * from './DeviceType'\nexport * from './DiaryNoteExportInfo'\nexport * from './Dmpp'\nexport * from './DocIdentifier'\nexport * from './Document'\nexport * from './DocumentGroup'\nexport * from './DocumentTemplate'\nexport * from './Duration'\nexport * from './EIDItem'\nexport * from './Editor'\nexport * from './EfactInvoice'\nexport * from './Employer'\nexport * from './EmploymentInfo'\nexport * from './EntityReference'\nexport * from './EntityTemplate'\nexport * from './Episode'\nexport * from './FilterChainCode'\nexport * from './FilterChainContact'\nexport * from './FilterChainDevice'\nexport * from './FilterChainHealthElement'\nexport * from './FilterChainHealthcareParty'\nexport * from './FilterChainInvoice'\nexport * from './FilterChainMaintenanceTask'\nexport * from './FilterChainPatient'\nexport * from './FilterChainService'\nexport * from './FilterChainUser'\nexport * from './FinancialInstitutionInformation'\nexport * from './FlatRateTarification'\nexport * from './FlowItem'\nexport * from './Form'\nexport * from './FormColumn'\nexport * from './FormDataOption'\nexport * from './FormLayout'\nexport * from './FormLayoutData'\nexport * from './FormPlanning'\nexport * from './FormSection'\nexport * from './FormTemplate'\nexport * from './FormTemplateLayout'\nexport * from './Formula'\nexport * from './FrontEndMigration'\nexport * from './Group'\nexport * from './GroupDatabasesInfo'\nexport * from './GuiCode'\nexport * from './GuiCodeType'\nexport * from './HealthElement'\nexport * from './HealthcareParty'\nexport * from './HealthcarePartyHistoryStatus'\nexport * from './IcureStub'\nexport * from './IdWithRev'\nexport * from './Identifier'\nexport * from './IdentityDocumentReader'\nexport * from './ImportMapping'\nexport * from './ImportResult'\nexport * from './IncapacityExportInfo'\nexport * from './IndexingInfo'\nexport * from './Ingredient'\nexport * from './Insurability'\nexport * from './Insurance'\nexport * from './Invoice'\nexport * from './InvoiceItem'\nexport * from './InvoiceSender'\nexport * from './InvoicesBatch'\nexport * from './InvoicingCode'\nexport * from './Keyword'\nexport * from './KeywordSubword'\nexport * from './LabelledOccurence'\nexport * from './LetterValue'\nexport * from './ListOfIds'\nexport * from './ListOfProperties'\nexport * from './LoginCredentials'\nexport * from './MaintenanceTask'\nexport * from './MapOfIds'\nexport * from './Measure'\nexport * from './MedexInfo'\nexport * from './MedicalHouseContract'\nexport * from './MedicalLocation'\nexport * from './Medication'\nexport * from './MedicationSchemeExportInfo'\nexport * from './Medicinalproduct'\nexport * from './Message'\nexport * from './MessageReadStatus'\nexport * from './MessageWithBatch'\nexport * from './MessagesReadStatusUpdate'\nexport * from './MimeAttachment'\nexport * from './Nmp'\nexport * from './NoGenericPrescriptionReason'\nexport * from './NoSwitchReason'\nexport * from './NumeratorRange'\nexport * from './PackagingType'\nexport * from './PaginatedDocumentKeyIdPairObject'\nexport * from './PaginatedListAccessLog'\nexport * from './PaginatedListAmp'\nexport * from './PaginatedListClassification'\nexport * from './PaginatedListClassificationTemplate'\nexport * from './PaginatedListCode'\nexport * from './PaginatedListContact'\nexport * from './PaginatedListDevice'\nexport * from './PaginatedListDocument'\nexport * from './PaginatedListEntityTemplate'\nexport * from './PaginatedListForm'\nexport * from './PaginatedListGroup'\nexport * from './PaginatedListHealthElement'\nexport * from './PaginatedListHealthcareParty'\nexport * from './PaginatedListInvoice'\nexport * from './PaginatedListMaintenanceTask'\nexport * from './PaginatedListMessage'\nexport * from './PaginatedListNmp'\nexport * from './PaginatedListPatient'\nexport * from './PaginatedListService'\nexport * from './PaginatedListString'\nexport * from './PaginatedListTarification'\nexport * from './PaginatedListUser'\nexport * from './PaginatedListVmp'\nexport * from './PaginatedListVmpGroup'\nexport * from './Paragraph'\nexport * from './ParagraphAgreement'\nexport * from './Partnership'\nexport * from './Patient'\nexport * from './PatientHealthCareParty'\nexport * from './Payment'\nexport * from './Periodicity'\nexport * from './Permission'\nexport * from './PermissionItem'\nexport * from './PersonName'\nexport * from './PharmaceuticalForm'\nexport * from './PharmaceuticalFormStub'\nexport * from './Place'\nexport * from './PlanOfAction'\nexport * from './Predicate'\nexport * from './Pricing'\nexport * from './PropertyStub'\nexport * from './PropertyTypeStub'\nexport * from './PublicKey'\nexport * from './Quantity'\nexport * from './Receipt'\nexport * from './ReferralPeriod'\nexport * from './RegimenItem'\nexport * from './RegistrationInformation'\nexport * from './RegistrationSuccess'\nexport * from './Reimbursement'\nexport * from './ReimbursementCriterion'\nexport * from './Remote'\nexport * from './RemoteAuthentication'\nexport * from './Renewal'\nexport * from './Replication'\nexport * from './ReplicateCommand'\nexport * from './ReplicationInfo'\nexport * from './ReplicationStats'\nexport * from './ReplicatorDocument'\nexport * from './ReplicatorResponse'\nexport * from './ResultInfo'\nexport * from './Right'\nexport * from './RouteOfAdministration'\nexport * from './SamText'\nexport * from './SamVersion'\nexport * from './SchoolingInfo'\nexport * from './Section'\nexport * from './Service'\nexport * from './ServiceLink'\nexport * from './SoftwareMedicalFileExport'\nexport * from './StandardSubstance'\nexport * from './StrengthRange'\nexport * from './StructureElement'\nexport * from './SubContact'\nexport * from './Substance'\nexport * from './SubstanceStub'\nexport * from './Substanceproduct'\nexport * from './Suggest'\nexport * from './SumehrContent'\nexport * from './SumehrExportInfo'\nexport * from './SumehrValidity'\nexport * from './SupplyProblem'\nexport * from './Suspension'\nexport * from './Tag'\nexport * from './Tarification'\nexport * from './Telecom'\nexport * from './TimeSeries'\nexport * from './TimeTable'\nexport * from './TimeTableHour'\nexport * from './TimeTableItem'\nexport * from './TokenWithGroup'\nexport * from './TypedValueObject'\nexport * from './Unit'\nexport * from './User'\nexport * from './UserAndHealthcareParty'\nexport * from './UserGroup'\nexport * from './Valorisation'\nexport * from './Verse'\nexport * from './VirtualForm'\nexport * from './VirtualIngredient'\nexport * from './Vmp'\nexport * from './VmpComponent'\nexport * from './VmpGroup'\nexport * from './VmpGroupStub'\nexport * from './VmpStub'\nexport * from './Vtm'\nexport * from './Wada'\nexport * from './Weekday'\n"]}
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../icc-api/model/models.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAcA,uDAAoC;AACpC,0DAAuC;AACvC,yDAAsC;AACtC,gEAA6C;AAC7C,kEAA+C;AAC/C,0DAAuC;AACvC,kEAA+C;AAC/C,0DAAuC;AACvC,0DAAuC;AACvC,uDAAoC;AACpC,8CAA2B;AAC3B,kDAA+B;AAC/B,4CAAyB;AACzB,2DAAwC;AACxC,2CAAwB;AACxB,sDAAmC;AACnC,wCAAqB;AACrB,iDAA8B;AAC9B,yCAAsB;AACtB,kDAA+B;AAC/B,+CAA4B;AAC5B,wDAAqC;AACrC,4DAAyC;AACzC,4CAAyB;AACzB,wCAAqB;AACrB,2DAAwC;AACxC,wDAAqC;AACrC,0CAAuB;AACvB,yCAAsB;AACtB,0CAAuB;AACvB,iDAA8B;AAC9B,oDAAiC;AACjC,qDAAkC;AAClC,mDAAgC;AAChC,uDAAoC;AACpC,0DAAuC;AACvC,mDAAgC;AAChC,2DAAwC;AACxC,yCAAsB;AACtB,6CAA0B;AAC1B,4DAAyC;AACzC,sDAAmC;AACnC,4CAAyB;AACzB,4CAAyB;AACzB,4CAAyB;AACzB,8CAA2B;AAC3B,yCAA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;AAC7B,8DAA2C;AAC3C,sDAAmC;AACnC,kDAA+B;AAC/B,qDAAkC;AAClC,+CAA4B;AAC5B,8CAA2B;AAC3B,kDAA+B;AAC/B,qDAAkC;AAClC,4CAAyB;AACzB,kDAA+B;AAC/B,qDAAkC;AAClC,mDAAgC;AAChC,kDAA+B;AAC/B,+CAA4B;AAC5B,wCAAqB;AACrB,iDAA8B;AAC9B,4CAAyB;AACzB,+CAA4B;AAC5B,8CAA2B;AAC3B,kDAA+B;AAC/B,kDAA+B;AAC/B,mDAAgC;AAChC,qDAAkC;AAClC,yCAAsB;AACtB,yCAAsB;AACtB,2DAAwC;AACxC,8CAA2B;AAC3B,iDAA8B;AAC9B,0CAAuB;AACvB,gDAA6B;AAC7B,sDAAmC;AACnC,wCAAqB;AACrB,iDAA8B;AAC9B,6CAA0B;AAC1B,iDAA8B;AAC9B,4CAAyB;AACzB,wCAAqB;AACrB,yCAAsB;AACtB,4CAAyB","sourcesContent":["import { AccessLog } from './AccessLog'\nimport { Article } from './Article'\nimport { Classification } from './Classification'\nimport { Document } from './Document'\nimport { HealthElement } from './HealthElement'\nimport { Invoice } from './Invoice'\nimport { Form } from './Form'\nimport { Contact } from './Contact'\nimport { CalendarItem } from './CalendarItem'\nimport { MaintenanceTask } from './MaintenanceTask'\nimport { Message } from './Message'\nimport { Receipt } from './Receipt'\nimport { Patient } from './Patient'\n\nexport * from './AbstractFilterCode'\nexport * from './AbstractFilterContact'\nexport * from './AbstractFilterDevice'\nexport * from './AbstractFilterHealthElement'\nexport * from './AbstractFilterHealthcareParty'\nexport * from './AbstractFilterInvoice'\nexport * from './AbstractFilterMaintenanceTask'\nexport * from './AbstractFilterPatient'\nexport * from './AbstractFilterService'\nexport * from './AbstractFilterUser'\nexport * from './AccessLog'\nexport * from './AddedDocument'\nexport * from './Address'\nexport * from './AdministrationQuantity'\nexport * from './Agenda'\nexport * from './AgreementAppendix'\nexport * from './Amp'\nexport * from './AmpComponent'\nexport * from './Ampp'\nexport * from './AmppComponent'\nexport * from './Annotation'\nexport * from './ApplicationSettings'\nexport * from './AppointmentTypeAndPlace'\nexport * from './Article'\nexport * from './Atc'\nexport * from './AuthenticationResponse'\nexport * from './AuthenticationToken'\nexport * from './Basic'\nexport * from './Body'\nexport * from './Body1'\nexport * from './CalendarItem'\nexport * from './CalendarItemTag'\nexport * from './CalendarItemType'\nexport * from './CareTeamMember'\nexport * from './CareTeamMembership'\nexport * from './CheckSMFPatientResult'\nexport * from './Classification'\nexport * from './ClassificationTemplate'\nexport * from './Code'\nexport * from './CodeStub'\nexport * from './CommentedClassification'\nexport * from './Commercialization'\nexport * from './Company'\nexport * from './Contact'\nexport * from './Content'\nexport * from './Copayment'\nexport * from './Data'\nexport * from './DataOwnerRegistrationSuccess'\nexport * from './DatabaseInfo'\nexport * from './DatabaseInitialisation'\nexport * from './DatabaseSynchronization'\nexport * from './Delegation'\nexport * from './Device'\nexport * from './DeviceType'\nexport * from './DiaryNoteExportInfo'\nexport * from './Dmpp'\nexport * from './DocIdentifier'\nexport * from './Document'\nexport * from './DocumentGroup'\nexport * from './DocumentTemplate'\nexport * from './Duration'\nexport * from './EIDItem'\nexport * from './Editor'\nexport * from './EfactInvoice'\nexport * from './Employer'\nexport * from './EmploymentInfo'\nexport * from './EntityReference'\nexport * from './EntityTemplate'\nexport * from './Episode'\nexport * from './FilterChainCode'\nexport * from './FilterChainContact'\nexport * from './FilterChainDevice'\nexport * from './FilterChainHealthElement'\nexport * from './FilterChainHealthcareParty'\nexport * from './FilterChainInvoice'\nexport * from './FilterChainMaintenanceTask'\nexport * from './FilterChainPatient'\nexport * from './FilterChainService'\nexport * from './FilterChainUser'\nexport * from './FinancialInstitutionInformation'\nexport * from './FlatRateTarification'\nexport * from './FlowItem'\nexport * from './Form'\nexport * from './FormColumn'\nexport * from './FormDataOption'\nexport * from './FormLayout'\nexport * from './FormLayoutData'\nexport * from './FormPlanning'\nexport * from './FormSection'\nexport * from './FormTemplate'\nexport * from './FormTemplateLayout'\nexport * from './Formula'\nexport * from './FrontEndMigration'\nexport * from './Group'\nexport * from './GroupDatabasesInfo'\nexport * from './GuiCode'\nexport * from './GuiCodeType'\nexport * from './HealthElement'\nexport * from './HealthcareParty'\nexport * from './HealthcarePartyHistoryStatus'\nexport * from './IcureStub'\nexport * from './IdWithRev'\nexport * from './Identifier'\nexport * from './IdentityDocumentReader'\nexport * from './ImportMapping'\nexport * from './ImportResult'\nexport * from './IncapacityExportInfo'\nexport * from './IndexingInfo'\nexport * from './Ingredient'\nexport * from './Insurability'\nexport * from './Insurance'\nexport * from './Invoice'\nexport * from './InvoiceItem'\nexport * from './InvoiceSender'\nexport * from './InvoicesBatch'\nexport * from './InvoicingCode'\nexport * from './Keyword'\nexport * from './KeywordSubword'\nexport * from './LabelledOccurence'\nexport * from './LetterValue'\nexport * from './ListOfIds'\nexport * from './ListOfProperties'\nexport * from './LoginCredentials'\nexport * from './MaintenanceTask'\nexport * from './MapOfIds'\nexport * from './Measure'\nexport * from './MedexInfo'\nexport * from './MedicalHouseContract'\nexport * from './MedicalLocation'\nexport * from './Medication'\nexport * from './MedicationSchemeExportInfo'\nexport * from './Medicinalproduct'\nexport * from './Message'\nexport * from './MessageReadStatus'\nexport * from './MessageWithBatch'\nexport * from './MessagesReadStatusUpdate'\nexport * from './MimeAttachment'\nexport * from './Nmp'\nexport * from './NoGenericPrescriptionReason'\nexport * from './NoSwitchReason'\nexport * from './NumeratorRange'\nexport * from './PackagingType'\nexport * from './PaginatedDocumentKeyIdPairObject'\nexport * from './PaginatedListAccessLog'\nexport * from './PaginatedListAmp'\nexport * from './PaginatedListClassification'\nexport * from './PaginatedListClassificationTemplate'\nexport * from './PaginatedListCode'\nexport * from './PaginatedListContact'\nexport * from './PaginatedListDevice'\nexport * from './PaginatedListDocument'\nexport * from './PaginatedListEntityTemplate'\nexport * from './PaginatedListForm'\nexport * from './PaginatedListGroup'\nexport * from './PaginatedListHealthElement'\nexport * from './PaginatedListHealthcareParty'\nexport * from './PaginatedListInvoice'\nexport * from './PaginatedListMaintenanceTask'\nexport * from './PaginatedListMessage'\nexport * from './PaginatedListNmp'\nexport * from './PaginatedListPatient'\nexport * from './PaginatedListService'\nexport * from './PaginatedListString'\nexport * from './PaginatedListTarification'\nexport * from './PaginatedListUser'\nexport * from './PaginatedListVmp'\nexport * from './PaginatedListVmpGroup'\nexport * from './Paragraph'\nexport * from './ParagraphAgreement'\nexport * from './Partnership'\nexport * from './Patient'\nexport * from './PatientHealthCareParty'\nexport * from './Payment'\nexport * from './Periodicity'\nexport * from './Permission'\nexport * from './PermissionItem'\nexport * from './PersonName'\nexport * from './PharmaceuticalForm'\nexport * from './PharmaceuticalFormStub'\nexport * from './Place'\nexport * from './PlanOfAction'\nexport * from './Predicate'\nexport * from './Pricing'\nexport * from './PropertyStub'\nexport * from './PropertyTypeStub'\nexport * from './PublicKey'\nexport * from './Quantity'\nexport * from './Receipt'\nexport * from './ReferralPeriod'\nexport * from './RegimenItem'\nexport * from './RegistrationInformation'\nexport * from './RegistrationSuccess'\nexport * from './Reimbursement'\nexport * from './ReimbursementCriterion'\nexport * from './Remote'\nexport * from './RemoteAuthentication'\nexport * from './Renewal'\nexport * from './Replication'\nexport * from './ReplicateCommand'\nexport * from './ReplicationInfo'\nexport * from './ReplicationStats'\nexport * from './ReplicatorDocument'\nexport * from './ReplicatorResponse'\nexport * from './ResultInfo'\nexport * from './Right'\nexport * from './RouteOfAdministration'\nexport * from './SamText'\nexport * from './SamVersion'\nexport * from './SchoolingInfo'\nexport * from './Section'\nexport * from './Service'\nexport * from './ServiceLink'\nexport * from './SoftwareMedicalFileExport'\nexport * from './StandardSubstance'\nexport * from './StrengthRange'\nexport * from './StructureElement'\nexport * from './SubContact'\nexport * from './Substance'\nexport * from './SubstanceStub'\nexport * from './Substanceproduct'\nexport * from './Suggest'\nexport * from './SumehrContent'\nexport * from './SumehrExportInfo'\nexport * from './SumehrValidity'\nexport * from './SupplyProblem'\nexport * from './Suspension'\nexport * from './Tag'\nexport * from './Tarification'\nexport * from './Telecom'\nexport * from './TimeSeries'\nexport * from './TimeTable'\nexport * from './TimeTableHour'\nexport * from './TimeTableItem'\nexport * from './TokenWithGroup'\nexport * from './TypedValueObject'\nexport * from './Unit'\nexport * from './User'\nexport * from './UserAndHealthcareParty'\nexport * from './UserGroup'\nexport * from './Valorisation'\nexport * from './Verse'\nexport * from './VirtualForm'\nexport * from './VirtualIngredient'\nexport * from './Vmp'\nexport * from './VmpComponent'\nexport * from './VmpGroup'\nexport * from './VmpGroupStub'\nexport * from './VmpStub'\nexport * from './Vtm'\nexport * from './Wada'\nexport * from './Weekday'\n\nexport type EncryptedEntity =\n | AccessLog\n | Article\n | CalendarItem\n | Classification\n | Contact\n | Document\n | Form\n | HealthElement\n | Invoice\n | MaintenanceTask\n | Message\n | Patient\n | Receipt\nexport type EncryptedParentEntity = Message | Patient\n"]}
|
|
@@ -16,6 +16,7 @@ export declare class AESUtils {
|
|
|
16
16
|
* @returns {Promise} will be ArrayBuffer
|
|
17
17
|
*/
|
|
18
18
|
decrypt(cryptoKey: CryptoKey, encryptedData: ArrayBuffer | Uint8Array, rawKey?: string): Promise<ArrayBuffer>;
|
|
19
|
+
decryptSome(cryptoKeys: CryptoKey[], uint8Array: Uint8Array): Promise<ArrayBuffer>;
|
|
19
20
|
/**
|
|
20
21
|
*
|
|
21
22
|
* @param toHex boolean, if true, it returns hex String
|
|
@@ -46,6 +47,6 @@ export declare class AESUtils {
|
|
|
46
47
|
* @param aesKey
|
|
47
48
|
* @returns {*}
|
|
48
49
|
*/
|
|
49
|
-
importKey(format:
|
|
50
|
+
importKey(format: 'jwk' | 'raw', aesKey: JsonWebKey | ArrayBuffer | Uint8Array): Promise<CryptoKey>;
|
|
50
51
|
}
|
|
51
52
|
export declare const AES: AESUtils;
|
package/icc-x-api/crypto/AES.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.AES = exports.AESUtils = void 0;
|
|
4
|
-
const utils_1 = require("
|
|
5
|
-
const binary_utils_1 = require("../utils/binary-utils");
|
|
13
|
+
const utils_1 = require("../utils");
|
|
6
14
|
class AESUtils {
|
|
7
15
|
constructor(crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : {}) {
|
|
8
16
|
/********* AES Config **********/
|
|
@@ -12,8 +20,8 @@ class AESUtils {
|
|
|
12
20
|
name: 'AES-CBC',
|
|
13
21
|
length: 256,
|
|
14
22
|
};
|
|
15
|
-
this.crypto = crypto;
|
|
16
23
|
this._debug = false;
|
|
24
|
+
this.crypto = crypto;
|
|
17
25
|
}
|
|
18
26
|
set debug(value) {
|
|
19
27
|
this._debug = value;
|
|
@@ -28,10 +36,13 @@ class AESUtils {
|
|
|
28
36
|
name: this.aesAlgorithmEncryptName,
|
|
29
37
|
iv: this.generateIV(this.ivLength),
|
|
30
38
|
};
|
|
31
|
-
this._debug && console.log(`encrypt ${plainData} with ${rawKey}`);
|
|
39
|
+
this._debug && console.log(`encrypt ${(0, utils_1.ua2hex)(plainData)} with ${rawKey}`);
|
|
32
40
|
this.crypto.subtle
|
|
33
41
|
.encrypt(Object.assign({}, aesAlgorithmEncrypt), cryptoKey, plainData)
|
|
34
|
-
.then((cipherData) =>
|
|
42
|
+
.then((cipherData) => {
|
|
43
|
+
this._debug && console.log(`cipherData: ${(0, utils_1.ua2hex)(cipherData)}`);
|
|
44
|
+
return resolve((0, utils_1.appendBuffer)(aesAlgorithmEncrypt.iv.buffer, cipherData));
|
|
45
|
+
}, (err) => reject('AES encryption failed: ' + err));
|
|
35
46
|
});
|
|
36
47
|
}
|
|
37
48
|
/**
|
|
@@ -67,14 +78,30 @@ class AESUtils {
|
|
|
67
78
|
* var delegateHcPartyKey = hcparty.hcPartyKeys[delegatorId][1];
|
|
68
79
|
*/
|
|
69
80
|
};
|
|
70
|
-
this._debug && console.log(`decrypt with ${rawKey}`);
|
|
71
|
-
this.crypto.subtle
|
|
72
|
-
.
|
|
73
|
-
|
|
81
|
+
this._debug && console.log(`decrypt ${(0, utils_1.ua2hex)(encryptedData)} with ${rawKey}`);
|
|
82
|
+
this.crypto.subtle.decrypt(aesAlgorithmEncrypt, cryptoKey, encryptedDataUint8.subarray(this.ivLength, encryptedDataUint8.length)).then((decipheredData) => {
|
|
83
|
+
this._debug && console.log(`decipheredData: ${(0, utils_1.ua2hex)(decipheredData)}`);
|
|
84
|
+
resolve(decipheredData);
|
|
85
|
+
}, (err) => {
|
|
74
86
|
reject('AES decryption failed: ' + err);
|
|
75
87
|
});
|
|
76
88
|
});
|
|
77
89
|
}
|
|
90
|
+
decryptSome(cryptoKeys, uint8Array) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
try {
|
|
93
|
+
return this.decrypt(cryptoKeys[0], uint8Array);
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
if (cryptoKeys.length > 1) {
|
|
97
|
+
return this.decryptSome(cryptoKeys.slice(1), uint8Array);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
78
105
|
generateCryptoKey(toHex) {
|
|
79
106
|
return new Promise((resolve, reject) => {
|
|
80
107
|
const extractable = true;
|
|
@@ -82,7 +109,7 @@ class AESUtils {
|
|
|
82
109
|
const cryptoKeyPromise = this.crypto.subtle.generateKey(this.aesKeyGenParams, extractable, keyUsages);
|
|
83
110
|
return toHex === undefined || !toHex
|
|
84
111
|
? cryptoKeyPromise.then(resolve, reject)
|
|
85
|
-
: cryptoKeyPromise.then((k) => this.exportKey(k, 'raw'), reject).then((raw) => resolve(
|
|
112
|
+
: cryptoKeyPromise.then((k) => this.exportKey(k, 'raw'), reject).then((raw) => resolve((0, utils_1.ua2hex)(raw)), reject);
|
|
86
113
|
});
|
|
87
114
|
}
|
|
88
115
|
// noinspection JSMethodCanBeStatic
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AES.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/AES.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAC/B,wDAA8C;AAE9C,MAAa,QAAQ;IAgBnB,YAAY,SAAiB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,EAAa;QAfvI,iCAAiC;QACjC,aAAQ,GAAG,EAAE,CAAA;QACb,4BAAuB,GAAG,SAAS,CAAA;QAEnC,oBAAe,GAAoB;YACjC,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,GAAG;SACZ,CAAA;QASC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAPD,IAAI,KAAK,CAAC,KAAc;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAOD,OAAO,CAAC,SAAoB,EAAE,SAAmC,EAAE,MAAM,GAAG,MAAM;QAChF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAoC,EAAE,MAA4B,EAAE,EAAE;YACxF,I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AO,CAAC,qBAAM,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;QAChH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,mCAAmC;IACnC,UAAU,CAAC,YAAoB;QAC7B,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IAClF,CAAC;IAYD,SAAS,CAAC,SAAoB,EAAE,MAAc;QAC5C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAiD,EAAE,MAA4B,EAAE,EAAE;YACrG,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QAC9E,CAAC,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,MAAc,EAAE,MAA6C;QACrE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAkC,EAAE,MAA4B,EAAE,EAAE;YACtF,MAAM,WAAW,GAAG,IAAI,CAAA;YACxB,MAAM,SAAS,GAAe,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;YACpD,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QACzH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAtJD,4BAsJC;AAEY,QAAA,GAAG,GAAG,IAAI,QAAQ,EAAE,CAAA","sourcesContent":["import { utils } from './utils'\nimport { ua2hex } from '../utils/binary-utils'\n\nexport class AESUtils {\n /********* AES Config **********/\n ivLength = 16\n aesAlgorithmEncryptName = 'AES-CBC'\n\n aesKeyGenParams: AesKeyGenParams = {\n name: 'AES-CBC',\n length: 256,\n }\n private crypto: Crypto\n private _debug: boolean\n\n set debug(value: boolean) {\n this._debug = value\n }\n\n constructor(crypto: Crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : ({} as Crypto)) {\n this.crypto = crypto\n this._debug = false\n }\n\n encrypt(cryptoKey: CryptoKey, plainData: ArrayBuffer | Uint8Array, rawKey = '<NA>'): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject: (reason: any) => any) => {\n if (plainData instanceof Uint8Array) {\n const buffer = plainData.buffer\n plainData = (buffer.byteLength > plainData.byteLength ? buffer.slice(0, plainData.byteLength) : buffer) as ArrayBuffer\n }\n const aesAlgorithmEncrypt = {\n name: this.aesAlgorithmEncryptName,\n iv: this.generateIV(this.ivLength),\n }\n this._debug && console.log(`encrypt ${plainData} with ${rawKey}`)\n this.crypto.subtle\n .encrypt(\n {\n ...aesAlgorithmEncrypt,\n } /* some ill behaved implementations change the values in place */,\n cryptoKey,\n plainData\n )\n .then(\n (cipherData) => resolve(utils.appendBuffer(aesAlgorithmEncrypt.iv.buffer as ArrayBuffer, cipherData)),\n (err) => reject('AES encryption failed: ' + err)\n )\n })\n }\n\n /**\n *\n * @param cryptoKey (CryptoKey)\n * @param encryptedData (ArrayBuffer)\n * @param rawKey\n * @returns {Promise} will be ArrayBuffer\n */\n decrypt(cryptoKey: CryptoKey, encryptedData: ArrayBuffer | Uint8Array, rawKey = '<NA>'): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject: (reason: any) => any) => {\n if (!cryptoKey) {\n return reject('No crypto key provided for decryption')\n }\n const encryptedDataUint8 = encryptedData instanceof ArrayBuffer ? new Uint8Array(encryptedData) : encryptedData\n const aesAlgorithmEncrypt = {\n name: this.aesAlgorithmEncryptName,\n iv: encryptedDataUint8.subarray(0, this.ivLength),\n\n /*\n * IF THIS BIT OF CODE PRODUCES A DOMEXCEPTION CODE 0 ERROR, IT MIGHT BE RELATED TO THIS:\n *\n * NOTOK:\n * if (!hcparty.hcPartyKeys && !hcparty.hcPartyKeys[hcpartyId] && hcparty.hcPartyKeys[hcpartyId].length !== 2) {\n * throw 'No hcPartyKey for this Healthcare party(' + hcpartyId + ').';\n * }\n * var delegateHcPartyKey = hcparty.hcPartyKeys[hcpartyId][1];\n *\n * SHOULD BE:\n * var delegatorId = patient.delegations[hcpartyId][0].owner;\n * if (!hcparty.hcPartyKeys && !hcparty.hcPartyKeys[delegatorId] && hcparty.hcPartyKeys[delegatorId].length !== 2) {\n * throw 'No hcPartyKey for this Healthcare party(' + delegatorId + ').';\n * }\n * var delegateHcPartyKey = hcparty.hcPartyKeys[delegatorId][1];\n */\n }\n this._debug && console.log(`decrypt with ${rawKey}`)\n this.crypto.subtle\n .decrypt(aesAlgorithmEncrypt, cryptoKey, encryptedDataUint8.subarray(this.ivLength, encryptedDataUint8.length))\n .then(resolve, (err) => {\n reject('AES decryption failed: ' + err)\n })\n })\n }\n\n // generate an AES key\n // noinspection JSUnusedGlobalSymbols\n /**\n *\n * @param toHex boolean, if true, it returns hex String\n * @returns {Promise} either Hex string or CryptoKey\n */\n generateCryptoKey(toHex: false): Promise<CryptoKey>\n generateCryptoKey(toHex: true): Promise<string>\n generateCryptoKey(toHex: boolean): Promise<string | CryptoKey> {\n return new Promise((resolve: (value: CryptoKey | string) => any, reject: (reason: any) => any) => {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n const cryptoKeyPromise: Promise<CryptoKey> = this.crypto.subtle.generateKey(this.aesKeyGenParams, extractable, keyUsages) as Promise<CryptoKey>\n return toHex === undefined || !toHex\n ? cryptoKeyPromise.then(resolve, reject)\n : cryptoKeyPromise.then((k) => this.exportKey(k, 'raw'), reject).then((raw) => resolve(ua2hex(raw)), reject)\n })\n }\n\n // noinspection JSMethodCanBeStatic\n generateIV(ivByteLength: number): Uint8Array {\n return new Uint8Array(this.crypto.getRandomValues(new Uint8Array(ivByteLength)))\n }\n\n /**\n * This function return a promise which will be the key Format will be either 'raw' or 'jwk'.\n * JWK: Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11)\n *\n * @param cryptoKey CryptoKey\n * @param format will be 'raw' or 'jwk'\n * @returns {Promise} will the AES Key\n */\n exportKey(cryptoKey: CryptoKey, format: 'raw'): Promise<ArrayBuffer>\n exportKey(cryptoKey: CryptoKey, format: 'jwk'): Promise<JsonWebKey>\n exportKey(cryptoKey: CryptoKey, format: string): Promise<ArrayBuffer | JsonWebKey> {\n return new Promise((resolve: (value: ArrayBuffer | JsonWebKey) => any, reject: (reason: any) => any) => {\n return this.crypto.subtle.exportKey(format, cryptoKey).then(resolve, reject)\n })\n }\n\n /**\n * the ability to import a key that have already been created elsewhere, for use within the web\n * application that is invoking the import function, for use within the importing web application's\n * origin. This necessiates an interoperable key format, such as JSON Web Key [JWK] which may be\n * represented as octets.\n *\n * https://chromium.googlesource.com/chromium/blink.git/+/6b902997e3ca0384c8fa6fe56f79ecd7589d3ca6/LayoutTests/crypto/resources/common.js\n *\n * @param format 'raw' or 'jwk'\n * @param aesKey\n * @returns {*}\n */\n importKey(format: string, aesKey: JsonWebKey | ArrayBuffer | Uint8Array): Promise<CryptoKey> {\n return new Promise((resolve: (value: CryptoKey) => any, reject: (reason: any) => any) => {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n return this.crypto.subtle.importKey(format, aesKey, this.aesKeyGenParams, extractable, keyUsages).then(resolve, reject)\n })\n }\n}\n\nexport const AES = new AESUtils()\n"]}
|
|
1
|
+
{"version":3,"file":"AES.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/AES.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAA+C;AAE/C,MAAa,QAAQ;IAgBnB,YAAY,SAAiB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC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AC,OAAO,CAAC,IAAA,cAAM,EAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;QAChH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,mCAAmC;IACnC,UAAU,CAAC,YAAoB;QAC7B,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IAClF,CAAC;IAYD,SAAS,CAAC,SAAoB,EAAE,MAAqB;QACnD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAiD,EAAE,MAA4B,EAAE,EAAE;YACrG,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,MAAa,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QACrF,CAAC,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,MAAqB,EAAE,MAA6C;QAC5E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAkC,EAAE,MAA4B,EAAE,EAAE;YACtF,MAAM,WAAW,GAAG,IAAI,CAAA;YACxB,MAAM,SAAS,GAAe,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;YACpD,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,MAAa,EAAE,MAAa,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QACvI,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAxKD,4BAwKC;AAEY,QAAA,GAAG,GAAG,IAAI,QAAQ,EAAE,CAAA","sourcesContent":["import { appendBuffer, ua2hex } from '../utils'\n\nexport class AESUtils {\n /********* AES Config **********/\n ivLength = 16\n aesAlgorithmEncryptName = 'AES-CBC'\n\n aesKeyGenParams: AesKeyGenParams = {\n name: 'AES-CBC',\n length: 256,\n }\n private crypto: Crypto\n private _debug: boolean = false\n\n set debug(value: boolean) {\n this._debug = value\n }\n\n constructor(crypto: Crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : ({} as Crypto)) {\n this.crypto = crypto\n }\n\n encrypt(cryptoKey: CryptoKey, plainData: ArrayBuffer | Uint8Array, rawKey = '<NA>'): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject: (reason: any) => any) => {\n if (plainData instanceof Uint8Array) {\n const buffer = plainData.buffer\n plainData = (buffer.byteLength > plainData.byteLength ? buffer.slice(0, plainData.byteLength) : buffer) as ArrayBuffer\n }\n const aesAlgorithmEncrypt = {\n name: this.aesAlgorithmEncryptName,\n iv: this.generateIV(this.ivLength),\n }\n this._debug && console.log(`encrypt ${ua2hex(plainData)} with ${rawKey}`)\n this.crypto.subtle\n .encrypt(\n {\n ...aesAlgorithmEncrypt,\n } /* some ill behaved implementations change the values in place */,\n cryptoKey,\n plainData\n )\n .then(\n (cipherData) => {\n this._debug && console.log(`cipherData: ${ua2hex(cipherData)}`)\n return resolve(appendBuffer(aesAlgorithmEncrypt.iv.buffer as ArrayBuffer, cipherData))\n },\n (err) => reject('AES encryption failed: ' + err)\n )\n })\n }\n\n /**\n *\n * @param cryptoKey (CryptoKey)\n * @param encryptedData (ArrayBuffer)\n * @param rawKey\n * @returns {Promise} will be ArrayBuffer\n */\n decrypt(cryptoKey: CryptoKey, encryptedData: ArrayBuffer | Uint8Array, rawKey = '<NA>'): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject: (reason: any) => any) => {\n if (!cryptoKey) {\n return reject('No crypto key provided for decryption')\n }\n const encryptedDataUint8 = encryptedData instanceof ArrayBuffer ? new Uint8Array(encryptedData) : encryptedData\n const aesAlgorithmEncrypt = {\n name: this.aesAlgorithmEncryptName,\n iv: encryptedDataUint8.subarray(0, this.ivLength),\n\n /*\n * IF THIS BIT OF CODE PRODUCES A DOMEXCEPTION CODE 0 ERROR, IT MIGHT BE RELATED TO THIS:\n *\n * NOTOK:\n * if (!hcparty.hcPartyKeys && !hcparty.hcPartyKeys[hcpartyId] && hcparty.hcPartyKeys[hcpartyId].length !== 2) {\n * throw 'No hcPartyKey for this Healthcare party(' + hcpartyId + ').';\n * }\n * var delegateHcPartyKey = hcparty.hcPartyKeys[hcpartyId][1];\n *\n * SHOULD BE:\n * var delegatorId = patient.delegations[hcpartyId][0].owner;\n * if (!hcparty.hcPartyKeys && !hcparty.hcPartyKeys[delegatorId] && hcparty.hcPartyKeys[delegatorId].length !== 2) {\n * throw 'No hcPartyKey for this Healthcare party(' + delegatorId + ').';\n * }\n * var delegateHcPartyKey = hcparty.hcPartyKeys[delegatorId][1];\n */\n }\n this._debug && console.log(`decrypt ${ua2hex(encryptedData)} with ${rawKey}`)\n this.crypto.subtle.decrypt(aesAlgorithmEncrypt, cryptoKey, encryptedDataUint8.subarray(this.ivLength, encryptedDataUint8.length)).then(\n (decipheredData) => {\n this._debug && console.log(`decipheredData: ${ua2hex(decipheredData)}`)\n resolve(decipheredData)\n },\n (err) => {\n reject('AES decryption failed: ' + err)\n }\n )\n })\n }\n\n async decryptSome(cryptoKeys: CryptoKey[], uint8Array: Uint8Array): Promise<ArrayBuffer> {\n try {\n return this.decrypt(cryptoKeys[0], uint8Array)\n } catch (e) {\n if (cryptoKeys.length > 1) {\n return this.decryptSome(cryptoKeys.slice(1), uint8Array)\n } else {\n throw e\n }\n }\n }\n\n // generate an AES key\n // noinspection JSUnusedGlobalSymbols\n /**\n *\n * @param toHex boolean, if true, it returns hex String\n * @returns {Promise} either Hex string or CryptoKey\n */\n generateCryptoKey(toHex: false): Promise<CryptoKey>\n generateCryptoKey(toHex: true): Promise<string>\n generateCryptoKey(toHex: boolean): Promise<string | CryptoKey> {\n return new Promise((resolve: (value: CryptoKey | string) => any, reject: (reason: any) => any) => {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n const cryptoKeyPromise: Promise<CryptoKey> = this.crypto.subtle.generateKey(this.aesKeyGenParams, extractable, keyUsages) as Promise<CryptoKey>\n return toHex === undefined || !toHex\n ? cryptoKeyPromise.then(resolve, reject)\n : cryptoKeyPromise.then((k) => this.exportKey(k, 'raw'), reject).then((raw) => resolve(ua2hex(raw)), reject)\n })\n }\n\n // noinspection JSMethodCanBeStatic\n generateIV(ivByteLength: number): Uint8Array {\n return new Uint8Array(this.crypto.getRandomValues(new Uint8Array(ivByteLength)))\n }\n\n /**\n * This function return a promise which will be the key Format will be either 'raw' or 'jwk'.\n * JWK: Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11)\n *\n * @param cryptoKey CryptoKey\n * @param format will be 'raw' or 'jwk'\n * @returns {Promise} will the AES Key\n */\n exportKey(cryptoKey: CryptoKey, format: 'raw'): Promise<ArrayBuffer>\n exportKey(cryptoKey: CryptoKey, format: 'jwk'): Promise<JsonWebKey>\n exportKey(cryptoKey: CryptoKey, format: 'jwk' | 'raw'): Promise<ArrayBuffer | JsonWebKey> {\n return new Promise((resolve: (value: ArrayBuffer | JsonWebKey) => any, reject: (reason: any) => any) => {\n return this.crypto.subtle.exportKey(format as any, cryptoKey).then(resolve, reject)\n })\n }\n\n /**\n * the ability to import a key that have already been created elsewhere, for use within the web\n * application that is invoking the import function, for use within the importing web application's\n * origin. This necessiates an interoperable key format, such as JSON Web Key [JWK] which may be\n * represented as octets.\n *\n * https://chromium.googlesource.com/chromium/blink.git/+/6b902997e3ca0384c8fa6fe56f79ecd7589d3ca6/LayoutTests/crypto/resources/common.js\n *\n * @param format 'raw' or 'jwk'\n * @param aesKey\n * @returns {*}\n */\n importKey(format: 'jwk' | 'raw', aesKey: JsonWebKey | ArrayBuffer | Uint8Array): Promise<CryptoKey> {\n return new Promise((resolve: (value: CryptoKey) => any, reject: (reason: any) => any) => {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n return this.crypto.subtle.importKey(format as any, aesKey as any, this.aesKeyGenParams, extractable, keyUsages).then(resolve, reject)\n })\n }\n}\n\nexport const AES = new AESUtils()\n"]}
|
|
@@ -2,8 +2,6 @@ export declare class RSAUtils {
|
|
|
2
2
|
/********* RSA Config **********/
|
|
3
3
|
rsaParams: any;
|
|
4
4
|
rsaHashedParams: any;
|
|
5
|
-
rsaLocalStoreIdPrefix: string;
|
|
6
|
-
rsaKeyPairs: any;
|
|
7
5
|
private crypto;
|
|
8
6
|
constructor(crypto?: Crypto);
|
|
9
7
|
/**
|
|
@@ -91,34 +89,5 @@ export declare class RSAUtils {
|
|
|
91
89
|
publicKey: CryptoKey;
|
|
92
90
|
privateKey: CryptoKey;
|
|
93
91
|
}>;
|
|
94
|
-
/**
|
|
95
|
-
*
|
|
96
|
-
* @param id
|
|
97
|
-
* @param keyPair should be JWK
|
|
98
|
-
*/
|
|
99
|
-
storeKeyPair(id: string, keyPair: {
|
|
100
|
-
publicKey: any;
|
|
101
|
-
privateKey: any;
|
|
102
|
-
}): void;
|
|
103
|
-
/**
|
|
104
|
-
* loads the RSA key pair (hcparty) in JWK, not imported
|
|
105
|
-
*
|
|
106
|
-
* @param id doc id - hcpartyId
|
|
107
|
-
* @returns {Object} it is in JWK - not imported
|
|
108
|
-
*/
|
|
109
|
-
loadKeyPairNotImported(id: string): {
|
|
110
|
-
publicKey: any;
|
|
111
|
-
privateKey: any;
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* Loads and imports the RSA key pair (hcparty)
|
|
115
|
-
*
|
|
116
|
-
* @param id doc id - hcPartyId
|
|
117
|
-
* @returns {Promise} -> {CryptoKey} - imported RSA
|
|
118
|
-
*/
|
|
119
|
-
loadKeyPairImported(id: string): Promise<{
|
|
120
|
-
publicKey: CryptoKey;
|
|
121
|
-
privateKey: CryptoKey;
|
|
122
|
-
}>;
|
|
123
92
|
}
|
|
124
93
|
export declare const RSA: RSAUtils;
|
package/icc-x-api/crypto/RSA.js
CHANGED
|
@@ -14,8 +14,6 @@ class RSAUtils {
|
|
|
14
14
|
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
|
15
15
|
hash: { name: 'sha-1' },
|
|
16
16
|
};
|
|
17
|
-
this.rsaLocalStoreIdPrefix = 'org.taktik.icure.rsa.';
|
|
18
|
-
this.rsaKeyPairs = {};
|
|
19
17
|
this.crypto = crypto;
|
|
20
18
|
}
|
|
21
19
|
/**
|
|
@@ -110,68 +108,6 @@ class RSAUtils {
|
|
|
110
108
|
};
|
|
111
109
|
});
|
|
112
110
|
}
|
|
113
|
-
/**
|
|
114
|
-
*
|
|
115
|
-
* @param id
|
|
116
|
-
* @param keyPair should be JWK
|
|
117
|
-
*/
|
|
118
|
-
storeKeyPair(id, keyPair) {
|
|
119
|
-
if (typeof Storage === 'undefined') {
|
|
120
|
-
console.log('Your browser does not support HTML5 Browser Local Storage !');
|
|
121
|
-
throw 'Your browser does not support HTML5 Browser Local Storage !';
|
|
122
|
-
}
|
|
123
|
-
//TODO encryption
|
|
124
|
-
localStorage.setItem(this.rsaLocalStoreIdPrefix + id, JSON.stringify(keyPair));
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* loads the RSA key pair (hcparty) in JWK, not imported
|
|
128
|
-
*
|
|
129
|
-
* @param id doc id - hcpartyId
|
|
130
|
-
* @returns {Object} it is in JWK - not imported
|
|
131
|
-
*/
|
|
132
|
-
loadKeyPairNotImported(id) {
|
|
133
|
-
if (typeof Storage === 'undefined') {
|
|
134
|
-
console.log('Your browser does not support HTML5 Browser Local Storage !');
|
|
135
|
-
throw 'Your browser does not support HTML5 Browser Local Storage !';
|
|
136
|
-
}
|
|
137
|
-
//TODO decryption
|
|
138
|
-
return JSON.parse(localStorage.getItem(this.rsaLocalStoreIdPrefix + id) || '{}');
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Loads and imports the RSA key pair (hcparty)
|
|
142
|
-
*
|
|
143
|
-
* @param id doc id - hcPartyId
|
|
144
|
-
* @returns {Promise} -> {CryptoKey} - imported RSA
|
|
145
|
-
*/
|
|
146
|
-
loadKeyPairImported(id) {
|
|
147
|
-
return new Promise((resolve, reject) => {
|
|
148
|
-
try {
|
|
149
|
-
const jwkKey = localStorage.getItem(this.rsaLocalStoreIdPrefix + id);
|
|
150
|
-
if (jwkKey) {
|
|
151
|
-
const jwkKeyPair = JSON.parse(jwkKey);
|
|
152
|
-
if (jwkKeyPair.publicKey && jwkKeyPair.privateKey) {
|
|
153
|
-
this.importKeyPair('jwk', jwkKeyPair.privateKey, 'jwk', jwkKeyPair.publicKey).then(resolve, (err) => {
|
|
154
|
-
console.log('Error in RSA.importKeyPair: ' + err);
|
|
155
|
-
reject(err);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
const message = 'Error in RSA.importKeyPair: Invalid key';
|
|
160
|
-
console.log(message);
|
|
161
|
-
reject(Error(message));
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
const message = 'Error in RSA.importKeyPair: Missing key';
|
|
166
|
-
console.log(message);
|
|
167
|
-
reject(Error(message));
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
catch (err) {
|
|
171
|
-
reject(err);
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
111
|
}
|
|
176
112
|
exports.RSAUtils = RSAUtils;
|
|
177
113
|
exports.RSA = new RSAUtils();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RSA.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/RSA.ts"],"names":[],"mappings":";;;AAAA,MAAa,QAAQ;IAgBnB,YAAY,SAAiB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,EAAa;QAfvI,iCAAiC;QACjC,qBAAqB;QACrB,sBAAsB;QACtB,cA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,GAAG,GAAG,CAAC,CAAA;4BACjD,MAAM,CAAC,GAAG,CAAC,CAAA;wBACb,CAAC,CAAC,CAAA;qBACH;yBAAM;wBACL,MAAM,OAAO,GAAG,yCAAyC,CAAA;wBACzD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;wBACpB,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAA;qBACvB;iBACF;qBAAM;oBACL,MAAM,OAAO,GAAG,yCAAyC,CAAA;oBACzD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;oBACpB,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAA;iBACvB;aACF;YAAC,OAAO,GAAG,EAAE;gBACZ,MAAM,CAAC,GAAG,CAAC,CAAA;aACZ;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AApOD,4BAoOC;AAEY,QAAA,GAAG,GAAG,IAAI,QAAQ,EAAE,CAAA","sourcesContent":["export class RSAUtils {\n /********* RSA Config **********/\n //TODO bigger modulus\n //TODO PSS for signing\n rsaParams: any = { name: 'RSA-OAEP' }\n // RSA params for 'import' and 'generate' function.\n rsaHashedParams: any = {\n name: 'RSA-OAEP',\n modulusLength: 2048,\n publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537 (Fermat F4), read http://en.wikipedia.org/wiki/65537_(number)\n hash: { name: 'sha-1' },\n }\n rsaLocalStoreIdPrefix = 'org.taktik.icure.rsa.'\n rsaKeyPairs: any = {}\n private crypto: Crypto\n\n constructor(crypto: Crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : ({} as Crypto)) {\n this.crypto = crypto\n }\n\n /**\n * It returns CryptoKey promise, which doesn't hold the bytes of the key.\n * If bytes are needed, you must export the generated key.\n * R\n * @returns {Promise} will be {publicKey: CryptoKey, privateKey: CryptoKey}\n */\n generateKeyPair(): Promise<CryptoKeyPair> {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n\n return new Promise((resolve: (value: CryptoKeyPair) => any, reject) => {\n this.crypto.subtle.generateKey(this.rsaHashedParams, extractable, keyUsages).then(resolve, reject)\n })\n }\n\n /**\n *\n * 'JWK': Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11)\n * 'spki': for private key\n * 'pkcs8': for private Key\n *\n * @param keyPair is {publicKey: CryptoKey, privateKey: CryptoKey}\n * @param privKeyFormat will be 'pkcs8' or 'jwk'\n * @param pubKeyFormat will be 'spki' or 'jwk'\n * @returns {Promise} will the AES Key\n */\n exportKeys(\n keyPair: { publicKey: CryptoKey; privateKey: CryptoKey },\n privKeyFormat: 'jwk',\n pubKeyFormat: 'jwk'\n ): Promise<{ publicKey: JsonWebKey; privateKey: JsonWebKey }>\n exportKeys(\n keyPair: { publicKey: CryptoKey; privateKey: CryptoKey },\n privKeyFormat: 'pkcs8',\n pubKeyFormat: 'spki'\n ): Promise<{ publicKey: ArrayBuffer; privateKey: ArrayBuffer }>\n exportKeys(\n keyPair: { publicKey: CryptoKey; privateKey: CryptoKey },\n privKeyFormat: string,\n pubKeyFormat: string\n ): Promise<{ publicKey: JsonWebKey | ArrayBuffer; privateKey: JsonWebKey | ArrayBuffer }> {\n const pubPromise = this.crypto.subtle.exportKey(pubKeyFormat, keyPair.publicKey)\n const privPromise = this.crypto.subtle.exportKey(privKeyFormat, keyPair.privateKey)\n\n return Promise.all([pubPromise, privPromise]).then(function (results) {\n return {\n publicKey: results[0],\n privateKey: results[1],\n }\n })\n }\n\n /**\n * Format:\n *\n * 'JWK': Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11)\n * 'spki': for private key\n * 'pkcs8': for private Key\n *\n * @param cryptoKey public or private\n * @param format either 'jwk' or 'spki' or 'pkcs8'\n * @returns {Promise|*} will be RSA key (public or private)\n */\n exportKey(cryptoKey: CryptoKey, format: 'jwk'): Promise<JsonWebKey>\n exportKey(cryptoKey: CryptoKey, format: 'spki'): Promise<ArrayBuffer>\n exportKey(cryptoKey: CryptoKey, format: 'pkcs8'): Promise<ArrayBuffer>\n exportKey(cryptoKey: CryptoKey, format: string): Promise<JsonWebKey | ArrayBuffer> {\n return new Promise((resolve: (value: JsonWebKey | ArrayBuffer) => any, reject) => {\n this.crypto.subtle.exportKey(format, cryptoKey).then(resolve, reject)\n })\n }\n\n /**\n *\n * @param publicKey (CryptoKey)\n * @param plainData (Uint8Array)\n */\n encrypt(publicKey: CryptoKey, plainData: Uint8Array) {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject) => {\n this.crypto.subtle.encrypt(this.rsaParams, publicKey, plainData.buffer ? plainData.buffer : plainData).then(resolve, reject) //Node prefers arrayBuffer\n })\n }\n\n /**\n *\n * @param privateKey (CryptoKey)\n * @param encryptedData (Uint8Array)\n */\n decrypt(privateKey: CryptoKey, encryptedData: Uint8Array): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject) => {\n this.crypto.subtle.decrypt(this.rsaParams, privateKey, encryptedData).then(resolve, reject)\n })\n }\n\n /**\n *\n * @param format 'jwk', 'spki', or 'pkcs8'\n * @param keydata should be the key data based on the format.\n * @param keyUsages Array of usages. For example, ['encrypt'] for public key.\n * @returns {*}\n */\n importKey(format: string, keydata: JsonWebKey | ArrayBuffer, keyUsages: KeyUsage[]) {\n const extractable = true\n return new Promise((resolve: (value: CryptoKey) => any, reject) => {\n this.crypto.subtle.importKey(format, keydata, this.rsaHashedParams, extractable, keyUsages).then(resolve, reject)\n })\n }\n\n /**\n *\n * @param format 'jwk' or 'pkcs8'\n * @param keydata should be the key data based on the format.\n * @returns {*}\n */\n importPrivateKey(format: string, keydata: JsonWebKey | ArrayBuffer) {\n const extractable = true\n return new Promise((resolve: (value: CryptoKey) => any, reject) => {\n this.crypto.subtle.importKey(format, keydata, this.rsaHashedParams, extractable, ['decrypt']).then(resolve, reject)\n })\n }\n\n /**\n *\n * @param privateKeyFormat 'jwk' or 'pkcs8'\n * @param privateKeydata should be the key data based on the format.\n * @param publicKeyFormat 'jwk' or 'spki'\n * @param publicKeyData should be the key data based on the format.\n * @returns {Promise|*}\n */\n importKeyPair(\n privateKeyFormat: string,\n privateKeydata: JsonWebKey | ArrayBuffer,\n publicKeyFormat: string,\n publicKeyData: JsonWebKey | ArrayBuffer\n ) {\n const extractable = true\n const privPromise = this.crypto.subtle.importKey(privateKeyFormat, privateKeydata, this.rsaHashedParams, extractable, ['decrypt'])\n const pubPromise = this.crypto.subtle.importKey(publicKeyFormat, publicKeyData, this.rsaHashedParams, extractable, ['encrypt'])\n\n return Promise.all([pubPromise, privPromise]).then(function (results) {\n return {\n publicKey: results[0],\n privateKey: results[1],\n }\n })\n }\n\n /**\n *\n * @param id\n * @param keyPair should be JWK\n */\n storeKeyPair(id: string, keyPair: { publicKey: any; privateKey: any }) {\n if (typeof Storage === 'undefined') {\n console.log('Your browser does not support HTML5 Browser Local Storage !')\n throw 'Your browser does not support HTML5 Browser Local Storage !'\n }\n //TODO encryption\n localStorage.setItem(this.rsaLocalStoreIdPrefix + id, JSON.stringify(keyPair))\n }\n\n /**\n * loads the RSA key pair (hcparty) in JWK, not imported\n *\n * @param id doc id - hcpartyId\n * @returns {Object} it is in JWK - not imported\n */\n loadKeyPairNotImported(id: string): { publicKey: any; privateKey: any } {\n if (typeof Storage === 'undefined') {\n console.log('Your browser does not support HTML5 Browser Local Storage !')\n throw 'Your browser does not support HTML5 Browser Local Storage !'\n }\n //TODO decryption\n return JSON.parse((localStorage.getItem(this.rsaLocalStoreIdPrefix + id) as string) || '{}')\n }\n\n /**\n * Loads and imports the RSA key pair (hcparty)\n *\n * @param id doc id - hcPartyId\n * @returns {Promise} -> {CryptoKey} - imported RSA\n */\n loadKeyPairImported(id: string) {\n return new Promise((resolve: (value: { publicKey: CryptoKey; privateKey: CryptoKey }) => any, reject) => {\n try {\n const jwkKey = localStorage.getItem(this.rsaLocalStoreIdPrefix + id) as string\n if (jwkKey) {\n const jwkKeyPair = JSON.parse(jwkKey)\n if (jwkKeyPair.publicKey && jwkKeyPair.privateKey) {\n this.importKeyPair('jwk', jwkKeyPair.privateKey, 'jwk', jwkKeyPair.publicKey).then(resolve, (err) => {\n console.log('Error in RSA.importKeyPair: ' + err)\n reject(err)\n })\n } else {\n const message = 'Error in RSA.importKeyPair: Invalid key'\n console.log(message)\n reject(Error(message))\n }\n } else {\n const message = 'Error in RSA.importKeyPair: Missing key'\n console.log(message)\n reject(Error(message))\n }\n } catch (err) {\n reject(err)\n }\n })\n }\n}\n\nexport const RSA = new RSAUtils()\n"]}
|
|
1
|
+
{"version":3,"file":"RSA.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/RSA.ts"],"names":[],"mappings":";;;AAEA,MAAa,QAAQ;IAenB,YAAY,SAAiB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,EAAa;QAdvI,iCAAiC;QACjC,qBAAqB;QACrB,sBAAsB;QACtB,cAAS,GAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,CAAA;QACrC,mDAAmD;QACnD,oBAAe,GAAQ;YACrB,IAAI,EAAE,UAAU;YAChB,aAAa,EAAE,IAAI;YACnB,cAAc,EAAE,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YAClD,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;SACxB,CAAA;QAKC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED;;;;;OAKG;IACH,eAAe;QACb,MAAM,WAAW,GAAG,IAAI,CAAA;QACxB,MAAM,SAAS,GAAe,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QAEpD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAsC,EAAE,MAAM,EAAE,EAAE;YACpE,IAAI,CAAC,MAAM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AAwB,EACxB,cAAwC,EACxC,eAAuB,EACvB,aAAuC;QAEvC,MAAM,WAAW,GAAG,IAAI,CAAA;QACxB,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,gBAAuB,EAAE,cAAqB,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;QAChJ,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,eAAsB,EAAE,aAAoB,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;QAE7I,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,OAAO;YAClE,OAAO;gBACL,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;gBACrB,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;aACvB,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AArKD,4BAqKC;AAEY,QAAA,GAAG,GAAG,IAAI,QAAQ,EAAE,CAAA","sourcesContent":["import { RsaPrivateKey } from 'crypto'\n\nexport class RSAUtils {\n /********* RSA Config **********/\n //TODO bigger modulus\n //TODO PSS for signing\n rsaParams: any = { name: 'RSA-OAEP' }\n // RSA params for 'import' and 'generate' function.\n rsaHashedParams: any = {\n name: 'RSA-OAEP',\n modulusLength: 2048,\n publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537 (Fermat F4), read http://en.wikipedia.org/wiki/65537_(number)\n hash: { name: 'sha-1' },\n }\n\n private crypto: Crypto\n\n constructor(crypto: Crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : ({} as Crypto)) {\n this.crypto = crypto\n }\n\n /**\n * It returns CryptoKey promise, which doesn't hold the bytes of the key.\n * If bytes are needed, you must export the generated key.\n * R\n * @returns {Promise} will be {publicKey: CryptoKey, privateKey: CryptoKey}\n */\n generateKeyPair(): Promise<CryptoKeyPair> {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n\n return new Promise((resolve: (value: CryptoKeyPair) => any, reject) => {\n this.crypto.subtle.generateKey(this.rsaHashedParams, extractable, keyUsages).then(resolve, reject)\n })\n }\n\n /**\n *\n * 'JWK': Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11)\n * 'spki': for private key\n * 'pkcs8': for private Key\n *\n * @param keyPair is {publicKey: CryptoKey, privateKey: CryptoKey}\n * @param privKeyFormat will be 'pkcs8' or 'jwk'\n * @param pubKeyFormat will be 'spki' or 'jwk'\n * @returns {Promise} will the AES Key\n */\n exportKeys(\n keyPair: { publicKey: CryptoKey; privateKey: CryptoKey },\n privKeyFormat: 'jwk',\n pubKeyFormat: 'jwk'\n ): Promise<{ publicKey: JsonWebKey; privateKey: JsonWebKey }>\n exportKeys(\n keyPair: { publicKey: CryptoKey; privateKey: CryptoKey },\n privKeyFormat: 'pkcs8',\n pubKeyFormat: 'spki'\n ): Promise<{ publicKey: ArrayBuffer; privateKey: ArrayBuffer }>\n exportKeys(\n keyPair: { publicKey: CryptoKey; privateKey: CryptoKey },\n privKeyFormat: string,\n pubKeyFormat: string\n ): Promise<{ publicKey: JsonWebKey | ArrayBuffer; privateKey: JsonWebKey | ArrayBuffer }> {\n const pubPromise = this.crypto.subtle.exportKey(pubKeyFormat as any, keyPair.publicKey)\n const privPromise = this.crypto.subtle.exportKey(privKeyFormat as any, keyPair.privateKey)\n\n return Promise.all([pubPromise, privPromise]).then(function (results) {\n return {\n publicKey: results[0],\n privateKey: results[1],\n }\n })\n }\n\n /**\n * Format:\n *\n * 'JWK': Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11)\n * 'spki': for private key\n * 'pkcs8': for private Key\n *\n * @param cryptoKey public or private\n * @param format either 'jwk' or 'spki' or 'pkcs8'\n * @returns {Promise|*} will be RSA key (public or private)\n */\n exportKey(cryptoKey: CryptoKey, format: 'jwk'): Promise<JsonWebKey>\n exportKey(cryptoKey: CryptoKey, format: 'spki'): Promise<ArrayBuffer>\n exportKey(cryptoKey: CryptoKey, format: 'pkcs8'): Promise<ArrayBuffer>\n exportKey(cryptoKey: CryptoKey, format: string): Promise<JsonWebKey | ArrayBuffer> {\n return new Promise((resolve: (value: JsonWebKey | ArrayBuffer) => any, reject) => {\n this.crypto.subtle.exportKey(format as any, cryptoKey).then(resolve, reject)\n })\n }\n\n /**\n *\n * @param publicKey (CryptoKey)\n * @param plainData (Uint8Array)\n */\n encrypt(publicKey: CryptoKey, plainData: Uint8Array) {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject) => {\n this.crypto.subtle.encrypt(this.rsaParams, publicKey, plainData.buffer ? plainData.buffer : plainData).then(resolve, reject) //Node prefers arrayBuffer\n })\n }\n\n /**\n *\n * @param privateKey (CryptoKey)\n * @param encryptedData (Uint8Array)\n */\n decrypt(privateKey: CryptoKey, encryptedData: Uint8Array): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject) => {\n this.crypto.subtle.decrypt(this.rsaParams, privateKey, encryptedData).then(resolve, reject)\n })\n }\n\n /**\n *\n * @param format 'jwk', 'spki', or 'pkcs8'\n * @param keydata should be the key data based on the format.\n * @param keyUsages Array of usages. For example, ['encrypt'] for public key.\n * @returns {*}\n */\n importKey(format: string, keydata: JsonWebKey | ArrayBuffer, keyUsages: KeyUsage[]) {\n const extractable = true\n return new Promise((resolve: (value: CryptoKey) => any, reject) => {\n this.crypto.subtle.importKey(format as any, keydata as any, this.rsaHashedParams, extractable, keyUsages).then(resolve, reject)\n })\n }\n\n /**\n *\n * @param format 'jwk' or 'pkcs8'\n * @param keydata should be the key data based on the format.\n * @returns {*}\n */\n importPrivateKey(format: string, keydata: JsonWebKey | ArrayBuffer) {\n const extractable = true\n return new Promise((resolve: (value: CryptoKey) => any, reject) => {\n this.crypto.subtle.importKey(format as any, keydata as any, this.rsaHashedParams, extractable, ['decrypt']).then(resolve, reject)\n })\n }\n\n /**\n *\n * @param privateKeyFormat 'jwk' or 'pkcs8'\n * @param privateKeydata should be the key data based on the format.\n * @param publicKeyFormat 'jwk' or 'spki'\n * @param publicKeyData should be the key data based on the format.\n * @returns {Promise|*}\n */\n importKeyPair(\n privateKeyFormat: string,\n privateKeydata: JsonWebKey | ArrayBuffer,\n publicKeyFormat: string,\n publicKeyData: JsonWebKey | ArrayBuffer\n ) {\n const extractable = true\n const privPromise = this.crypto.subtle.importKey(privateKeyFormat as any, privateKeydata as any, this.rsaHashedParams, extractable, ['decrypt'])\n const pubPromise = this.crypto.subtle.importKey(publicKeyFormat as any, publicKeyData as any, this.rsaHashedParams, extractable, ['encrypt'])\n\n return Promise.all([pubPromise, privPromise]).then(function (results) {\n return {\n publicKey: results[0],\n privateKey: results[1],\n }\n })\n }\n}\n\nexport const RSA = new RSAUtils()\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shamir.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/shamir.ts"],"names":[],"mappings":";;;AAEA,MAAa,WAAW;IAsBtB,YAAY,SAAiB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,EAAa;QArBvI,4BAA4B;QAC5B,WAAM,GAAG;YACP,IAAI,EAAE,CAAC;YACP,KAAK,EAAE,EAAE;YACT,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,iBAAiB,CAAC;YACtC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC;YACzC,OAAO,EAAE,CAAC;YACV,OAAO,EAAE,EAAE;YACX,YAAY,EAA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CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA,CAAC,mIAAmI;SACjM;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF;AAnUD,kCAmUC;AAEY,QAAA,MAAM,GAAG,IAAI,WAAW,EAAE,CAAA","sourcesContent":["import { utils } from './utils'\n\nexport class ShamirClass {\n // Protected settings object\n config = {\n bits: 8, // default number of bits\n radix: 16, // work with HEX by default\n size: Math.pow(2, 8 /* config.bits */),\n max: Math.pow(2, 8 /* config.bits */) - 1,\n minBits: 3,\n maxBits: 16, // this permits 65,535 shares, though going this high is NOT recommended in JS!\n bytesPerChar: 2,\n maxBytesPerChar: 6, // Math.pow(256,7) > Math.pow(2,53)\n // Primitive polynomials (in decimal form) for Galois Fields GF(2^n), for 2 <= n <= 30\n // The index of each term in the array corresponds to the n for that polynomial\n // i.e. to get the polynomial for n=16, use primitivePolynomials[16]\n primitivePolynomials: [null, null, 1, 3, 3, 5, 3, 3, 29, 17, 9, 5, 83, 27, 43, 3, 45, 9, 39, 39, 9, 5, 3, 33, 27, 9, 71, 39, 9, 5, 83],\n // warning for insecure PRNG\n warning: 'WARNING:\\nA secure random number generator was not found.\\nUsing Math.random(), which is NOT cryptographically strong!',\n logs: [] as Array<number>,\n exps: [] as Array<number>,\n }\n private crypto: Crypto\n\n constructor(crypto: Crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : ({} as Crypto)) {\n this.crypto = crypto\n }\n\n init() {\n const primitive = this.config.primitivePolynomials[this.config.bits]!\n let x = 1\n\n for (let i = 0; i < this.config.size; i++) {\n this.config.exps[i] = x\n this.config.logs[x] = i\n x <<= 1\n if (x >= this.config.size) {\n x ^= primitive\n x &= this.config.max\n }\n }\n }\n\n // Splits a number string `bits`-length segments, after first\n // optionally zero-padding it to a length that is a multiple of `padLength.\n // Returns array of integers (each less than 2^bits-1), with each element\n // representing a `bits`-length segment of the input string from right to left,\n // i.e. parts[0] represents the right-most `bits`-length segment of the input string.\n split(str: string, padLength = 0) {\n if (padLength) {\n str = this.padLeft(str, padLength)\n }\n const parts = []\n for (var i = str.length; i > this.config.bits; i -= this.config.bits) {\n parts.push(parseInt(str.slice(i - this.config.bits, i), 2))\n }\n parts.push(parseInt(str.slice(0, i), 2))\n return parts\n }\n\n bin2hex(str: string) {\n let hex = '',\n num\n str = this.padLeft(str, 4)\n for (let i = str.length; i >= 4; i -= 4) {\n num = parseInt(str.slice(i - 4, i), 2)\n if (isNaN(num)) {\n throw new Error('Invalid binary character.')\n }\n hex = num.toString(16) + hex\n }\n return hex\n }\n\n hex2bin(str: string) {\n let bin = '',\n num\n for (let i = str.length - 1; i >= 0; i--) {\n num = parseInt(str[i], 16)\n if (isNaN(num)) {\n throw new Error('Invalid hex character.')\n }\n bin = this.padLeft(num.toString(2), 4) + bin\n }\n\n return bin\n }\n\n padLeft(str: string, bits: number = this.config.bits) {\n const missing = str.length % bits\n return (missing ? new Array(bits - missing + 1).join('0') : '') + str\n }\n\n random(bits: number) {\n const construct = (bits: number, arr: Uint32Array, size: number) => {\n let str = '',\n i = 0\n const len = arr.length - 1\n while (i < len || str.length < bits) {\n str += this.padLeft(arr[i].toString(16), size)\n i++\n }\n str = str.substr(-bits / 4)\n return (str.match(/0/g) || []).length === str.length ? null : str\n }\n\n let elems = Math.ceil(bits / 32),\n str = null,\n arr = new Uint32Array(elems)\n\n while (str === null) {\n crypto.getRandomValues(arr)\n str = construct(bits, arr, 8)\n }\n\n return str\n }\n\n share(secretString: string, numShares: number, threshold: number) {\n if (!this.config.logs.length) {\n this.init()\n }\n\n if (numShares % 1 !== 0 || numShares < 2) {\n throw new Error('Number of shares must be an integer between 2 and 2^bits-1 (' + this.config.max + '), inclusive.')\n }\n if (numShares > this.config.max) {\n var neededBits = Math.ceil(Math.log(numShares + 1) / Math.LN2)\n throw new Error(\n 'Number of shares must be an integer between 2 and 2^bits-1 (' +\n this.config.max +\n '), inclusive. To create ' +\n numShares +\n ' shares, use at least ' +\n neededBits +\n ' bits.'\n )\n }\n if (threshold % 1 !== 0 || threshold < 2) {\n throw new Error('Threshold number of shares must be an integer between 2 and 2^bits-1 (' + this.config.max + '), inclusive.')\n }\n if (threshold > this.config.max) {\n var neededBits = Math.ceil(Math.log(threshold + 1) / Math.LN2)\n throw new Error(\n 'Threshold number of shares must be an integer between 2 and 2^bits-1 (' +\n this.config.max +\n '), inclusive. To use a threshold of ' +\n threshold +\n ', use at least ' +\n neededBits +\n ' bits.'\n )\n }\n\n // append a 1 so that we can preserve the correct number of leading zeros in our secret\n const secret = this.split('1' + this.hex2bin(secretString), 0)\n const x = new Array(numShares),\n y = new Array(numShares)\n for (let i = 0, len = secret.length; i < len; i++) {\n const subShares = this._getShares(secret[i], numShares, threshold)\n for (let j = 0; j < numShares; j++) {\n x[j] = x[j] || subShares[j].x.toString(this.config.radix)\n y[j] = this.padLeft(subShares[j].y.toString(2)) + (y[j] ? y[j] : '')\n }\n }\n const padding = this.config.max.toString(this.config.radix).length\n return y.map((b, idx) => this.config.bits.toString(16).toUpperCase() + this.padLeft(x[idx], padding) + this.bin2hex(b))\n }\n\n // This is the basic polynomial generation and evaluation function\n // for a `config.bits`-length secret (NOT an arbitrary length)\n // Note: no error-checking at this stage! If `secrets` is NOT\n // a NUMBER less than 2^bits-1, the output will be incorrect!\n _getShares(secret: number, numShares: number, threshold: number) {\n const shares = []\n const coeffs = [secret]\n\n for (var i = 1; i < threshold; i++) {\n coeffs[i] = parseInt(this.random(this.config.bits), 16)\n }\n for (var i = 1, len = numShares + 1; i < len; i++) {\n shares[i - 1] = {\n x: i,\n y: this.horner(i, coeffs),\n }\n }\n return shares\n }\n\n // Polynomial evaluation at `x` using Horner's Method\n // TODO: this can possibly be sped up using other methods\n // NOTE: fx=fx * x + coeff[i] -> exp(log(fx) + log(x)) + coeff[i],\n // so if fx===0, just set fx to coeff[i] because\n // using the exp/log form will result in incorrect value\n horner(x: number, coeffs: Array<number>) {\n const logx = this.config.logs[x]\n let fx = 0\n for (let i = coeffs.length - 1; i >= 0; i--) {\n if (fx === 0) {\n fx = coeffs[i]\n continue\n }\n fx = this.config.exps[(logx + this.config.logs[fx]) % this.config.max] ^ coeffs[i]\n }\n return fx\n }\n\n processShare(share: string) {\n const bits = parseInt(share[0], 16)\n if (bits && (bits % 1 !== 0 || bits < this.config.minBits || bits > this.config.maxBits)) {\n throw new Error('Number of bits must be an integer between ' + this.config.minBits + ' and ' + this.config.maxBits + ', inclusive.')\n }\n\n const max = Math.pow(2, bits) - 1\n const idLength = max.toString(this.config.radix).length\n\n const id = parseInt(share.substr(1, idLength), this.config.radix)\n if (id % 1 !== 0 || id < 1 || id > max) {\n throw new Error('Share id must be an integer between 1 and ' + this.config.max + ', inclusive.')\n }\n share = share.substr(idLength + 1)\n if (!share.length) {\n throw new Error('Invalid share: zero-length share.')\n }\n return {\n bits: bits,\n id: id,\n value: share,\n }\n }\n\n _combine(at: number, shares: Array<string>) {\n if (!this.config.logs.length) {\n this.init()\n }\n\n const x: Array<number> = []\n const y: Array<Array<number>> = []\n let result = ''\n let idx: number\n\n for (var i = 0, len = shares.length; i < len; i++) {\n const share = this.processShare(shares[i])\n\n if (x.includes(share['id'])) {\n // repeated x value?\n continue\n }\n\n idx = x.push(share['id']) - 1\n const shareValues = this.split(this.hex2bin(share['value']))\n for (let j = 0, len2 = shareValues.length; j < len2; j++) {\n y[j] = y[j] || []\n y[j][idx] = shareValues[j]\n }\n }\n\n for (var i = 0, len = y.length; i < len; i++) {\n result = this.padLeft(this.lagrange(at, x, y[i]).toString(2)) + result\n }\n\n if (at === 0) {\n // reconstructing the secret\n return this.bin2hex(result.slice(result.indexOf('1') + 1))\n } else {\n // generating a new share\n return this.bin2hex(result)\n }\n }\n\n combine(shares: Array<string>) {\n return this._combine(0, shares)\n }\n\n // Generate a new share with id `id` (a number between 1 and 2^bits-1)\n // `id` can be a Number or a String in the default radix (16)\n newShare(id: number | string, shares: Array<string>) {\n if (typeof id === 'string') {\n id = parseInt(id, this.config.radix)\n }\n\n const share = this.processShare(shares[0])\n const max = Math.pow(2, share['bits']) - 1\n\n if (id % 1 !== 0 || id < 1 || id > max) {\n throw new Error('Share id must be an integer between 1 and ' + this.config.max + ', inclusive.')\n }\n\n const padding = max.toString(this.config.radix).length\n return this.config.bits.toString(16).toUpperCase() + this.padLeft(id.toString(this.config.radix), padding) + this._combine(id, shares)\n }\n\n // Evaluate the Lagrange interpolation polynomial at x = `at`\n // using x and y Arrays that are of the same length, with\n // corresponding elements constituting points on the polynomial.\n lagrange(at: number, x: Array<number>, y: Array<number>) {\n let sum = 0,\n product,\n i,\n j,\n len\n for (i = 0, len = x.length; i < len; i++) {\n if (!y[i]) {\n continue\n }\n\n product = this.config.logs[y[i]]\n for (j = 0; j < len; j++) {\n if (i === j) {\n continue\n }\n if (at === x[j]) {\n // happens when computing a share that is in the list of shares used to compute it\n product = -1 // fix for a zero product term, after which the sum should be sum^0 = sum, not sum^1\n break\n }\n product =\n (product + this.config.logs[at ^ x[j]] - this.config.logs[x[i] ^ x[j]] + this.config.max) /* to make sure it's not negative */ %\n this.config.max\n }\n\n sum = product === -1 ? sum : sum ^ this.config.exps[product] // though exps[-1]= undefined and undefined ^ anything = anything in chrome, this behavior may not hold everywhere, so do the check\n }\n return sum\n }\n}\n\nexport const shamir = new ShamirClass()\n"]}
|
|
1
|
+
{"version":3,"file":"shamir.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/shamir.ts"],"names":[],"mappings":";;;AAAA,MAAa,WAAW;IAsBtB,YAAY,SAAiB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,EAAa;QArBvI,4BAA4B;QAC5B,WAAM,GAAG;YACP,IAAI,EAAE,CAAC;YACP,KAAK,EAAE,EAAE;YACT,IAAI,EAAE,IAA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AAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,oCAAoC;wBAC9H,IAAI,CAAC,MAAM,CAAC,GAAG,CAAA;aAClB;YAED,GAAG,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA,CAAC,mIAAmI;SACjM;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF;AAnUD,kCAmUC;AAEY,QAAA,MAAM,GAAG,IAAI,WAAW,EAAE,CAAA","sourcesContent":["export class ShamirClass {\n // Protected settings object\n config = {\n bits: 8, // default number of bits\n radix: 16, // work with HEX by default\n size: Math.pow(2, 8 /* config.bits */),\n max: Math.pow(2, 8 /* config.bits */) - 1,\n minBits: 3,\n maxBits: 16, // this permits 65,535 shares, though going this high is NOT recommended in JS!\n bytesPerChar: 2,\n maxBytesPerChar: 6, // Math.pow(256,7) > Math.pow(2,53)\n // Primitive polynomials (in decimal form) for Galois Fields GF(2^n), for 2 <= n <= 30\n // The index of each term in the array corresponds to the n for that polynomial\n // i.e. to get the polynomial for n=16, use primitivePolynomials[16]\n primitivePolynomials: [null, null, 1, 3, 3, 5, 3, 3, 29, 17, 9, 5, 83, 27, 43, 3, 45, 9, 39, 39, 9, 5, 3, 33, 27, 9, 71, 39, 9, 5, 83],\n // warning for insecure PRNG\n warning: 'WARNING:\\nA secure random number generator was not found.\\nUsing Math.random(), which is NOT cryptographically strong!',\n logs: [] as Array<number>,\n exps: [] as Array<number>,\n }\n private crypto: Crypto\n\n constructor(crypto: Crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : ({} as Crypto)) {\n this.crypto = crypto\n }\n\n init() {\n const primitive = this.config.primitivePolynomials[this.config.bits]!\n let x = 1\n\n for (let i = 0; i < this.config.size; i++) {\n this.config.exps[i] = x\n this.config.logs[x] = i\n x <<= 1\n if (x >= this.config.size) {\n x ^= primitive\n x &= this.config.max\n }\n }\n }\n\n // Splits a number string `bits`-length segments, after first\n // optionally zero-padding it to a length that is a multiple of `padLength.\n // Returns array of integers (each less than 2^bits-1), with each element\n // representing a `bits`-length segment of the input string from right to left,\n // i.e. parts[0] represents the right-most `bits`-length segment of the input string.\n split(str: string, padLength = 0) {\n if (padLength) {\n str = this.padLeft(str, padLength)\n }\n const parts = []\n for (var i = str.length; i > this.config.bits; i -= this.config.bits) {\n parts.push(parseInt(str.slice(i - this.config.bits, i), 2))\n }\n parts.push(parseInt(str.slice(0, i), 2))\n return parts\n }\n\n bin2hex(str: string) {\n let hex = '',\n num\n str = this.padLeft(str, 4)\n for (let i = str.length; i >= 4; i -= 4) {\n num = parseInt(str.slice(i - 4, i), 2)\n if (isNaN(num)) {\n throw new Error('Invalid binary character.')\n }\n hex = num.toString(16) + hex\n }\n return hex\n }\n\n hex2bin(str: string) {\n let bin = '',\n num\n for (let i = str.length - 1; i >= 0; i--) {\n num = parseInt(str[i], 16)\n if (isNaN(num)) {\n throw new Error('Invalid hex character.')\n }\n bin = this.padLeft(num.toString(2), 4) + bin\n }\n\n return bin\n }\n\n padLeft(str: string, bits: number = this.config.bits) {\n const missing = str.length % bits\n return (missing ? new Array(bits - missing + 1).join('0') : '') + str\n }\n\n random(bits: number) {\n const construct = (bits: number, arr: Uint32Array, size: number) => {\n let str = '',\n i = 0\n const len = arr.length - 1\n while (i < len || str.length < bits) {\n str += this.padLeft(arr[i].toString(16), size)\n i++\n }\n str = str.substr(-bits / 4)\n return (str.match(/0/g) || []).length === str.length ? null : str\n }\n\n let elems = Math.ceil(bits / 32),\n str = null,\n arr = new Uint32Array(elems)\n\n while (str === null) {\n crypto.getRandomValues(arr)\n str = construct(bits, arr, 8)\n }\n\n return str\n }\n\n share(secretString: string, numShares: number, threshold: number) {\n if (!this.config.logs.length) {\n this.init()\n }\n\n if (numShares % 1 !== 0 || numShares < 2) {\n throw new Error('Number of shares must be an integer between 2 and 2^bits-1 (' + this.config.max + '), inclusive.')\n }\n if (numShares > this.config.max) {\n var neededBits = Math.ceil(Math.log(numShares + 1) / Math.LN2)\n throw new Error(\n 'Number of shares must be an integer between 2 and 2^bits-1 (' +\n this.config.max +\n '), inclusive. To create ' +\n numShares +\n ' shares, use at least ' +\n neededBits +\n ' bits.'\n )\n }\n if (threshold % 1 !== 0 || threshold < 2) {\n throw new Error('Threshold number of shares must be an integer between 2 and 2^bits-1 (' + this.config.max + '), inclusive.')\n }\n if (threshold > this.config.max) {\n var neededBits = Math.ceil(Math.log(threshold + 1) / Math.LN2)\n throw new Error(\n 'Threshold number of shares must be an integer between 2 and 2^bits-1 (' +\n this.config.max +\n '), inclusive. To use a threshold of ' +\n threshold +\n ', use at least ' +\n neededBits +\n ' bits.'\n )\n }\n\n // append a 1 so that we can preserve the correct number of leading zeros in our secret\n const secret = this.split('1' + this.hex2bin(secretString), 0)\n const x = new Array(numShares),\n y = new Array(numShares)\n for (let i = 0, len = secret.length; i < len; i++) {\n const subShares = this._getShares(secret[i], numShares, threshold)\n for (let j = 0; j < numShares; j++) {\n x[j] = x[j] || subShares[j].x.toString(this.config.radix)\n y[j] = this.padLeft(subShares[j].y.toString(2)) + (y[j] ? y[j] : '')\n }\n }\n const padding = this.config.max.toString(this.config.radix).length\n return y.map((b, idx) => this.config.bits.toString(16).toUpperCase() + this.padLeft(x[idx], padding) + this.bin2hex(b))\n }\n\n // This is the basic polynomial generation and evaluation function\n // for a `config.bits`-length secret (NOT an arbitrary length)\n // Note: no error-checking at this stage! If `secrets` is NOT\n // a NUMBER less than 2^bits-1, the output will be incorrect!\n _getShares(secret: number, numShares: number, threshold: number) {\n const shares = []\n const coeffs = [secret]\n\n for (var i = 1; i < threshold; i++) {\n coeffs[i] = parseInt(this.random(this.config.bits), 16)\n }\n for (var i = 1, len = numShares + 1; i < len; i++) {\n shares[i - 1] = {\n x: i,\n y: this.horner(i, coeffs),\n }\n }\n return shares\n }\n\n // Polynomial evaluation at `x` using Horner's Method\n // TODO: this can possibly be sped up using other methods\n // NOTE: fx=fx * x + coeff[i] -> exp(log(fx) + log(x)) + coeff[i],\n // so if fx===0, just set fx to coeff[i] because\n // using the exp/log form will result in incorrect value\n horner(x: number, coeffs: Array<number>) {\n const logx = this.config.logs[x]\n let fx = 0\n for (let i = coeffs.length - 1; i >= 0; i--) {\n if (fx === 0) {\n fx = coeffs[i]\n continue\n }\n fx = this.config.exps[(logx + this.config.logs[fx]) % this.config.max] ^ coeffs[i]\n }\n return fx\n }\n\n processShare(share: string) {\n const bits = parseInt(share[0], 16)\n if (bits && (bits % 1 !== 0 || bits < this.config.minBits || bits > this.config.maxBits)) {\n throw new Error('Number of bits must be an integer between ' + this.config.minBits + ' and ' + this.config.maxBits + ', inclusive.')\n }\n\n const max = Math.pow(2, bits) - 1\n const idLength = max.toString(this.config.radix).length\n\n const id = parseInt(share.substr(1, idLength), this.config.radix)\n if (id % 1 !== 0 || id < 1 || id > max) {\n throw new Error('Share id must be an integer between 1 and ' + this.config.max + ', inclusive.')\n }\n share = share.substr(idLength + 1)\n if (!share.length) {\n throw new Error('Invalid share: zero-length share.')\n }\n return {\n bits: bits,\n id: id,\n value: share,\n }\n }\n\n _combine(at: number, shares: Array<string>) {\n if (!this.config.logs.length) {\n this.init()\n }\n\n const x: Array<number> = []\n const y: Array<Array<number>> = []\n let result = ''\n let idx: number\n\n for (var i = 0, len = shares.length; i < len; i++) {\n const share = this.processShare(shares[i])\n\n if (x.includes(share['id'])) {\n // repeated x value?\n continue\n }\n\n idx = x.push(share['id']) - 1\n const shareValues = this.split(this.hex2bin(share['value']))\n for (let j = 0, len2 = shareValues.length; j < len2; j++) {\n y[j] = y[j] || []\n y[j][idx] = shareValues[j]\n }\n }\n\n for (var i = 0, len = y.length; i < len; i++) {\n result = this.padLeft(this.lagrange(at, x, y[i]).toString(2)) + result\n }\n\n if (at === 0) {\n // reconstructing the secret\n return this.bin2hex(result.slice(result.indexOf('1') + 1))\n } else {\n // generating a new share\n return this.bin2hex(result)\n }\n }\n\n combine(shares: Array<string>) {\n return this._combine(0, shares)\n }\n\n // Generate a new share with id `id` (a number between 1 and 2^bits-1)\n // `id` can be a Number or a String in the default radix (16)\n newShare(id: number | string, shares: Array<string>) {\n if (typeof id === 'string') {\n id = parseInt(id, this.config.radix)\n }\n\n const share = this.processShare(shares[0])\n const max = Math.pow(2, share['bits']) - 1\n\n if (id % 1 !== 0 || id < 1 || id > max) {\n throw new Error('Share id must be an integer between 1 and ' + this.config.max + ', inclusive.')\n }\n\n const padding = max.toString(this.config.radix).length\n return this.config.bits.toString(16).toUpperCase() + this.padLeft(id.toString(this.config.radix), padding) + this._combine(id, shares)\n }\n\n // Evaluate the Lagrange interpolation polynomial at x = `at`\n // using x and y Arrays that are of the same length, with\n // corresponding elements constituting points on the polynomial.\n lagrange(at: number, x: Array<number>, y: Array<number>) {\n let sum = 0,\n product,\n i,\n j,\n len\n for (i = 0, len = x.length; i < len; i++) {\n if (!y[i]) {\n continue\n }\n\n product = this.config.logs[y[i]]\n for (j = 0; j < len; j++) {\n if (i === j) {\n continue\n }\n if (at === x[j]) {\n // happens when computing a share that is in the list of shares used to compute it\n product = -1 // fix for a zero product term, after which the sum should be sum^0 = sum, not sum^1\n break\n }\n product =\n (product + this.config.logs[at ^ x[j]] - this.config.logs[x[i] ^ x[j]] + this.config.max) /* to make sure it's not negative */ %\n this.config.max\n }\n\n sum = product === -1 ? sum : sum ^ this.config.exps[product] // though exps[-1]= undefined and undefined ^ anything = anything in chrome, this behavior may not hold everywhere, so do the check\n }\n return sum\n }\n}\n\nexport const shamir = new ShamirClass()\n"]}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -194,10 +198,10 @@ class PatientFilterBuilder extends FilterBuilder {
|
|
|
194
198
|
}), this.hcpId));
|
|
195
199
|
}
|
|
196
200
|
olderThan(age) {
|
|
197
|
-
return this.withDateOfBirthBetween(10000101, parseInt(date_fns_1.format(date_fns_1.add(new Date(), { years: -age }), 'yyyyMMdd')));
|
|
201
|
+
return this.withDateOfBirthBetween(10000101, parseInt((0, date_fns_1.format)((0, date_fns_1.add)(new Date(), { years: -age }), 'yyyyMMdd')));
|
|
198
202
|
}
|
|
199
203
|
youngerThan(age) {
|
|
200
|
-
return this.withDateOfBirthBetween(parseInt(date_fns_1.format(date_fns_1.add(new Date(), { years: -age }), 'yyyyMMdd')), 99991231);
|
|
204
|
+
return this.withDateOfBirthBetween(parseInt((0, date_fns_1.format)((0, date_fns_1.add)(new Date(), { years: -age }), 'yyyyMMdd')), 99991231);
|
|
201
205
|
}
|
|
202
206
|
byGenderEducationProfession(gender, education, profession) {
|
|
203
207
|
return this.composer(this, new PatientFilterBuilder(() => new PatientByHcPartyGenderEducationProfession_1.PatientByHcPartyGenderEducationProfession({
|