Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                ### Interaction

<script src="https://cdn.cosmic.plus/stellar-sdk"></script>
<script src="https://cdn.cosmic.plus/cosmic-lib@2.x"></script>


<form>
  
  <fieldset><legend>#network</legend>
    <select id="network">
      <option value="test">Test</option>
      <option value="public">Public</option>
    </select>
  </fieldset>
  
  <fieldset><legend>#xdr</legend>
    <textarea id="xdr" rows="5" placeholder="Public Key or Federated Address"></textarea>
  </fieldset>
  
  <fieldset><legend>#sep7</legend>
    <input id="sep7" type="button" value="Sign using SEP7">
  </fieldset>
  
  <fieldset><legend>#cosmicLink</legend>
    <input id="cosmicLink" type="button" value="Sign using Cosmic.link">
  </fieldset>
  
  <fieldset><legend>#cosmiclink_description</legend>
    <pre id="cosmiclink_description"></pre>
  </fieldset>

</form>
  

### Description

This pen makes use of `cosmic-lib` to generate SEP7 and CosmicLink requests from a transaction XDR. This is to let the user sign a transaction using her own wallet.

### Concepts

- [SEP7](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0007.md#simple-summary): a protocol that passes transaction requests to wallets.
- [CosmicLink](https://cosmic.plus/#view:js-cosmic-lib/index.html#what-are-cosmiclinks): another protocol that passes transaction requests from applications to wallets.
- [XDR](https://www.stellar.org/developers/guides/concepts/xdr.html): The binary format Stellar ledger uses.

### Keypoints

- For SEP7 to work, you need to have registered a SEP7 handler.
- On desktop environments, you can register the [cosmic-lib demo interface](https://cosmic.plus/js-cosmic-lib/web/demo) as your SEP7 handler.
- The code of this pen shows how to authenticate the SEP7 request `origin_domain`, but this part is commented out as it is not meant to be done client-side.
- You can use almost the same code to generate SEP7 & CosmicLink requests from a StellarSdk _Transaction_ or a JSON.
- The only difference is that you don't need to provide `network` to `new CosmicLink(tx|json)`.

### Challenges

- **easy/** Edit this pen to add support for the **#callback** parameter in the form. _Hint:_ you can set it the same way than **#network**.
- **hard/** Edit this pen to add support for arbitrary **#network** passphrases. You'll offer the user to enter an **#horizon** URL for custom networks.

_Give it a try by editing the code, and be the first to post a solution on GalacticTalk!_

### Documentation

- [Stellar networks](https://www.stellar.org/developers/guides/concepts/networks.html)
- [CosmicLink documentation](https://cosmic.plus/#view:js-cosmic-lib/web/doc)

### Social

- [Discuss that pen on GalacticTalk](https://galactictalk.org/d/2163-pen-of-the-week-cosmic-lib-xdr-to-sep7-cosmiclink)
              
            
!

CSS

              
                
              
            
!

JS

              
                // $ npm install cosmic-lib
// const cosmicLib = require("cosmic-lib")
const { CosmicLink } = cosmicLib

const $ = document.querySelector.bind(document)

/* Configuration */
const network = "test"
const xdr = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

// Default CosmicLink handler.
cosmicLib.config.page = "https://cosmic.link"

/* Logic */
function xdrToCosmicLink (xdr, network) {
  const cosmicLink = new CosmicLink(xdr, { network })
  // cosmicLink.signSep7(domain, keypair)
  return cosmicLink
}

/* Interface */
function updateButtons () {
  const xdr = $("#xdr").value
  const network = $("#network").value
  const cosmicLink = xdrToCosmicLink(xdr, network)
  $("#sep7").onclick = () => open(cosmicLink.sep7)
  $("#cosmicLink").onclick = () => open(cosmicLink.uri)
}

/* Events */
$("#network").oninput = updateButtons
$("#xdr").oninput = updateButtons

/* Initialization */
$("#xdr").value = xdr
updateButtons()
              
            
!
999px

Console